make_unique.hpp
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include <memory>
00004 
00005 #if defined(_MSC_VER) && __cplusplus == 201103L
00006 #  define MAKE_UNIQUE_DEFINED 1
00007 #endif
00008 
00009 #ifdef __cpp_lib_make_unique
00010 #  define MAKE_UNIQUE_DEFINED 1
00011 #endif
00012 
00013 #ifndef MAKE_UNIQUE_DEFINED
00014 
00015 //The compiler doesn't provide it, so implement it ourselves.
00016 
00017 #include <cstddef>
00018 #include <memory>
00019 #include <type_traits>
00020 #include <utility>
00021 
00022 namespace std {
00023 
00024 template<class _Ty> struct _Unique_if {
00025     typedef unique_ptr<_Ty> _Single_object;
00026 };
00027 
00028 template<class _Ty> struct _Unique_if<_Ty[]> {
00029     typedef unique_ptr<_Ty[]> _Unknown_bound;
00030 };
00031 
00032 template<class _Ty, size_t N> struct _Unique_if<_Ty[N]> {
00033     typedef void _Known_bound;
00034 };
00035 
00036 template<class _Ty, class... Args>
00037 typename _Unique_if<_Ty>::_Single_object
00038 make_unique(Args&&... args) {
00039     return unique_ptr<_Ty>(new _Ty(std::forward<Args>(args)...));
00040 }
00041 
00042 template<class _Ty>
00043 typename _Unique_if<_Ty>::_Unknown_bound
00044 make_unique(size_t n) {
00045     typedef typename remove_extent<_Ty>::type U;
00046     return unique_ptr<_Ty>(new U[n]());
00047 }
00048 
00049 
00050 } // namespace std
00051 
00052 #endif // !COMPILER_SUPPORTS_MAKE_UNIQUE
00053 


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 20:17:15