From 19ec26e17d9ae63f7c8527f05cde889d560451f2 Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Fri, 30 May 2014 17:10:38 -0700 Subject: [PATCH] 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 --- folly/Memory.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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: * -- 2.34.1