////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2014-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_DEFAULT_DELETE_HPP_INCLUDED #define BOOST_MOVE_DEFAULT_DELETE_HPP_INCLUDED #include #include #include #include #include #include //For std::size_t,std::nullptr_t //!\file //! Describes the default deleter (destruction policy) of unique_ptr: default_delete. namespace boost{ namespace move_upd { namespace bmupmu = ::boost::move_upmu; //////////////////////////////////////// //// enable_def_del //////////////////////////////////////// //compatible with a pointer type T*: //When either Y* is convertible to T* //Y is U[N] and T is U cv [] template struct def_del_compatible_cond : bmupmu::is_convertible {}; template struct def_del_compatible_cond : def_del_compatible_cond {}; template struct enable_def_del : bmupmu::enable_if_c::value, Type> {}; //////////////////////////////////////// //// enable_defdel_call //////////////////////////////////////// //When 2nd is T[N], 1st(*)[N] shall be convertible to T(*)[N]; //When 2nd is T[], 1st(*)[] shall be convertible to T(*)[]; //Otherwise, 1st* shall be convertible to 2nd*. template struct enable_defdel_call : public enable_def_del {}; template struct enable_defdel_call : public enable_def_del {}; template struct enable_defdel_call : public enable_def_del {}; //////////////////////////////////////// //// Some bool literal zero conversion utilities //////////////////////////////////////// struct bool_conversion {int for_bool; int for_arg(); }; typedef int bool_conversion::* explicit_bool_arg; #if !defined(BOOST_NO_CXX11_NULLPTR) && !defined(BOOST_NO_CXX11_DECLTYPE) typedef decltype(nullptr) nullptr_type; #elif !defined(BOOST_NO_CXX11_NULLPTR) typedef std::nullptr_t nullptr_type; #else typedef int (bool_conversion::*nullptr_type)(); #endif } //namespace move_upd { namespace movelib { namespace bmupd = boost::move_upd; namespace bmupmu = ::boost::move_upmu; //!The class template default_delete serves as the default deleter //!(destruction policy) for the class template unique_ptr. //! //! \tparam T The type to be deleted. It may be an incomplete type template struct default_delete { //! Default constructor. //! BOOST_CONSTEXPR default_delete() //Avoid "defaulted on its first declaration must not have an exception-specification" error for GCC 4.6 #if !defined(BOOST_GCC) || (BOOST_GCC < 40600 && BOOST_GCC >= 40700) || defined(BOOST_MOVE_DOXYGEN_INVOKED) BOOST_NOEXCEPT #endif #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || defined(BOOST_MOVE_DOXYGEN_INVOKED) = default; #else {}; #endif #if defined(BOOST_MOVE_DOXYGEN_INVOKED) default_delete(const default_delete&) BOOST_NOEXCEPT = default; default_delete &operator=(const default_delete&) BOOST_NOEXCEPT = default; #else typedef typename bmupmu::remove_extent::type element_type; #endif //! Effects: Constructs a default_delete object from another default_delete object. //! //! Remarks: This constructor shall not participate in overload resolution unless: //! - If T is not an array type and U* is implicitly convertible to T*. //! - If T is an array type and U* is a more CV qualified pointer to remove_extent::type. template default_delete(const default_delete& BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmupd::enable_def_del::type* =0) ) BOOST_NOEXCEPT { //If T is not an array type, U derives from T //and T has no virtual destructor, then you have a problem BOOST_STATIC_ASSERT(( !::boost::move_upmu::missing_virtual_destructor::value )); } //! Effects: Constructs a default_delete object from another default_delete object. //! //! Remarks: This constructor shall not participate in overload resolution unless: //! - If T is not an array type and U* is implicitly convertible to T*. //! - If T is an array type and U* is a more CV qualified pointer to remove_extent::type. template BOOST_MOVE_DOC1ST(default_delete&, typename bmupd::enable_def_del::type) operator=(const default_delete&) BOOST_NOEXCEPT { //If T is not an array type, U derives from T //and T has no virtual destructor, then you have a problem BOOST_STATIC_ASSERT(( !::boost::move_upmu::missing_virtual_destructor::value )); return *this; } //! Effects: if T is not an array type, calls delete on static_cast(ptr), //! otherwise calls delete[] on static_cast::type*>(ptr). //! //! Remarks: If U is an incomplete type, the program is ill-formed. //! This operator shall not participate in overload resolution unless: //! - T is not an array type and U* is convertible to T*, OR //! - T is an array type, and remove_cv::type is the same type as //! remove_cv::type>::type and U* is convertible to remove_extent::type*. template BOOST_MOVE_DOC1ST(void, typename bmupd::enable_defdel_call::type) operator()(U* ptr) const BOOST_NOEXCEPT { //U must be a complete type BOOST_STATIC_ASSERT(sizeof(U) > 0); //If T is not an array type, U derives from T //and T has no virtual destructor, then you have a problem BOOST_STATIC_ASSERT(( !::boost::move_upmu::missing_virtual_destructor::value )); element_type * const p = static_cast(ptr); bmupmu::is_array::value ? delete [] p : delete p; } //! Effects: Same as (*this)(static_cast(nullptr)). //! void operator()(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT(sizeof(element_type) > 0); } }; } //namespace movelib { } //namespace boost{ #include #endif //#ifndef BOOST_MOVE_DEFAULT_DELETE_HPP_INCLUDED