Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:54

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2006-2014. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/move for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_MOVE_MAKE_UNIQUE_HPP_INCLUDED
0012 #define BOOST_MOVE_MAKE_UNIQUE_HPP_INCLUDED
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 #  pragma once
0020 #endif
0021 
0022 #include <boost/move/detail/config_begin.hpp>
0023 #include <boost/move/detail/workaround.hpp>
0024 #include <boost/move/utility_core.hpp>
0025 #include <boost/move/unique_ptr.hpp>
0026 #include <cstddef>   //for std::size_t
0027 #include <boost/move/detail/unique_ptr_meta_utils.hpp>
0028 #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
0029 #  include <boost/move/detail/fwd_macros.hpp>
0030 #endif
0031 
0032 //!\file
0033 //! Defines "make_unique" functions, which are factories to create instances
0034 //! of unique_ptr depending on the passed arguments.
0035 //!
0036 //! This header can be a bit heavyweight in C++03 compilers due to the use of the
0037 //! preprocessor library, that's why it's a a separate header from <tt>unique_ptr.hpp</tt>
0038  
0039 #if !defined(BOOST_MOVE_DOXYGEN_INVOKED)
0040 
0041 #if defined(_MSC_VER) && (_MSC_VER >= 1915)
0042    #pragma warning (push)
0043    #pragma warning (disable : 4643) // Forward declaring 'X' in namespace std is not permitted by the C++ Standard
0044 #endif
0045 
0046 namespace std {   //no namespace versioning in clang+libc++
0047 
0048 struct nothrow_t;
0049 
0050 }  //namespace std {
0051 
0052 #if defined(_MSC_VER) && (_MSC_VER >= 1915)
0053    #pragma warning (pop)
0054 #endif
0055 
0056 
0057 namespace boost{
0058 namespace move_upmu {
0059 
0060 //Compile time switch between
0061 //single element, unknown bound array
0062 //and known bound array
0063 template<class T>
0064 struct unique_ptr_if
0065 {
0066    typedef ::boost::movelib::unique_ptr<T> t_is_not_array;
0067 };
0068 
0069 template<class T>
0070 struct unique_ptr_if<T[]>
0071 {
0072    typedef ::boost::movelib::unique_ptr<T[]> t_is_array_of_unknown_bound;
0073 };
0074 
0075 template<class T, std::size_t N>
0076 struct unique_ptr_if<T[N]>
0077 {
0078    typedef void t_is_array_of_known_bound;
0079 };
0080 
0081 template <int Dummy = 0>
0082 struct nothrow_holder
0083 {
0084    static std::nothrow_t *pnothrow;   
0085 };
0086 
0087 template <int Dummy>
0088 std::nothrow_t *nothrow_holder<Dummy>::pnothrow = 
0089    reinterpret_cast<std::nothrow_t *>(0x1234);  //Avoid reference to null errors in sanitizers
0090 
0091 }  //namespace move_upmu {
0092 }  //namespace boost{
0093 
0094 #endif   //!defined(BOOST_MOVE_DOXYGEN_INVOKED)
0095 
0096 namespace boost{
0097 namespace movelib {
0098 
0099 #if defined(BOOST_MOVE_DOXYGEN_INVOKED) || !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0100 
0101 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is not an array.
0102 //!
0103 //! <b>Returns</b>: <tt>unique_ptr<T>(new T(std::forward<Args>(args)...))</tt>.
0104 template<class T, class... Args>
0105 inline BOOST_MOVE_DOC1ST(unique_ptr<T>, 
0106    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array)
0107       make_unique(BOOST_FWD_REF(Args)... args)
0108 {  return unique_ptr<T>(new T(::boost::forward<Args>(args)...));  }
0109 
0110 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is not an array.
0111 //!
0112 //! <b>Returns</b>: <tt>unique_ptr<T>(new T(std::nothrow)(std::forward<Args>(args)...))</tt>.
0113 template<class T, class... Args>
0114 inline BOOST_MOVE_DOC1ST(unique_ptr<T>, 
0115    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array)
0116       make_unique_nothrow(BOOST_FWD_REF(Args)... args)
0117 {  return unique_ptr<T>(new (*boost::move_upmu::nothrow_holder<>::pnothrow)T(::boost::forward<Args>(args)...));  }
0118 
0119 #else
0120    #define BOOST_MOVE_MAKE_UNIQUE_CODE(N)\
0121       template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N>\
0122       typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array\
0123          make_unique( BOOST_MOVE_UREF##N)\
0124       {  return unique_ptr<T>( new T( BOOST_MOVE_FWD##N ) );  }\
0125       \
0126       template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N>\
0127       typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array\
0128          make_unique_nothrow( BOOST_MOVE_UREF##N)\
0129       {  return unique_ptr<T>( new (*boost::move_upmu::nothrow_holder<>::pnothrow)T ( BOOST_MOVE_FWD##N ) );  }\
0130       //
0131    BOOST_MOVE_ITERATE_0TO9(BOOST_MOVE_MAKE_UNIQUE_CODE)
0132    #undef BOOST_MOVE_MAKE_UNIQUE_CODE
0133 
0134 #endif
0135 
0136 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is not an array.
0137 //!
0138 //! <b>Returns</b>: <tt>unique_ptr<T>(new T)</tt> (default initialization)
0139 template<class T>
0140 inline BOOST_MOVE_DOC1ST(unique_ptr<T>, 
0141    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array)
0142       make_unique_definit()
0143 {
0144     return unique_ptr<T>(new T);
0145 }
0146 
0147 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is not an array.
0148 //!
0149 //! <b>Returns</b>: <tt>unique_ptr<T>(new T(std::nothrow)</tt> (default initialization)
0150 template<class T>
0151 inline BOOST_MOVE_DOC1ST(unique_ptr<T>, 
0152    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_not_array)
0153       make_unique_nothrow_definit()
0154 {
0155     return unique_ptr<T>(new (*boost::move_upmu::nothrow_holder<>::pnothrow)T);
0156 }
0157 
0158 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is an array of 
0159 //!   unknown bound.
0160 //!
0161 //! <b>Returns</b>: <tt>unique_ptr<T>(new remove_extent_t<T>[n]())</tt> (value initialization)
0162 template<class T>
0163 inline BOOST_MOVE_DOC1ST(unique_ptr<T>, 
0164    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_unknown_bound)
0165       make_unique(std::size_t n)
0166 {
0167     typedef typename ::boost::move_upmu::remove_extent<T>::type U;
0168     return unique_ptr<T>(new U[n]());
0169 }
0170 
0171 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is an array of 
0172 //!   unknown bound.
0173 //!
0174 //! <b>Returns</b>: <tt>unique_ptr<T>(new (std::nothrow)remove_extent_t<T>[n]())</tt> (value initialization)
0175 template<class T>
0176 inline BOOST_MOVE_DOC1ST(unique_ptr<T>, 
0177    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_unknown_bound)
0178       make_unique_nothrow(std::size_t n)
0179 {
0180     typedef typename ::boost::move_upmu::remove_extent<T>::type U;
0181     return unique_ptr<T>(new (*boost::move_upmu::nothrow_holder<>::pnothrow)U[n]());
0182 }
0183 
0184 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is an array of 
0185 //!   unknown bound.
0186 //!
0187 //! <b>Returns</b>: <tt>unique_ptr<T>(new remove_extent_t<T>[n])</tt> (default initialization)
0188 template<class T>
0189 inline BOOST_MOVE_DOC1ST(unique_ptr<T>, 
0190    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_unknown_bound)
0191       make_unique_definit(std::size_t n)
0192 {
0193     typedef typename ::boost::move_upmu::remove_extent<T>::type U;
0194     return unique_ptr<T>(new U[n]);
0195 }
0196 
0197 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is an array of 
0198 //!   unknown bound.
0199 //!
0200 //! <b>Returns</b>: <tt>unique_ptr<T>(new (std::nothrow)remove_extent_t<T>[n])</tt> (default initialization)
0201 template<class T>
0202 inline BOOST_MOVE_DOC1ST(unique_ptr<T>, 
0203    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_unknown_bound)
0204       make_unique_nothrow_definit(std::size_t n)
0205 {
0206     typedef typename ::boost::move_upmu::remove_extent<T>::type U;
0207     return unique_ptr<T>(new (*boost::move_upmu::nothrow_holder<>::pnothrow) U[n]);
0208 }
0209 
0210 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
0211 
0212 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is
0213 //!   an array of known bound.
0214 template<class T, class... Args>
0215 inline BOOST_MOVE_DOC1ST(unspecified, 
0216    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_known_bound)
0217       make_unique(BOOST_FWD_REF(Args) ...) = delete;
0218 
0219 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is
0220 //!   an array of known bound.
0221 template<class T, class... Args>
0222 inline BOOST_MOVE_DOC1ST(unspecified, 
0223    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_known_bound)
0224       make_unique_definit(BOOST_FWD_REF(Args) ...) = delete;
0225 
0226 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is
0227 //!   an array of known bound.
0228 template<class T, class... Args>
0229 inline BOOST_MOVE_DOC1ST(unspecified, 
0230    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_known_bound)
0231       make_unique_nothrow(BOOST_FWD_REF(Args) ...) = delete;
0232 
0233 //! <b>Remarks</b>: This function shall not participate in overload resolution unless T is
0234 //!   an array of known bound.
0235 template<class T, class... Args>
0236 inline BOOST_MOVE_DOC1ST(unspecified, 
0237    typename ::boost::move_upmu::unique_ptr_if<T>::t_is_array_of_known_bound)
0238       make_unique_nothrow_definit(BOOST_FWD_REF(Args) ...) = delete;
0239 
0240 #endif
0241 
0242 }  //namespace movelib {
0243 
0244 }  //namespace boost{
0245 
0246 #include <boost/move/detail/config_end.hpp>
0247 
0248 #endif   //#ifndef BOOST_MOVE_MAKE_UNIQUE_HPP_INCLUDED