Skip to content

Instantly share code, notes, and snippets.

@hatsusato
Last active January 26, 2016 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatsusato/09a296a855c1826fe2b8 to your computer and use it in GitHub Desktop.
Save hatsusato/09a296a855c1826fe2b8 to your computer and use it in GitHub Desktop.
make_unique
#include <memory>
#include <type_traits>
template <class T, class... Args>
typename std::enable_if<std::is_constructible<T, Args...>::value,
std::unique_ptr<T> >::type
make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template <class T, class... Args>
typename std::enable_if<!std::is_constructible<T, Args...>::value,
std::unique_ptr<T> >::type
make_unique(Args&&... args) {
return std::unique_ptr<T>(new T{std::forward<Args>(args)...});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment