Last active
August 29, 2015 14:10
-
-
Save kkaefer/9cc2acb9a028e57ce157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <type_traits> | |
#include <utility> | |
namespace util { | |
// C++14 backfill based on http://llvm.org/svn/llvm-project/libcxx/trunk/include/memory | |
namespace detail { | |
template<class T> struct unique_type { typedef ::std::unique_ptr<T> single; }; | |
template<class T> struct unique_type<T[]> { typedef ::std::unique_ptr<T[]> unknown_bound; }; | |
template<class T, size_t size> struct unique_type<T[size]> { typedef void known_bound; }; | |
} | |
template<class T, class... Args> | |
typename detail::unique_type<T>::single make_unique(Args&&... args) { | |
return ::std::unique_ptr<T>(new T(::std::forward<Args>(args)...)); | |
} | |
template<class T> | |
typename detail::unique_type<T>::unknown_bound make_unique(size_t size) { | |
return ::std::unique_ptr<T>(new typename ::std::remove_extent<T>::type[size]()); | |
} | |
template<class T, class... Args> | |
typename detail::unique_type<T>::known_bound make_unique(Args&&...) = delete; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment