Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-03 08:10:30

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