Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make_unique availability in Xcode5?

Tags:

c++

c++11

xcode5

I was just trying to use make_unique function of c++11 on Xcode5.0.2, The Clang version is

Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)

After checking <memory> It looks like it is not there. make_shared is.

I know this is C++14, but it was also one of the first function validated for c++14. It is even in Visual :).

When will it be available?

like image 821
dzada Avatar asked Aug 16 '26 11:08

dzada


1 Answers

Note: more a comment than an answer, but formatted code and comments do not mix.

Unfortunately, no idea when it will be available; however you can easily define it yourself for now and just switch to the standard one later:

template <typename T, typename... Args>
auto make_unique(Args&&... args) -> std::unique_ptr<T>
{
    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

That's it, contrary to make_shared there is no magic here because the benefit is just one of exception safety (tie together allocation and capture in unique_ptr) whereas make_shared bundles additional advantages (irrelevant to unique_ptr).

like image 101
Matthieu M. Avatar answered Aug 18 '26 00:08

Matthieu M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!