add make_unique to FreeCAD

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
abdullah
Posts: 2788
Joined: Sun May 04, 2014 3:16 pm

add make_unique to FreeCAD

Postby abdullah » Thu Feb 14, 2019 5:09 am

I use "make_unique" function for making unique smart pointers, which comes with c++14. "make_shared" for shared pointers does comes with c++11.

The function is of general utility and straightforward to implement:

Code: Select all

namespace std {
    template<typename T, typename... Args>
    std::unique_ptr<T> make_unique(Args&&... args)
    {
        return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
    }
}
Where is the right place to put this function in FreeCAD (probably with some conditional compilation so that only applies to c++11, not to c++14, if FreeCAD were to be compiled with c++14)?
wmayer
Site Admin
Posts: 13597
Joined: Thu Feb 19, 2009 10:32 am

Re: add make_unique to FreeCAD

Postby wmayer » Thu Feb 14, 2019 8:41 am

An option is the file src/Base/Tools.h. But we could also think about creating a new file. At least it makes most sense to have it in FreeCADBase.
abdullah
Posts: 2788
Joined: Sun May 04, 2014 3:16 pm

Re: add make_unique to FreeCAD

Postby abdullah » Thu Feb 14, 2019 12:38 pm

wmayer wrote:
Thu Feb 14, 2019 8:41 am
An option is the file src/Base/Tools.h. But we could also think about creating a new file. At least it makes most sense to have it in FreeCADBase.
Ok. Thanks! :)