////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2006-2014. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/move for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_MOVE_MAKE_UNIQUE_HPP_INCLUDED #define BOOST_MOVE_MAKE_UNIQUE_HPP_INCLUDED #include #include #include #include #include #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #include #include #include #include #endif //!\file //! Defines "make_unique" functions, which are factories to create instances //! of unique_ptr depending on the passed arguments. //! //! This header can be a bit heavyweight in C++03 compilers due to the use of the //! preprocessor library, that's why it's a a separate header from unique_ptr.hpp namespace boost{ #if !defined(BOOST_MOVE_DOXYGEN_INVOKED) namespace move_detail { //Compile time switch between //single element, unknown bound array //and known bound array template struct unique_ptr_if { typedef ::boost::movelib::unique_ptr t_is_not_array; }; template struct unique_ptr_if { typedef ::boost::movelib::unique_ptr t_is_array_of_unknown_bound; }; template struct unique_ptr_if { typedef void t_is_array_of_known_bound; }; } //namespace move_detail { #endif //!defined(BOOST_MOVE_DOXYGEN_INVOKED) namespace movelib { #if defined(BOOST_MOVE_DOXYGEN_INVOKED) || !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) //! Remarks: This function shall not participate in overload resolution unless T is not an array. //! //! Returns: unique_ptr(new T(std::forward(args)...)). template inline #if defined(BOOST_MOVE_DOXYGEN_INVOKED) unique_ptr #else typename ::boost::move_detail::unique_ptr_if::t_is_not_array #endif make_unique(BOOST_FWD_REF(Args)... args) { return unique_ptr(new T(::boost::forward(args)...)); } #else #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES #define BOOST_MOVE_PP_PARAM_LIST(z, n, data) \ BOOST_PP_CAT(P, n) && BOOST_PP_CAT(p, n) \ //! #else #define BOOST_MOVE_PP_PARAM_LIST(z, n, data) \ const BOOST_PP_CAT(P, n) & BOOST_PP_CAT(p, n) \ //! #endif //#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES #define BOOST_MOVE_PP_PARAM_FORWARD(z, n, data) \ ::boost::forward< BOOST_PP_CAT(P, n) >( BOOST_PP_CAT(p, n) ) \ //! #define BOOST_MOVE_MAX_CONSTRUCTOR_PARAMETERS 10 #define BOOST_PP_LOCAL_MACRO(n) \ template \ typename ::boost::move_detail::unique_ptr_if::t_is_not_array \ make_unique(BOOST_PP_ENUM(n, BOOST_MOVE_PP_PARAM_LIST, _)) \ { return unique_ptr(new T(BOOST_PP_ENUM(n, BOOST_MOVE_PP_PARAM_FORWARD, _))); } \ //! #define BOOST_PP_LOCAL_LIMITS (0, BOOST_MOVE_MAX_CONSTRUCTOR_PARAMETERS) #include BOOST_PP_LOCAL_ITERATE() #endif //! Remarks: This function shall not participate in overload resolution unless T is an array of //! unknown bound. //! //! Returns: unique_ptr(new remove_extent_t[n]()). template inline #if defined(BOOST_MOVE_DOXYGEN_INVOKED) unique_ptr #else typename ::boost::move_detail::unique_ptr_if::t_is_array_of_unknown_bound #endif make_unique(size_t n) { typedef typename ::boost::move_detail::remove_extent::type U; return unique_ptr(new U[n]()); } #if defined(BOOST_MOVE_DOXYGEN_INVOKED) || !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) //! Remarks: This function shall not participate in overload resolution unless T is //! an array of known bound. template #if defined(BOOST_MOVE_DOXYGEN_INVOKED) unspecified #else typename ::boost::move_detail::unique_ptr_if::t_is_array_of_known_bound #endif make_unique(BOOST_FWD_REF(Args) ...) = delete; #endif } //namespace movelib { } //namespace boost{ #include #endif //#ifndef BOOST_MOVE_MAKE_UNIQUE_HPP_INCLUDED