diff --git a/include/boost/move/default_delete.hpp b/include/boost/move/default_delete.hpp new file mode 100644 index 0000000..dab8a83 --- /dev/null +++ b/include/boost/move/default_delete.hpp @@ -0,0 +1,173 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (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 + +//!\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) +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_detail; + +//!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 + {} + + //! 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 + { 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); + 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 diff --git a/include/boost/move/detail/unique_ptr_meta_utils.hpp b/include/boost/move/detail/unique_ptr_meta_utils.hpp new file mode 100644 index 0000000..33e4d52 --- /dev/null +++ b/include/boost/move/detail/unique_ptr_meta_utils.hpp @@ -0,0 +1,523 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2012-2012. +// 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. +// +////////////////////////////////////////////////////////////////////////////// + +//! \file + +#ifndef BOOST_MOVE_UNIQUE_PTR_DETAIL_META_UTILS_HPP +#define BOOST_MOVE_UNIQUE_PTR_DETAIL_META_UTILS_HPP + +#include //for std::size_t + +//Small meta-typetraits to support move + +namespace boost { + +#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES +//Forward declare boost::rv +template class rv; +#endif + +namespace move_upmu { + +////////////////////////////////////// +// nat +////////////////////////////////////// +struct nat{}; + +////////////////////////////////////// +// natify +////////////////////////////////////// +template struct natify{}; + +////////////////////////////////////// +// if_c +////////////////////////////////////// +template +struct if_c +{ + typedef T1 type; +}; + +template +struct if_c +{ + typedef T2 type; +}; + +////////////////////////////////////// +// if_ +////////////////////////////////////// +template +struct if_ : if_c<0 != T1::value, T2, T3> +{}; + +//enable_if_ +template +struct enable_if_c +{ + typedef T type; +}; + +////////////////////////////////////// +// enable_if_c +////////////////////////////////////// +template +struct enable_if_c {}; + +////////////////////////////////////// +// enable_if +////////////////////////////////////// +template +struct enable_if : public enable_if_c {}; + +////////////////////////////////////// +// remove_reference +////////////////////////////////////// +template +struct remove_reference +{ + typedef T type; +}; + +template +struct remove_reference +{ + typedef T type; +}; + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + +template +struct remove_reference +{ + typedef T type; +}; + +#else + +template +struct remove_reference< rv > +{ + typedef T type; +}; + +template +struct remove_reference< rv &> +{ + typedef T type; +}; + +template +struct remove_reference< const rv &> +{ + typedef T type; +}; + + +#endif + +////////////////////////////////////// +// remove_const +////////////////////////////////////// +template< class T > +struct remove_const +{ + typedef T type; +}; + +template< class T > +struct remove_const +{ + typedef T type; +}; + +////////////////////////////////////// +// remove_volatile +////////////////////////////////////// +template< class T > +struct remove_volatile +{ + typedef T type; +}; + +template< class T > +struct remove_volatile +{ + typedef T type; +}; + +////////////////////////////////////// +// remove_cv +////////////////////////////////////// +template< class T > +struct remove_cv +{ + typedef typename remove_volatile + ::type>::type type; +}; + +////////////////////////////////////// +// remove_extent +////////////////////////////////////// +template +struct remove_extent +{ + typedef T type; +}; + +template +struct remove_extent +{ + typedef T type; +}; + +template +struct remove_extent +{ + typedef T type; +}; + +////////////////////////////////////// +// extent +////////////////////////////////////// + +template +struct extent +{ + static const std::size_t value = 0; +}; + +template +struct extent +{ + static const std::size_t value = 0; +}; + +template +struct extent +{ + static const std::size_t value = extent::value; +}; + +template +struct extent +{ + static const std::size_t value = N; +}; + +template +struct extent +{ + static const std::size_t value = extent::value; +}; + +////////////////////////////////////// +// add_lvalue_reference +////////////////////////////////////// +template +struct add_lvalue_reference +{ + typedef T& type; +}; + +template +struct add_lvalue_reference +{ + typedef T& type; +}; + +template<> +struct add_lvalue_reference +{ + typedef void type; +}; + +template<> +struct add_lvalue_reference +{ + typedef const void type; +}; + +template<> +struct add_lvalue_reference +{ + typedef volatile void type; +}; + +template<> +struct add_lvalue_reference +{ + typedef const volatile void type; +}; + +template +struct add_const_lvalue_reference +{ + typedef typename remove_reference::type t_unreferenced; + typedef const t_unreferenced t_unreferenced_const; + typedef typename add_lvalue_reference + ::type type; +}; + +////////////////////////////////////// +// is_same +////////////////////////////////////// +template +struct is_same +{ + static const bool value = false; +}; + +template +struct is_same +{ + static const bool value = true; +}; + +////////////////////////////////////// +// is_pointer +////////////////////////////////////// +template< class T > +struct is_pointer +{ + static const bool value = false; +}; + +template< class T > +struct is_pointer +{ + static const bool value = true; +}; + +////////////////////////////////////// +// is_reference +////////////////////////////////////// +template< class T > +struct is_reference +{ + static const bool value = false; +}; + +template< class T > +struct is_reference +{ + static const bool value = true; +}; + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + +template< class T > +struct is_reference +{ + static const bool value = true; +}; + +#endif + +////////////////////////////////////// +// is_lvalue_reference +////////////////////////////////////// +template +struct is_lvalue_reference +{ + static const bool value = false; +}; + +template +struct is_lvalue_reference +{ + static const bool value = true; +}; + +////////////////////////////////////// +// is_array +////////////////////////////////////// +template +struct is_array +{ + static const bool value = false; +}; + +template +struct is_array +{ + static const bool value = true; +}; + +template +struct is_array +{ + static const bool value = true; +}; + +////////////////////////////////////// +// has_pointer_type +////////////////////////////////////// +template +struct has_pointer_type +{ + struct two { char c[2]; }; + template static two test(...); + template static char test(typename U::pointer* = 0); + static const bool value = sizeof(test(0)) == 1; +}; + +////////////////////////////////////// +// pointer_type +////////////////////////////////////// +template ::value> +struct pointer_type_imp +{ + typedef typename D::pointer type; +}; + +template +struct pointer_type_imp +{ + typedef typename remove_extent::type* type; +}; + +template +struct pointer_type +{ + typedef typename pointer_type_imp + ::type, typename remove_reference::type>::type type; +}; + +////////////////////////////////////// +// is_convertible +////////////////////////////////////// +#if defined(_MSC_VER) && (_MSC_VER >= 1400) + +//use intrinsic since in MSVC +//overaligned types can't go through ellipsis +template +struct is_convertible +{ + static const bool value = __is_convertible_to(T, U); +}; + +#else + +template +class is_convertible +{ + typedef typename add_lvalue_reference::type t_reference; + typedef char true_t; + class false_t { char dummy[2]; }; + static false_t dispatch(...); + static true_t dispatch(U); + static t_reference trigger(); + public: + static const bool value = sizeof(dispatch(trigger())) == sizeof(true_t); +}; + +#endif + +////////////////////////////////////// +// is_unary_function +////////////////////////////////////// +#if defined(BOOST_MSVC) || defined(__BORLANDC_) +#define BOOST_MOVE_TT_DECL __cdecl +#else +#define BOOST_MOVE_TT_DECL +#endif + +#if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64) && !defined(_M_ARM) && !defined(UNDER_CE) +#define BOOST_MOVE_TT_TEST_MSC_FUNC_SIGS +#endif + +template +struct is_unary_function_impl +{ static const bool value = false; }; + +// avoid duplicate definitions of is_unary_function_impl +#ifndef BOOST_MOVE_TT_TEST_MSC_FUNC_SIGS + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +#else // BOOST_MOVE_TT_TEST_MSC_FUNC_SIGS + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +#ifndef _MANAGED + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +#endif + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +#endif + +// avoid duplicate definitions of is_unary_function_impl +#ifndef BOOST_MOVE_TT_TEST_MSC_FUNC_SIGS + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +#else // BOOST_MOVE_TT_TEST_MSC_FUNC_SIGS + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +#ifndef _MANAGED + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +#endif + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +template +struct is_unary_function_impl +{ static const bool value = true; }; + +#endif + +template +struct is_unary_function_impl +{ static const bool value = false; }; + +template +struct is_unary_function +{ static const bool value = is_unary_function_impl::value; }; + +} //namespace move_upmu { +} //namespace boost { + +#endif //#ifndef BOOST_MOVE_UNIQUE_PTR_DETAIL_META_UTILS_HPP diff --git a/include/boost/move/unique_ptr.hpp b/include/boost/move/unique_ptr.hpp index 5544d55..a78ca66 100644 --- a/include/boost/move/unique_ptr.hpp +++ b/include/boost/move/unique_ptr.hpp @@ -13,8 +13,9 @@ #include #include +#include +#include #include -#include #include #include @@ -36,8 +37,7 @@ //! cv-less T and cv-less U are the same type and T is more CV qualified than U. namespace boost{ - -namespace move_detail { +namespace move_upd { //////////////////////////////////////////// // deleter types @@ -58,25 +58,25 @@ class is_noncopyable template struct deleter_types { - typedef typename add_lvalue_reference::type del_ref; - typedef typename add_const_lvalue_reference::type del_cref; + typedef typename bmupmu::add_lvalue_reference::type del_ref; + typedef typename bmupmu::add_const_lvalue_reference::type del_cref; #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - typedef typename if_c - < is_lvalue_reference::value, D, del_cref >::type deleter_arg_type1; - typedef typename remove_reference::type && deleter_arg_type2; + typedef typename bmupmu::if_c + < bmupmu::is_lvalue_reference::value, D, del_cref >::type deleter_arg_type1; + typedef typename bmupmu::remove_reference::type && deleter_arg_type2; #else - typedef typename if_c - < is_noncopyable::value, nat, del_cref>::type non_ref_deleter_arg1; - typedef typename if_c< is_lvalue_reference::value - , D, non_ref_deleter_arg1 >::type deleter_arg_type1; - typedef ::boost::rv & deleter_arg_type2; + typedef typename bmupmu::if_c + < is_noncopyable::value, bmupmu::nat, del_cref>::type non_ref_deleter_arg1; + typedef typename bmupmu::if_c< bmupmu::is_lvalue_reference::value + , D, non_ref_deleter_arg1 >::type deleter_arg_type1; + typedef ::boost::rv & deleter_arg_type2; #endif }; //////////////////////////////////////////// // unique_ptr_data //////////////////////////////////////////// -template ::value || is_reference::value > +template ::value || bmupmu::is_reference::value > struct unique_ptr_data { typedef typename deleter_types::deleter_arg_type1 deleter_arg_type1; @@ -155,11 +155,11 @@ struct unique_ptr_data template struct get_element_type { - struct DefaultWrap { typedef natify element_type; }; + struct DefaultWrap { typedef bmupmu::natify element_type; }; template static char test(int, typename X::element_type*); template static int test(...); static const bool value = (1 == sizeof(test(0, 0))); - typedef typename if_c::type::element_type type; + typedef typename bmupmu::if_c::type::element_type type; }; template @@ -170,18 +170,17 @@ struct get_element_type template struct get_cvelement -{ - typedef typename remove_cv::type>::type type; -}; + : bmupmu::remove_cv::type> +{}; template struct is_same_cvelement_and_convertible { - typedef typename remove_reference::type arg1; - typedef typename remove_reference::type arg2; + typedef typename bmupmu::remove_reference::type arg1; + typedef typename bmupmu::remove_reference::type arg2; static const bool same_cvless = - is_same::type,typename get_cvelement::type>::value; - static const bool value = same_cvless && is_convertible::value; + bmupmu::is_same::type,typename get_cvelement::type>::value; + static const bool value = same_cvless && bmupmu::is_convertible::value; }; template @@ -191,63 +190,17 @@ struct is_unique_ptr_convertible template struct is_unique_ptr_convertible - : is_convertible -{}; - -//////////////////////////////////////// -//// 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 -{ - static const bool value = is_convertible::value; -}; - -template -struct def_del_compatible_cond -{ - static const bool value = def_del_compatible_cond::value; -}; - -template -struct enable_def_del - : 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 + : bmupmu::is_convertible {}; //////////////////////////////////////// //// enable_up_moveconv_assign //////////////////////////////////////// -template +template struct enable_up_ptr - : enable_if_c< is_unique_ptr_convertible < is_array::value, FromPointer, ThisPointer>::value, Type> + : bmupmu::enable_if_c< is_unique_ptr_convertible + < bmupmu::is_array::value, FromPointer, ThisPointer>::value, Type> {}; //////////////////////////////////////// @@ -257,53 +210,40 @@ struct enable_up_ptr template struct unique_moveconvert_assignable { - static const bool value = (extent::value == extent::value)&& is_unique_ptr_convertible - ::value, typename pointer_type::type, typename pointer_type::type>::value; + static const bool value = (bmupmu::extent::value == bmupmu::extent::value) && is_unique_ptr_convertible + < bmupmu::is_array::value + , typename bmupmu::pointer_type::type, typename bmupmu::pointer_type::type>::value; }; template struct unique_moveconvert_assignable -{ - static const bool value = unique_moveconvert_assignable::value; -}; -/* -template -struct unique_moveconvert_assignable -{ - static const bool value = unique_moveconvert_assignable::value; -}; + : unique_moveconvert_assignable +{}; -template -struct unique_moveconvert_assignable -{ - static const bool value = (M == N) && unique_moveconvert_assignable::value; -}; -*/ -template +template struct enable_up_moveconv_assign - : enable_if_c::value, Type> + : bmupmu::enable_if_c::value, Type> {}; //////////////////////////////////////// //// enable_up_moveconv_constr //////////////////////////////////////// -template::value> +template::value> struct unique_deleter_is_initializable -{ - static const bool value = is_same::value; -}; + : bmupmu::is_same +{}; template class is_rvalue_convertible { #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - typedef typename remove_reference::type&& t_from; + typedef typename bmupmu::remove_reference::type&& t_from; #else - typedef typename if_c - < has_move_emulation_enabled::value && !is_reference::value - , boost::rv& - , typename add_lvalue_reference::type + typedef typename bmupmu::if_c + < ::boost::has_move_emulation_enabled::value && !bmupmu::is_reference::value + , ::boost::rv& + , typename bmupmu::add_lvalue_reference::type >::type t_from; #endif @@ -339,103 +279,16 @@ struct unique_deleter_is_initializable #endif }; -template +template struct enable_up_moveconv_constr - : enable_if_c::value && - unique_deleter_is_initializable::value, Type> + : bmupmu::enable_if_c::value && + unique_deleter_is_initializable::value, Type> {}; -//////////////////////////////////////// -//// 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) -typedef std::nullptr_t nullptr_type; -#else -typedef int (bool_conversion::*nullptr_type)(); -#endif - -} //namespace move_detail { +} //namespace move_upd { namespace movelib { -namespace bmd = boost::move_detail; - -//!The class template default_delete serves as the default deleter -//!(destruction policy) for the class template unique_ptr. -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 bmd::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 bmd::enable_def_del::type* =0) - ) BOOST_NOEXCEPT - {} - - //! 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 bmd::enable_def_del::type) - operator=(const default_delete&) BOOST_NOEXCEPT - { 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 bmd::enable_defdel_call::type) - operator()(U* ptr) const BOOST_NOEXCEPT - { - //U must be a complete type - BOOST_STATIC_ASSERT(sizeof(U) > 0); - element_type * const p = static_cast(ptr); - bmd::is_array::value ? delete [] p : delete p; - } - - //! Effects: Same as (*this)(static_cast(nullptr)). - //! - void operator()(BOOST_MOVE_DOC0PTR(bmd::nullptr_type)) const BOOST_NOEXCEPT - { BOOST_STATIC_ASSERT(sizeof(element_type) > 0); } -}; - - //! A unique pointer is an object that owns another object and //! manages that other object through a pointer. //! @@ -491,11 +344,11 @@ class unique_ptr #else BOOST_MOVABLE_BUT_NOT_COPYABLE(unique_ptr) - typedef move_detail::pointer_type pointer_type_obtainer; - typedef bmd::unique_ptr_data + typedef bmupmu::pointer_type pointer_type_obtainer; + typedef bmupd::unique_ptr_data data_type; - typedef typename bmd::deleter_types::deleter_arg_type1 deleter_arg_type1; - typedef typename bmd::deleter_types::deleter_arg_type2 deleter_arg_type2; + typedef typename bmupd::deleter_types::deleter_arg_type1 deleter_arg_type1; + typedef typename bmupd::deleter_types::deleter_arg_type2 deleter_arg_type2; data_type m_data; #endif @@ -506,7 +359,7 @@ class unique_ptr typedef typename BOOST_MOVE_SEEDOC(pointer_type_obtainer::type) pointer; //! If T is an array type, then element_type is equal to T. Otherwise, if T is a type //! in the form U[], element_type is equal to U. - typedef typename BOOST_MOVE_SEEDOC(bmd::remove_extent::type) element_type; + typedef typename BOOST_MOVE_SEEDOC(bmupmu::remove_extent::type) element_type; typedef D deleter_type; //! Requires: D shall satisfy the requirements of DefaultConstructible, and @@ -524,19 +377,19 @@ class unique_ptr { //If this constructor is instantiated with a pointer type or reference type //for the template argument D, the program is ill-formed. - BOOST_STATIC_ASSERT(!bmd::is_pointer::value); - BOOST_STATIC_ASSERT(!bmd::is_reference::value); + BOOST_STATIC_ASSERT(!bmupmu::is_pointer::value); + BOOST_STATIC_ASSERT(!bmupmu::is_reference::value); } //! Effects: Same as unique_ptr() (default constructor). //! - BOOST_CONSTEXPR unique_ptr(BOOST_MOVE_DOC0PTR(bmd::nullptr_type)) BOOST_NOEXCEPT + BOOST_CONSTEXPR unique_ptr(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) BOOST_NOEXCEPT : m_data() { //If this constructor is instantiated with a pointer type or reference type //for the template argument D, the program is ill-formed. - BOOST_STATIC_ASSERT(!bmd::is_pointer::value); - BOOST_STATIC_ASSERT(!bmd::is_reference::value); + BOOST_STATIC_ASSERT(!bmupmu::is_pointer::value); + BOOST_STATIC_ASSERT(!bmupmu::is_reference::value); } //! Requires: D shall satisfy the requirements of DefaultConstructible, and @@ -554,14 +407,14 @@ class unique_ptr //! - If T is an array type and Pointer is a more CV qualified pointer to element_type. template explicit unique_ptr(Pointer p - BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmd::enable_up_ptr::type* =0) + BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmupd::enable_up_ptr::type* =0) ) BOOST_NOEXCEPT : m_data(p) { //If this constructor is instantiated with a pointer type or reference type //for the template argument D, the program is ill-formed. - BOOST_STATIC_ASSERT(!bmd::is_pointer::value); - BOOST_STATIC_ASSERT(!bmd::is_reference::value); + BOOST_STATIC_ASSERT(!bmupmu::is_pointer::value); + BOOST_STATIC_ASSERT(!bmupmu::is_reference::value); } //!The signature of this constructor depends upon whether D is a reference type. @@ -588,14 +441,14 @@ class unique_ptr //! - If T is an array type and Pointer is a more CV qualified pointer to element_type. template unique_ptr(Pointer p, BOOST_MOVE_SEEDOC(deleter_arg_type1) d1 - BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmd::enable_up_ptr::type* =0) + BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmupd::enable_up_ptr::type* =0) ) BOOST_NOEXCEPT : m_data(p, d1) {} //! Effects: Same effects as template unique_ptr(Pointer p, deleter_arg_type1 d1) //! and additionally get() == nullptr - unique_ptr(BOOST_MOVE_DOC0PTR(bmd::nullptr_type), BOOST_MOVE_SEEDOC(deleter_arg_type1) d1) BOOST_NOEXCEPT + unique_ptr(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), BOOST_MOVE_SEEDOC(deleter_arg_type1) d1) BOOST_NOEXCEPT : m_data(pointer(), d1) {} @@ -621,14 +474,14 @@ class unique_ptr //! - If T is an array type and Pointer is a more CV qualified pointer to element_type. template unique_ptr(Pointer p, BOOST_MOVE_SEEDOC(deleter_arg_type2) d2 - BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmd::enable_up_ptr::type* =0) + BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmupd::enable_up_ptr::type* =0) ) BOOST_NOEXCEPT : m_data(p, ::boost::move(d2)) {} //! Effects: Same effects as template unique_ptr(Pointer p, deleter_arg_type2 d2) //! and additionally get() == nullptr - unique_ptr(BOOST_MOVE_DOC0PTR(bmd::nullptr_type), BOOST_MOVE_SEEDOC(deleter_arg_type2) d2) BOOST_NOEXCEPT + unique_ptr(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), BOOST_MOVE_SEEDOC(deleter_arg_type2) d2) BOOST_NOEXCEPT : m_data(pointer(), ::boost::move(d2)) {} @@ -663,7 +516,7 @@ class unique_ptr //! returns a reference to the stored deleter that was constructed from u.get_deleter(). template unique_ptr( BOOST_RV_REF_BEG unique_ptr BOOST_RV_REF_END u - BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmd::enable_up_moveconv_constr::type* =0) + BOOST_MOVE_DOCIGN(BOOST_MOVE_I typename bmupd::enable_up_moveconv_constr::type* =0) ) BOOST_NOEXCEPT : m_data(u.release(), ::boost::move_if_not_lvalue_reference(u.get_deleter())) {} @@ -706,7 +559,7 @@ class unique_ptr //! //! Returns: *this. template - BOOST_MOVE_DOC1ST(unique_ptr&, typename bmd::enable_up_moveconv_assign + BOOST_MOVE_DOC1ST(unique_ptr&, typename bmupd::enable_up_moveconv_assign ::type) operator=(BOOST_RV_REF_BEG unique_ptr BOOST_RV_REF_END u) BOOST_NOEXCEPT { @@ -720,7 +573,7 @@ class unique_ptr //! Postcondition: get() == nullptr //! //! Returns: *this. - unique_ptr& operator=(BOOST_MOVE_DOC0PTR(bmd::nullptr_type)) BOOST_NOEXCEPT + unique_ptr& operator=(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) BOOST_NOEXCEPT { this->reset(); return *this; } //! Requires: get() != nullptr. @@ -728,10 +581,10 @@ class unique_ptr //! Returns: *get(). //! //! Remarks::type) + BOOST_MOVE_DOC1ST(element_type&, typename bmupmu::add_lvalue_reference::type) operator*() const BOOST_NOEXCEPT { - BOOST_STATIC_ASSERT((!bmd::is_array::value)); + BOOST_STATIC_ASSERT((!bmupmu::is_array::value)); return *m_data.m_p; } @@ -740,10 +593,10 @@ class unique_ptr //! Returns: get()[i]. //! //! Remarks::type) + BOOST_MOVE_DOC1ST(element_type&, typename bmupmu::add_lvalue_reference::type) operator[](std::size_t i) const BOOST_NOEXCEPT { - BOOST_ASSERT( bmd::extent::value == 0 || i < bmd::extent::value ); + BOOST_ASSERT( bmupmu::extent::value == 0 || i < bmupmu::extent::value ); BOOST_ASSERT(m_data.m_p); return m_data.m_p[i]; } @@ -757,7 +610,7 @@ class unique_ptr //! Remarks() const BOOST_NOEXCEPT { - BOOST_STATIC_ASSERT((!bmd::is_array::value)); + BOOST_STATIC_ASSERT((!bmupmu::is_array::value)); BOOST_ASSERT(m_data.m_p); return m_data.m_p; } @@ -769,13 +622,13 @@ class unique_ptr //! Returns: A reference to the stored deleter. //! - BOOST_MOVE_DOC1ST(D&, typename bmd::add_lvalue_reference::type) + BOOST_MOVE_DOC1ST(D&, typename bmupmu::add_lvalue_reference::type) get_deleter() BOOST_NOEXCEPT { return m_data.deleter(); } //! Returns: A reference to the stored deleter. //! - BOOST_MOVE_DOC1ST(const D&, typename bmd::add_const_lvalue_reference::type) + BOOST_MOVE_DOC1ST(const D&, typename bmupmu::add_const_lvalue_reference::type) get_deleter() const BOOST_NOEXCEPT { return m_data.deleter(); } @@ -784,13 +637,13 @@ class unique_ptr //! explicit operator bool #else - operator bmd::explicit_bool_arg + operator bmupd::explicit_bool_arg #endif ()const BOOST_NOEXCEPT { return m_data.m_p - ? &bmd::bool_conversion::for_bool - : bmd::explicit_bool_arg(0); + ? &bmupd::bool_conversion::for_bool + : bmupd::explicit_bool_arg(0); } //! Postcondition: get() == nullptr. @@ -817,7 +670,7 @@ class unique_ptr //! - If T is not an array type and Pointer is implicitly convertible to pointer. //! - If T is an array type and Pointer is a more CV qualified pointer to element_type. template - BOOST_MOVE_DOC1ST(void, typename bmd::enable_up_ptr::type) + BOOST_MOVE_DOC1ST(void, typename bmupd::enable_up_ptr::type) reset(Pointer p) BOOST_NOEXCEPT { pointer tmp = m_data.m_p; @@ -839,7 +692,7 @@ class unique_ptr //! Effects: Same as reset() //! - void reset(BOOST_MOVE_DOC0PTR(bmd::nullptr_type)) BOOST_NOEXCEPT + void reset(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) BOOST_NOEXCEPT { this->reset(); } //! Requires: get_deleter() shall be swappable and shall not throw an exception under swap. @@ -847,7 +700,7 @@ class unique_ptr //! Effects: Invokes swap on the stored pointers and on the stored deleters of *this and u. void swap(unique_ptr& u) BOOST_NOEXCEPT { - using bmd::swap; + using bmupmu::swap; swap(m_data.m_p, u.m_data.m_p); swap(m_data.deleter(), u.m_data.deleter()); } @@ -900,76 +753,76 @@ inline bool operator>=(const unique_ptr &x, const unique_ptr &y) //! Returns:!x. //! template -inline bool operator==(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmd::nullptr_type)) BOOST_NOEXCEPT +inline bool operator==(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) BOOST_NOEXCEPT { return !x; } //! Returns:!x. //! template -inline bool operator==(BOOST_MOVE_DOC0PTR(bmd::nullptr_type), const unique_ptr &x) BOOST_NOEXCEPT +inline bool operator==(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), const unique_ptr &x) BOOST_NOEXCEPT { return !x; } //! Returns: (bool)x. //! template -inline bool operator!=(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmd::nullptr_type)) BOOST_NOEXCEPT +inline bool operator!=(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) BOOST_NOEXCEPT { return !!x; } //! Returns: (bool)x. //! template -inline bool operator!=(BOOST_MOVE_DOC0PTR(bmd::nullptr_type), const unique_ptr &x) BOOST_NOEXCEPT +inline bool operator!=(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), const unique_ptr &x) BOOST_NOEXCEPT { return !!x; } //! Requires: operator shall induce a strict weak ordering on unique_ptr::pointer values. //! //! Returns: Returns x.get() < pointer(). template -inline bool operator<(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmd::nullptr_type)) +inline bool operator<(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) { return x.get() < typename unique_ptr::pointer(); } //! Requires: operator shall induce a strict weak ordering on unique_ptr::pointer values. //! //! Returns: Returns pointer() < x.get(). template -inline bool operator<(BOOST_MOVE_DOC0PTR(bmd::nullptr_type), const unique_ptr &x) +inline bool operator<(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), const unique_ptr &x) { return typename unique_ptr::pointer() < x.get(); } //! Returns: nullptr < x. //! template -inline bool operator>(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmd::nullptr_type)) +inline bool operator>(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) { return x.get() > typename unique_ptr::pointer(); } //! Returns: x < nullptr. //! template -inline bool operator>(BOOST_MOVE_DOC0PTR(bmd::nullptr_type), const unique_ptr &x) +inline bool operator>(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), const unique_ptr &x) { return typename unique_ptr::pointer() > x.get(); } //! Returns: !(nullptr < x). //! template -inline bool operator<=(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmd::nullptr_type)) -{ return !(bmd::nullptr_type() < x); } +inline bool operator<=(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) +{ return !(bmupd::nullptr_type() < x); } //! Returns: !(x < nullptr). //! template -inline bool operator<=(BOOST_MOVE_DOC0PTR(bmd::nullptr_type), const unique_ptr &x) -{ return !(x < bmd::nullptr_type()); } +inline bool operator<=(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), const unique_ptr &x) +{ return !(x < bmupd::nullptr_type()); } //! Returns: !(x < nullptr). //! template -inline bool operator>=(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmd::nullptr_type)) -{ return !(x < bmd::nullptr_type()); } +inline bool operator>=(const unique_ptr &x, BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) +{ return !(x < bmupd::nullptr_type()); } //! Returns: !(nullptr < x). //! template -inline bool operator>=(BOOST_MOVE_DOC0PTR(bmd::nullptr_type), const unique_ptr &x) -{ return !(bmd::nullptr_type() < x); } +inline bool operator>=(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), const unique_ptr &x) +{ return !(bmupd::nullptr_type() < x); } } //namespace movelib { } //namespace boost{ diff --git a/proj/vc7ide/Move.sln b/proj/vc7ide/Move.sln index e9d250b..b43ac07 100644 --- a/proj/vc7ide/Move.sln +++ b/proj/vc7ide/Move.sln @@ -95,7 +95,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unique_ptr_nullptr_test", " ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unique_ptr_test", "unique_ptr_observers_test.vcproj", "{C57C28A3-4FE0-6208-BF87-B2B61D3A7670}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unique_ptr_observers_test", "unique_ptr_observers_test.vcproj", "{C57C28A3-4FE0-6208-BF87-B2B61D3A7670}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject @@ -221,6 +221,7 @@ Global ..\..\..\..\boost\move\detail\config_begin.hpp = ..\..\..\..\boost\move\detail\config_begin.hpp ..\..\..\..\boost\move\detail\config_end.hpp = ..\..\..\..\boost\move\detail\config_end.hpp ..\..\..\..\boost\move\core.hpp = ..\..\..\..\boost\move\core.hpp + ..\..\..\..\boost\move\default_delete.hpp = ..\..\..\..\boost\move\default_delete.hpp ..\..\..\..\boost\move\iterator.hpp = ..\..\..\..\boost\move\iterator.hpp ..\..\doc\Jamfile.v2 = ..\..\doc\Jamfile.v2 ..\..\..\..\boost\move\make_unique.hpp = ..\..\..\..\boost\move\make_unique.hpp diff --git a/test/unique_ptr_default_deleter.cpp b/test/unique_ptr_default_deleter.cpp index cbe6255..67b36ea 100644 --- a/test/unique_ptr_default_deleter.cpp +++ b/test/unique_ptr_default_deleter.cpp @@ -10,7 +10,7 @@ // See http://www.boost.org/libs/move for documentation. // ////////////////////////////////////////////////////////////////////////////// -#include +#include #include ////////////////////////////////////////////// diff --git a/test/unique_ptr_movector.cpp b/test/unique_ptr_movector.cpp index b8d7aa7..ece216b 100644 --- a/test/unique_ptr_movector.cpp +++ b/test/unique_ptr_movector.cpp @@ -32,6 +32,7 @@ #include "unique_ptr_test_utils_beg.hpp" namespace bml = ::boost::movelib; +namespace bmupmu = ::boost::move_upmu; //////////////////////////////// // unique_ptr_ctor_move_defdel @@ -266,7 +267,7 @@ void test() { //Single unique_ptr reset_counters(); - BOOST_STATIC_ASSERT((boost::move_detail::is_convertible::value)); + BOOST_STATIC_ASSERT((bmupmu::is_convertible::value)); { bml::unique_ptr > s(new B); A* p = s.get(); diff --git a/test/unique_ptr_test_utils_beg.hpp b/test/unique_ptr_test_utils_beg.hpp index 51995f5..a98e926 100644 --- a/test/unique_ptr_test_utils_beg.hpp +++ b/test/unique_ptr_test_utils_beg.hpp @@ -71,13 +71,13 @@ class copy_constr_deleter template copy_constr_deleter(const copy_constr_deleter& - , typename boost::move_detail::enable_def_del::type* =0) + , typename boost::move_upd::enable_def_del::type* =0) { state_ = 5; } explicit copy_constr_deleter(int s) : state_(s) {} template - typename boost::move_detail::enable_def_del::type + typename boost::move_upd::enable_def_del::type operator=(const copy_constr_deleter &d) { state_ = d.state(); @@ -117,7 +117,7 @@ class move_constr_deleter template move_constr_deleter(BOOST_RV_REF(move_constr_deleter) d - , typename boost::move_detail::enable_def_del::type* =0) + , typename boost::move_upd::enable_def_del::type* =0) : state_(d.state()) { d.set_state(0); } @@ -129,7 +129,7 @@ class move_constr_deleter } template - typename boost::move_detail::enable_def_del::type + typename boost::move_upd::enable_def_del::type operator=(BOOST_RV_REF(move_constr_deleter) d) { state_ = d.state(); diff --git a/test/unique_ptr_types.cpp b/test/unique_ptr_types.cpp index 6d7d4a8..484c906 100644 --- a/test/unique_ptr_types.cpp +++ b/test/unique_ptr_types.cpp @@ -32,6 +32,7 @@ #include "unique_ptr_test_utils_beg.hpp" namespace bml = ::boost::movelib; +namespace bmupmu = ::boost::move_upmu; //////////////////////////////// // unique_ptr_pointer_type @@ -49,29 +50,29 @@ void test() //Single unique_ptr { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } //Unbounded array unique_ptr { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } //Bounded array unique_ptr { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } } @@ -91,29 +92,29 @@ void test() //Single unique_ptr { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same >::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same >::value)); } { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } //Unbounded array unique_ptr { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same >::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same >::value)); } { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } //Bounded array unique_ptr { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same >::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same >::value)); } { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } } @@ -130,17 +131,17 @@ void test() //Single unique_ptr { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } //Unbounded array unique_ptr { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } //Bounded array unique_ptr { typedef bml::unique_ptr P; - BOOST_STATIC_ASSERT((boost::move_detail::is_same::value)); + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } }