From: Jon Purdy Date: Sat, 31 May 2014 00:10:38 +0000 (-0700) Subject: Add missing make_unique overload. X-Git-Tag: v0.22.0~521 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=19ec26e17d9ae63f7c8527f05cde889d560451f2;p=folly.git Add missing make_unique overload. Summary: C++14 adds this overload but I wanted it today. Test Plan: It compiles, and this is the definition described in the standard. Reviewed By: xning@fb.com Subscribers: folly@lists FB internal diff: D1338839 --- diff --git a/folly/Memory.h b/folly/Memory.h index 8394f6ad..625c466e 100644 --- a/folly/Memory.h +++ b/folly/Memory.h @@ -38,10 +38,24 @@ namespace folly { */ template, typename... Args> -std::unique_ptr make_unique(Args&&... args) { +typename std::enable_if::value, std::unique_ptr>::type +make_unique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } +// Allows 'make_unique(10)'. (N3690 s20.9.1.4 p3-4) +template> +typename std::enable_if::value, std::unique_ptr>::type +make_unique(const size_t n) { + return std::unique_ptr(new typename std::remove_extent::type[n]()); +} + +// Disallows 'make_unique()'. (N3690 s20.9.1.4 p5) +template, typename... Args> +typename std::enable_if< + std::extent::value != 0, std::unique_ptr>::type +make_unique(Args&&...) = delete; + /** * A SimpleAllocator must provide two methods: *