Commit 19ec26e1 authored by Jon Purdy's avatar Jon Purdy Committed by Anton Likhtarov

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
parent 300f64f9
......@@ -38,10 +38,24 @@ namespace folly {
*/
template<typename T, typename Dp = std::default_delete<T>, typename... Args>
std::unique_ptr<T, Dp> make_unique(Args&&... args) {
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T, Dp>>::type
make_unique(Args&&... args) {
return std::unique_ptr<T, Dp>(new T(std::forward<Args>(args)...));
}
// Allows 'make_unique<T[]>(10)'. (N3690 s20.9.1.4 p3-4)
template<typename T, typename Dp = std::default_delete<T>>
typename std::enable_if<std::is_array<T>::value, std::unique_ptr<T, Dp>>::type
make_unique(const size_t n) {
return std::unique_ptr<T, Dp>(new typename std::remove_extent<T>::type[n]());
}
// Disallows 'make_unique<T[10]>()'. (N3690 s20.9.1.4 p5)
template<typename T, typename Dp = std::default_delete<T>, typename... Args>
typename std::enable_if<
std::extent<T>::value != 0, std::unique_ptr<T, Dp>>::type
make_unique(Args&&...) = delete;
/**
* A SimpleAllocator must provide two methods:
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment