////////////////////////////////////////////////////////////////////////////// // // (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 //for std::size_t #include //!\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 #if !defined(BOOST_MOVE_DOXYGEN_INVOKED) namespace std { //no namespace versioning in clang+libc++ struct nothrow_t; } //namespace std { namespace boost{ namespace move_upmu { //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; }; static std::nothrow_t *pnothrow; } //namespace move_upmu { } //namespace boost{ #endif //!defined(BOOST_MOVE_DOXYGEN_INVOKED) namespace boost{ 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 BOOST_MOVE_DOC1ST(unique_ptr, typename ::boost::move_upmu::unique_ptr_if::t_is_not_array) make_unique(BOOST_FWD_REF(Args)... args) { return unique_ptr(new T(::boost::forward(args)...)); } //! Remarks: This function shall not participate in overload resolution unless T is not an array. //! //! Returns: unique_ptr(new T(std::nothrow)(std::forward(args)...)). template inline BOOST_MOVE_DOC1ST(unique_ptr, typename ::boost::move_upmu::unique_ptr_if::t_is_not_array) make_unique_nothrow(BOOST_FWD_REF(Args)... args) { return unique_ptr(new (*boost::move_upmu::pnothrow)T(::boost::forward(args)...)); } #else //0 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique() { return unique_ptr(new T()); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow() { return unique_ptr(new (*boost::move_upmu::pnothrow)T()); } //1 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique( BOOST_FWD_REF(P0) p0 ) { return unique_ptr ( new T( ::boost::forward(p0) ) ); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow( BOOST_FWD_REF(P0) p0 ) { return unique_ptr ( new (*boost::move_upmu::pnothrow)T ( ::boost::forward(p0) ) ); } //2 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 ) { return unique_ptr ( new T( ::boost::forward(p0) , ::boost::forward(p1) ) ); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 ) { return unique_ptr ( new (*boost::move_upmu::pnothrow)T ( ::boost::forward(p0) , ::boost::forward(p1) ) ); } //3 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 ) { return unique_ptr ( new T( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) ) ); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow ( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 ) { return unique_ptr ( new (*boost::move_upmu::pnothrow)T ( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) ) ); } //4 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 ) { return unique_ptr ( new T( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) ) ); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow ( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 ) { return unique_ptr ( new (*boost::move_upmu::pnothrow)T ( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) ) ); } //5 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 ) { return unique_ptr ( new T( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) ) ); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow ( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 ) { return unique_ptr ( new (*boost::move_upmu::pnothrow)T ( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) ) ); } //6 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 , BOOST_FWD_REF(P5) p5 ) { return unique_ptr ( new T( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) , ::boost::forward(p5) ) ); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow ( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 , BOOST_FWD_REF(P5) p5 ) { return unique_ptr ( new (*boost::move_upmu::pnothrow)T ( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) , ::boost::forward(p5) ) ); } //7 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 , BOOST_FWD_REF(P5) p5 , BOOST_FWD_REF(P6) p6 ) { return unique_ptr ( new T( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) , ::boost::forward(p5) , ::boost::forward(p6) ) ); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow ( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 , BOOST_FWD_REF(P5) p5 , BOOST_FWD_REF(P6) p6 ) { return unique_ptr ( new (*boost::move_upmu::pnothrow)T ( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) , ::boost::forward(p5) , ::boost::forward(p6) ) ); } //8 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 , BOOST_FWD_REF(P5) p5 , BOOST_FWD_REF(P6) p6 , BOOST_FWD_REF(P7) p7 ) { return unique_ptr ( new T( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) , ::boost::forward(p5) , ::boost::forward(p6) , ::boost::forward(p7) ) ); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow ( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 , BOOST_FWD_REF(P5) p5 , BOOST_FWD_REF(P6) p6 , BOOST_FWD_REF(P7) p7 ) { return unique_ptr ( new (*boost::move_upmu::pnothrow)T ( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) , ::boost::forward(p5) , ::boost::forward(p6) , ::boost::forward(p7) ) ); } //9 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 , BOOST_FWD_REF(P5) p5 , BOOST_FWD_REF(P6) p6 , BOOST_FWD_REF(P7) p7 , BOOST_FWD_REF(P8) p8 ) { return unique_ptr ( new T( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) , ::boost::forward(p5) , ::boost::forward(p6) , ::boost::forward(p7) , ::boost::forward(p8) ) ); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow ( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 , BOOST_FWD_REF(P5) p5 , BOOST_FWD_REF(P6) p6 , BOOST_FWD_REF(P7) p7 , BOOST_FWD_REF(P8) p8 ) { return unique_ptr ( new (*boost::move_upmu::pnothrow)T ( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) , ::boost::forward(p5) , ::boost::forward(p6) , ::boost::forward(p7) , ::boost::forward(p8) ) ); } //10 arg template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 , BOOST_FWD_REF(P5) p5 , BOOST_FWD_REF(P6) p6 , BOOST_FWD_REF(P7) p7 , BOOST_FWD_REF(P8) p8 , BOOST_FWD_REF(P9) p9 ) { return unique_ptr ( new T( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) , ::boost::forward(p5) , ::boost::forward(p6) , ::boost::forward(p7) , ::boost::forward(p8) , ::boost::forward(p9) ) ); } template typename ::boost::move_upmu::unique_ptr_if::t_is_not_array make_unique_nothrow ( BOOST_FWD_REF(P0) p0 , BOOST_FWD_REF(P1) p1 , BOOST_FWD_REF(P2) p2 , BOOST_FWD_REF(P3) p3 , BOOST_FWD_REF(P4) p4 , BOOST_FWD_REF(P5) p5 , BOOST_FWD_REF(P6) p6 , BOOST_FWD_REF(P7) p7 , BOOST_FWD_REF(P8) p8 , BOOST_FWD_REF(P9) p9 ) { return unique_ptr ( new (*boost::move_upmu::pnothrow)T ( ::boost::forward(p0) , ::boost::forward(p1) , ::boost::forward(p2) , ::boost::forward(p3) , ::boost::forward(p4) , ::boost::forward(p5) , ::boost::forward(p6) , ::boost::forward(p7) , ::boost::forward(p8) , ::boost::forward(p9) ) ); } #endif //! Remarks: This function shall not participate in overload resolution unless T is not an array. //! //! Returns: unique_ptr(new T) (default initialization) template inline BOOST_MOVE_DOC1ST(unique_ptr, typename ::boost::move_upmu::unique_ptr_if::t_is_not_array) make_unique_definit() { return unique_ptr(new T); } //! Remarks: This function shall not participate in overload resolution unless T is not an array. //! //! Returns: unique_ptr(new T(std::nothrow) (default initialization) template inline BOOST_MOVE_DOC1ST(unique_ptr, typename ::boost::move_upmu::unique_ptr_if::t_is_not_array) make_unique_nothrow_definit() { return unique_ptr(new (*boost::move_upmu::pnothrow)T); } //! 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]()) (value initialization) template inline BOOST_MOVE_DOC1ST(unique_ptr, typename ::boost::move_upmu::unique_ptr_if::t_is_array_of_unknown_bound) make_unique(std::size_t n) { typedef typename ::boost::move_upmu::remove_extent::type U; return unique_ptr(new U[n]()); } //! Remarks: This function shall not participate in overload resolution unless T is an array of //! unknown bound. //! //! Returns: unique_ptr(new (std::nothrow)remove_extent_t[n]()) (value initialization) template inline BOOST_MOVE_DOC1ST(unique_ptr, typename ::boost::move_upmu::unique_ptr_if::t_is_array_of_unknown_bound) make_unique_nothrow(std::size_t n) { typedef typename ::boost::move_upmu::remove_extent::type U; return unique_ptr(new (*boost::move_upmu::pnothrow)U[n]()); } //! 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]) (default initialization) template inline BOOST_MOVE_DOC1ST(unique_ptr, typename ::boost::move_upmu::unique_ptr_if::t_is_array_of_unknown_bound) make_unique_definit(std::size_t n) { typedef typename ::boost::move_upmu::remove_extent::type U; return unique_ptr(new U[n]); } //! Remarks: This function shall not participate in overload resolution unless T is an array of //! unknown bound. //! //! Returns: unique_ptr(new (std::nothrow)remove_extent_t[n]) (default initialization) template inline BOOST_MOVE_DOC1ST(unique_ptr, typename ::boost::move_upmu::unique_ptr_if::t_is_array_of_unknown_bound) make_unique_nothrow_definit(std::size_t n) { typedef typename ::boost::move_upmu::remove_extent::type U; return unique_ptr(new (*boost::move_upmu::pnothrow) U[n]); } #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) //! Remarks: This function shall not participate in overload resolution unless T is //! an array of known bound. template inline BOOST_MOVE_DOC1ST(unspecified, typename ::boost::move_upmu::unique_ptr_if::t_is_array_of_known_bound) make_unique(BOOST_FWD_REF(Args) ...) = delete; //! Remarks: This function shall not participate in overload resolution unless T is //! an array of known bound. template inline BOOST_MOVE_DOC1ST(unspecified, typename ::boost::move_upmu::unique_ptr_if::t_is_array_of_known_bound) make_unique_definit(BOOST_FWD_REF(Args) ...) = delete; //! Remarks: This function shall not participate in overload resolution unless T is //! an array of known bound. template inline BOOST_MOVE_DOC1ST(unspecified, typename ::boost::move_upmu::unique_ptr_if::t_is_array_of_known_bound) make_unique_nothrow(BOOST_FWD_REF(Args) ...) = delete; //! Remarks: This function shall not participate in overload resolution unless T is //! an array of known bound. template inline BOOST_MOVE_DOC1ST(unspecified, typename ::boost::move_upmu::unique_ptr_if::t_is_array_of_known_bound) make_unique_nothrow_definit(BOOST_FWD_REF(Args) ...) = delete; #endif } //namespace movelib { } //namespace boost{ #include #endif //#ifndef BOOST_MOVE_MAKE_UNIQUE_HPP_INCLUDED