diff --git a/util/make_unique.hpp b/util/make_unique.hpp index b88145d17..e670ffd4d 100644 --- a/util/make_unique.hpp +++ b/util/make_unique.hpp @@ -34,24 +34,40 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace osrm { -// Taken from http://msdn.microsoft.com/en-us/library/dn439780.asp -// Note, that the snippet was broken there and needed minor massaging +// Implement make_unique according to N3656. Taken from libcxx's implementation -// make_unique -template std::unique_ptr make_unique(Types &&... Args) +/// \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)...))); + return std::unique_ptr(new T(std::forward(args)...)); } -// make_unique -template std::unique_ptr make_unique(std::size_t Size) +/// \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 T[Size]())); + return std::unique_ptr(new typename std::remove_extent::type[n]()); } -// make_unique disallowed -template -typename std::enable_if::value != 0, void>::type make_unique(Types &&...) = delete; +/// 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_