/* * STL standards compatibility functions * (C) 2017 Tomasz Frydrych * * Botan is released under the Simplified BSD License (see license.txt) */ #ifndef BOTAN_STL_COMPATIBILITY_H_ #define BOTAN_STL_COMPATIBILITY_H_ #include #include #if __cplusplus < 201402L #include #include #include #endif BOTAN_FUTURE_INTERNAL_HEADER(stl_compatability.h) namespace Botan { /* * std::make_unique functionality similar as we have in C++14. * C++11 version based on proposal for C++14 implemenatation by Stephan T. Lavavej * source: https://isocpp.org/files/papers/N3656.txt */ #if __cplusplus >= 201402L template constexpr auto make_unique(Args&&... args) { return std::make_unique(std::forward(args)...); } template constexpr auto make_unique(std::size_t size) { return std::make_unique(size); } #else namespace stlCompatibilityDetails { template struct _Unique_if { typedef std::unique_ptr _Single_object; }; template struct _Unique_if { typedef std::unique_ptr _Unknown_bound; }; template struct _Unique_if { typedef void _Known_bound; }; } // namespace stlCompatibilityDetails template typename stlCompatibilityDetails::_Unique_if::_Single_object make_unique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } template typename stlCompatibilityDetails::_Unique_if::_Unknown_bound make_unique(size_t n) { typedef typename std::remove_extent::type U; return std::unique_ptr(new U[n]()); } template typename stlCompatibilityDetails::_Unique_if::_Known_bound make_unique(Args&&...) = delete; #endif } // namespace Botan #endif