Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2014-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_DEFAULT_DELETE_HPP_INCLUDED
0012 #define BOOST_MOVE_DEFAULT_DELETE_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/detail/unique_ptr_meta_utils.hpp>
0025 #include <boost/move/utility_core.hpp>
0026 
0027 #include <cstddef>   //For std::size_t,std::nullptr_t
0028 
0029 //!\file
0030 //! Describes the default deleter (destruction policy) of <tt>unique_ptr</tt>: <tt>default_delete</tt>.
0031 
0032 namespace boost{
0033 // @cond
0034 namespace move_upd {
0035 
0036 namespace bmupmu = ::boost::move_upmu;
0037 
0038 ////////////////////////////////////////
0039 ////        enable_def_del
0040 ////////////////////////////////////////
0041 
0042 //compatible with a pointer type T*:
0043 //When either Y* is convertible to T*
0044 //Y is U[N] and T is U cv []
0045 template<class U, class T>
0046 struct def_del_compatible_cond
0047    : bmupmu::is_convertible<U*, T*>
0048 {};
0049 
0050 template<class U, class T, std::size_t N>
0051 struct def_del_compatible_cond<U[N], T[]>
0052    : def_del_compatible_cond<U[], T[]>
0053 {};
0054 
0055 template<class U, class T, class Type = bmupmu::nat>
0056 struct enable_def_del
0057    : bmupmu::enable_if_c<def_del_compatible_cond<U, T>::value, Type>
0058 {};
0059 
0060 ////////////////////////////////////////
0061 ////        enable_defdel_call
0062 ////////////////////////////////////////
0063 
0064 //When 2nd is T[N], 1st(*)[N] shall be convertible to T(*)[N]; 
0065 //When 2nd is T[],  1st(*)[] shall be convertible to T(*)[]; 
0066 //Otherwise, 1st* shall be convertible to 2nd*.
0067 
0068 template<class U, class T, class Type = bmupmu::nat>
0069 struct enable_defdel_call
0070    : public enable_def_del<U, T, Type>
0071 {};
0072 
0073 template<class U, class T, class Type>
0074 struct enable_defdel_call<U, T[], Type>
0075    : public enable_def_del<U[], T[], Type>
0076 {};
0077 
0078 template<class U, class T, class Type, std::size_t N>
0079 struct enable_defdel_call<U, T[N], Type>
0080    : public enable_def_del<U[N], T[N], Type>
0081 {};
0082 
0083 ////////////////////////////////////////
0084 ////     Some bool literal zero conversion utilities
0085 ////////////////////////////////////////
0086 
0087 struct bool_conversion {int for_bool; int for_arg(); };
0088 typedef int bool_conversion::* explicit_bool_arg;
0089 
0090 #if !defined(BOOST_NO_CXX11_NULLPTR) && !defined(BOOST_NO_CXX11_DECLTYPE)
0091    typedef decltype(nullptr) nullptr_type;
0092 #elif !defined(BOOST_NO_CXX11_NULLPTR)
0093    typedef std::nullptr_t nullptr_type;
0094 #else
0095    typedef int (bool_conversion::*nullptr_type)();
0096 #endif
0097 
0098 template<bool B>
0099 struct is_array_del
0100 {};
0101 
0102 template<class T>
0103 void call_delete(T *p, is_array_del<true>)
0104 {
0105    delete [] p;
0106 }
0107 
0108 template<class T>
0109 void call_delete(T *p, is_array_del<false>)
0110 {
0111    delete p;
0112 }
0113 
0114 template< class T, class U
0115         , bool enable =  def_del_compatible_cond< U, T>::value &&
0116                         !move_upmu::is_array<T>::value &&
0117                         !move_upmu::is_same<typename move_upmu::remove_cv<T>::type, void>::value &&
0118                         !move_upmu::is_same<typename move_upmu::remove_cv<U>::type, typename move_upmu::remove_cv<T>::type>::value
0119         >
0120 struct missing_virtual_destructor_default_delete
0121 {  static const bool value = !move_upmu::has_virtual_destructor<T>::value;  };
0122 
0123 template<class T, class U>
0124 struct missing_virtual_destructor_default_delete<T, U, false>
0125 {  static const bool value = false;  };
0126 
0127 //////////////////////////////////////
0128 //       missing_virtual_destructor
0129 //////////////////////////////////////
0130 
0131 template<class Deleter, class U>
0132 struct missing_virtual_destructor
0133 {  static const bool value = false;  };
0134 
0135 template<class T, class U>
0136 struct missing_virtual_destructor< ::boost::movelib::default_delete<T>, U >
0137    : missing_virtual_destructor_default_delete<T, U>
0138 {};
0139 
0140 
0141 }  //namespace move_upd {
0142 // @endcond
0143 
0144 namespace movelib {
0145 
0146 namespace bmupd = boost::move_upd;
0147 namespace bmupmu = ::boost::move_upmu;
0148 
0149 //!The class template <tt>default_delete</tt> serves as the default deleter
0150 //!(destruction policy) for the class template <tt>unique_ptr</tt>.
0151 //!
0152 //! \tparam T The type to be deleted. It may be an incomplete type
0153 template <class T>
0154 struct default_delete
0155 {
0156    //! Default constructor.
0157    //!
0158    BOOST_CONSTEXPR default_delete()
0159    //Avoid "defaulted on its first declaration must not have an exception-specification" error for GCC 4.6
0160    #if !defined(BOOST_GCC) || (BOOST_GCC < 40600 && BOOST_GCC >= 40700) || defined(BOOST_MOVE_DOXYGEN_INVOKED)
0161    BOOST_NOEXCEPT
0162    #endif
0163    #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || defined(BOOST_MOVE_DOXYGEN_INVOKED)
0164    = default;
0165    #else
0166    {};
0167    #endif
0168 
0169    #if defined(BOOST_MOVE_DOXYGEN_INVOKED)
0170    //! Trivial copy constructor
0171    //!
0172    default_delete(const default_delete&) BOOST_NOEXCEPT = default;
0173    //! Trivial assignment
0174    //!
0175    default_delete &operator=(const default_delete&) BOOST_NOEXCEPT = default;
0176    #else
0177    typedef typename bmupmu::remove_extent<T>::type element_type;
0178    #endif
0179 
0180    //! <b>Effects</b>: Constructs a default_delete object from another <tt>default_delete<U></tt> object.
0181    //!
0182    //! <b>Remarks</b>: This constructor shall not participate in overload resolution unless:
0183    //!   - If T is not an array type and U* is implicitly convertible to T*.
0184    //!   - If T is an array type and U* is a more CV qualified pointer to remove_extent<T>::type.
0185    template <class U>
0186    default_delete(const default_delete<U>&
0187       BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmupd::enable_def_del<U BOOST_MOVE_I T>::type* =0)
0188       ) BOOST_NOEXCEPT
0189    {
0190       //If T is not an array type, U derives from T
0191       //and T has no virtual destructor, then you have a problem
0192       BOOST_MOVE_STATIC_ASSERT(( !bmupd::missing_virtual_destructor<default_delete, U>::value ));
0193    }
0194 
0195    //! <b>Effects</b>: Constructs a default_delete object from another <tt>default_delete<U></tt> object.
0196    //!
0197    //! <b>Remarks</b>: This constructor shall not participate in overload resolution unless:
0198    //!   - If T is not an array type and U* is implicitly convertible to T*.
0199    //!   - If T is an array type and U* is a more CV qualified pointer to remove_extent<T>::type.
0200    template <class U>
0201    BOOST_MOVE_DOC1ST(default_delete&, 
0202       typename bmupd::enable_def_del<U BOOST_MOVE_I T BOOST_MOVE_I default_delete &>::type)
0203       operator=(const default_delete<U>&) BOOST_NOEXCEPT
0204    {
0205       //If T is not an array type, U derives from T
0206       //and T has no virtual destructor, then you have a problem
0207       BOOST_MOVE_STATIC_ASSERT(( !bmupd::missing_virtual_destructor<default_delete, U>::value ));
0208       return *this;
0209    }
0210 
0211    //! <b>Effects</b>: if T is not an array type, calls <tt>delete</tt> on static_cast<T*>(ptr),
0212    //!   otherwise calls <tt>delete[]</tt> on static_cast<remove_extent<T>::type*>(ptr).
0213    //!
0214    //! <b>Remarks</b>: If U is an incomplete type, the program is ill-formed.
0215    //!   This operator shall not participate in overload resolution unless:
0216    //!      - T is not an array type and U* is convertible to T*, OR
0217    //!      - T is an array type, and remove_cv<U>::type is the same type as
0218    //!         remove_cv<remove_extent<T>::type>::type and U* is convertible to remove_extent<T>::type*.
0219    template <class U>
0220    BOOST_MOVE_DOC1ST(void, typename bmupd::enable_defdel_call<U BOOST_MOVE_I T BOOST_MOVE_I void>::type)
0221       operator()(U* ptr) const BOOST_NOEXCEPT
0222    {
0223       //U must be a complete type
0224       BOOST_MOVE_STATIC_ASSERT(sizeof(U) > 0);
0225       //If T is not an array type, U derives from T
0226       //and T has no virtual destructor, then you have a problem
0227       BOOST_MOVE_STATIC_ASSERT(( !bmupd::missing_virtual_destructor<default_delete, U>::value ));
0228       element_type * const p = static_cast<element_type*>(ptr);
0229       move_upd::call_delete(p, move_upd::is_array_del<bmupmu::is_array<T>::value>());
0230    }
0231 
0232    //! <b>Effects</b>: Same as <tt>(*this)(static_cast<element_type*>(nullptr))</tt>.
0233    //!
0234    void operator()(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) const BOOST_NOEXCEPT
0235    {  BOOST_MOVE_STATIC_ASSERT(sizeof(element_type) > 0);  }
0236 };
0237 
0238 }  //namespace movelib {
0239 }  //namespace boost{
0240 
0241 #include <boost/move/detail/config_end.hpp>
0242 
0243 #endif   //#ifndef BOOST_MOVE_DEFAULT_DELETE_HPP_INCLUDED