News for hackers. Stuff that matters.
Re:Elements of Modern C++ Style by cpeterso on Saturday October 29, 2011 @11:07PM (#3173530)
I wish C++11 added syntactic sugar for the smart pointer classes like scoped_ptr, shared_ptr, and unique_ptr. I would rather see new operators (like Microsoft C++/CLI's ^ and %) than even more templated code. Compare something like:

  int^ foo(int% bar);
versus:

  std::unique_ptr<int> foo(std::shared_ptr<int> bar);
Smart pointers have long been available in boost and are required for writing safe code, but they make code unreadable (even after typedefs).
Re:Elements of Modern C++ Style by pyrtsa on Sunday October 30, 2011 @08:44AM (#3174229)
I don't think introducing more syntax to the language for a feature that ultimately is a library solution, is a sustainable way to go.

But if you really need a compact notation for smart pointers, you'll get pretty close by using template aliases, e.g.

    template <typename T> using up = std::unique_ptr<T>;
    template <typename T> using sp = std::shared_ptr<T>;
    // ...
    up<int> foo(sp<int> bar) {
        return bar ? up<int>(new int(*bar)) : nullptr;
    }
Re:Elements of Modern C++ Style by thwest on Sunday October 30, 2011 @10:50AM (#3174495)
Oh C++11 has template typedefs? Time to migrate my project.