#ifndef MAKE_UNIQUE_H_ #define MAKE_UNIQUE_H_ #include #include #include namespace osrm { namespace util { // Implement make_unique according to N3656. Taken from libcxx's implementation /// \brief Constructs a `new T()` with the given args and returns a /// `unique_ptr` which owns the object. /// /// Example: /// /// auto p = make_unique(); /// auto p = make_unique>(0, 1); template typename std::enable_if::value, std::unique_ptr>::type make_unique(Args &&... args) { return std::unique_ptr(new T(std::forward(args)...)); } /// \brief Constructs a `new T[n]` with the given args and returns a /// `unique_ptr` which owns the object. /// /// \param n size of the new array. /// /// Example: /// /// auto p = make_unique(2); // value-initializes the array with 0's. template typename std::enable_if::value && std::extent::value == 0, std::unique_ptr>::type make_unique(size_t n) { return std::unique_ptr(new typename std::remove_extent::type[n]()); } /// This function isn't used and is only here to provide better compile errors. template typename std::enable_if::value != 0>::type make_unique(Args &&...) = delete; } } #endif // MAKE_UNIQUE_H_