Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:53:51

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Pablo Halpern 2009. 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 //////////////////////////////////////////////////////////////////////////////
0008 //
0009 // (C) Copyright Ion Gaztanaga 2011-2014. Distributed under the Boost
0010 // Software License, Version 1.0. (See accompanying file
0011 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0012 //
0013 // See http://www.boost.org/libs/intrusive for documentation.
0014 //
0015 //////////////////////////////////////////////////////////////////////////////
0016 
0017 #ifndef BOOST_INTRUSIVE_POINTER_TRAITS_HPP
0018 #define BOOST_INTRUSIVE_POINTER_TRAITS_HPP
0019 
0020 #include <boost/intrusive/detail/config_begin.hpp>
0021 #include <boost/intrusive/detail/workaround.hpp>
0022 #include <boost/intrusive/pointer_rebind.hpp>
0023 #include <boost/move/detail/pointer_element.hpp>
0024 #include <boost/intrusive/detail/mpl.hpp>
0025 #include <cstddef>
0026 
0027 #if defined(BOOST_HAS_PRAGMA_ONCE)
0028 #  pragma once
0029 #endif
0030 
0031 namespace boost {
0032 namespace intrusive {
0033 namespace detail {
0034 
0035 #if !defined(BOOST_MSVC) || (BOOST_MSVC > 1310)
0036 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_pointer_to, pointer_to)
0037 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_dynamic_cast_from, dynamic_cast_from)
0038 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_static_cast_from, static_cast_from)
0039 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_const_cast_from, const_cast_from)
0040 #else
0041 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_pointer_to, pointer_to)
0042 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_dynamic_cast_from, dynamic_cast_from)
0043 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_static_cast_from, static_cast_from)
0044 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_const_cast_from, const_cast_from)
0045 #endif
0046 
0047 BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(element_type)
0048 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type)
0049 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(size_type)
0050 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reference)
0051 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(value_traits_ptr)
0052 
0053 }  //namespace detail {
0054 
0055 
0056 //! pointer_traits is the implementation of C++11 std::pointer_traits class with some
0057 //! extensions like castings.
0058 //!
0059 //! pointer_traits supplies a uniform interface to certain attributes of pointer-like types.
0060 //!
0061 //! <b>Note</b>: When defining a custom family of pointers or references to be used with BI
0062 //! library, make sure the public static conversion functions accessed through
0063 //! the `pointer_traits` interface (`*_cast_from` and `pointer_to`) can
0064 //! properly convert between const and nonconst referred member types
0065 //! <b>without the use of implicit constructor calls</b>. It is suggested these
0066 //! conversions be implemented as function templates, where the template
0067 //! argument is the type of the object being converted from.
0068 template <typename Ptr>
0069 struct pointer_traits
0070 {
0071    #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
0072       //!The pointer type
0073       //!queried by this pointer_traits instantiation
0074       typedef Ptr             pointer;
0075 
0076       //!Ptr::element_type if such a type exists; otherwise, T if Ptr is a class
0077       //!template instantiation of the form SomePointer<T, Args>, where Args is zero or
0078       //!more type arguments ; otherwise , the specialization is ill-formed.
0079       typedef unspecified_type element_type;
0080 
0081       //!Ptr::difference_type if such a type exists; otherwise,
0082       //!std::ptrdiff_t.
0083       typedef unspecified_type difference_type;
0084 
0085       //!Ptr::rebind<U> if such a type exists; otherwise, SomePointer<U, Args> if Ptr is
0086       //!a class template instantiation of the form SomePointer<T, Args>, where Args is zero or
0087       //!more type arguments ; otherwise, the instantiation of rebind is ill-formed.
0088       //!
0089       //!For portable code for C++03 and C++11, <pre>typename rebind_pointer<U>::type</pre>
0090       //!shall be used instead of rebind<U> to obtain a pointer to U.
0091       template <class U> using rebind = unspecified;
0092 
0093       //!Ptr::reference if such a type exists (non-standard extension); otherwise, element_type &
0094       //!
0095       typedef unspecified_type reference;
0096    #else
0097       typedef Ptr                                                             pointer;
0098       //
0099       typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT
0100          ( boost::intrusive::detail::, Ptr, element_type
0101          , boost::movelib::detail::first_param<Ptr>)                          element_type;
0102       //
0103       typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
0104          (boost::intrusive::detail::, Ptr, difference_type, std::ptrdiff_t)   difference_type;
0105 
0106       typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
0107          ( boost::intrusive::detail::, Ptr, size_type
0108          , typename boost::move_detail::
0109                make_unsigned<difference_type>::type)                          size_type;
0110 
0111       typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
0112          ( boost::intrusive::detail::, Ptr, reference
0113          , typename boost::intrusive::detail::unvoid_ref<element_type>::type) reference;
0114       //
0115       template <class U> struct rebind_pointer
0116       {
0117          typedef typename boost::intrusive::pointer_rebind<Ptr, U>::type  type;
0118       };
0119 
0120       #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
0121          template <class U> using rebind = typename boost::intrusive::pointer_rebind<Ptr, U>::type;
0122       #endif
0123    #endif   //#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
0124 
0125    //! <b>Remark</b>: If element_type is (possibly cv-qualified) void, r type is unspecified; otherwise,
0126    //!   it is element_type &.
0127    //!
0128    //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling Ptr::pointer_to(reference).
0129    //!   Non-standard extension: If such function does not exist, returns pointer(addressof(r));
0130    //!
0131    //! <b>Note</b>: For non-conforming compilers only the existence of a member function called
0132    //!   <code>pointer_to</code> is checked.
0133    BOOST_INTRUSIVE_FORCEINLINE static pointer pointer_to(reference r) BOOST_NOEXCEPT
0134    {
0135       //Non-standard extension, it does not require Ptr::pointer_to. If not present
0136       //tries to converts &r to pointer.
0137       const bool value = boost::intrusive::detail::
0138          has_member_function_callable_with_pointer_to
0139             <Ptr, Ptr (*)(reference)>::value;
0140       boost::intrusive::detail::bool_<value> flag;
0141       return pointer_traits::priv_pointer_to(flag, r);
0142    }
0143 
0144    //! <b>Remark</b>: Non-standard extension.
0145    //!
0146    //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling the static template function
0147    //!   Ptr::static_cast_from(UPpr/const UPpr &).
0148    //!   If such function does not exist, returns pointer_to(static_cast<element_type&>(*uptr))
0149    //!
0150    //! <b>Note</b>: For non-conforming compilers only the existence of a member function called
0151    //!   <code>static_cast_from</code> is checked.
0152    template<class UPtr>
0153    BOOST_INTRUSIVE_FORCEINLINE static pointer static_cast_from(const UPtr &uptr) BOOST_NOEXCEPT
0154    {
0155       typedef const UPtr &RefArg;
0156       const bool value = boost::intrusive::detail::
0157          has_member_function_callable_with_static_cast_from
0158             <pointer, pointer(*)(RefArg)>::value
0159          || boost::intrusive::detail::
0160                has_member_function_callable_with_static_cast_from
0161                   <pointer, pointer(*)(UPtr)>::value;
0162       return pointer_traits::priv_static_cast_from(boost::intrusive::detail::bool_<value>(), uptr);
0163    }
0164 
0165    //! <b>Remark</b>: Non-standard extension.
0166    //!
0167    //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling the static template function
0168    //!   Ptr::const_cast_from<UPtr>(UPpr/const UPpr &).
0169    //!   If such function does not exist, returns pointer_to(const_cast<element_type&>(*uptr))
0170    //!
0171    //! <b>Note</b>: For non-conforming compilers only the existence of a member function called
0172    //!   <code>const_cast_from</code> is checked.
0173    template<class UPtr>
0174    BOOST_INTRUSIVE_FORCEINLINE static pointer const_cast_from(const UPtr &uptr) BOOST_NOEXCEPT
0175    {
0176       typedef const UPtr &RefArg;
0177       const bool value = boost::intrusive::detail::
0178          has_member_function_callable_with_const_cast_from
0179             <pointer, pointer(*)(RefArg)>::value
0180          || boost::intrusive::detail::
0181                has_member_function_callable_with_const_cast_from
0182                   <pointer, pointer(*)(UPtr)>::value;
0183       return pointer_traits::priv_const_cast_from(boost::intrusive::detail::bool_<value>(), uptr);
0184    }
0185 
0186    //! <b>Remark</b>: Non-standard extension.
0187    //!
0188    //! <b>Returns</b>: A dereferenceable pointer to r obtained by calling the static template function
0189    //!   Ptr::dynamic_cast_from<UPtr>(UPpr/const UPpr &).
0190    //!   If such function does not exist, returns pointer_to(*dynamic_cast<element_type*>(&*uptr))
0191    //!
0192    //! <b>Note</b>: For non-conforming compilers only the existence of a member function called
0193    //!   <code>dynamic_cast_from</code> is checked.
0194    template<class UPtr>
0195    BOOST_INTRUSIVE_FORCEINLINE static pointer dynamic_cast_from(const UPtr &uptr) BOOST_NOEXCEPT
0196    {
0197       typedef const UPtr &RefArg;
0198       const bool value = boost::intrusive::detail::
0199          has_member_function_callable_with_dynamic_cast_from
0200             <pointer, pointer(*)(RefArg)>::value
0201          || boost::intrusive::detail::
0202                has_member_function_callable_with_dynamic_cast_from
0203                   <pointer, pointer(*)(UPtr)>::value;
0204       return pointer_traits::priv_dynamic_cast_from(boost::intrusive::detail::bool_<value>(), uptr);
0205    }
0206 
0207    ///@cond
0208    private:
0209    //priv_to_raw_pointer
0210    template <class T>
0211    BOOST_INTRUSIVE_FORCEINLINE static T* to_raw_pointer(T* p) BOOST_NOEXCEPT
0212    {  return p; }
0213 
0214    template <class Pointer>
0215    BOOST_INTRUSIVE_FORCEINLINE static typename pointer_traits<Pointer>::element_type*
0216       to_raw_pointer(const Pointer &p) BOOST_NOEXCEPT
0217    {  return pointer_traits::to_raw_pointer(p.operator->());  }
0218 
0219    //priv_pointer_to
0220    BOOST_INTRUSIVE_FORCEINLINE static pointer priv_pointer_to(boost::intrusive::detail::true_, reference r) BOOST_NOEXCEPT
0221    { return Ptr::pointer_to(r); }
0222 
0223    BOOST_INTRUSIVE_FORCEINLINE static pointer priv_pointer_to(boost::intrusive::detail::false_, reference r) BOOST_NOEXCEPT
0224    { return pointer(boost::intrusive::detail::addressof(r)); }
0225 
0226    //priv_static_cast_from
0227    template<class UPtr>
0228    BOOST_INTRUSIVE_FORCEINLINE static pointer priv_static_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) BOOST_NOEXCEPT
0229    { return Ptr::static_cast_from(uptr); }
0230 
0231    template<class UPtr>
0232    BOOST_INTRUSIVE_FORCEINLINE static pointer priv_static_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) BOOST_NOEXCEPT
0233    {  return uptr ? pointer_to(*static_cast<element_type*>(to_raw_pointer(uptr))) : pointer();  }
0234 
0235    //priv_const_cast_from
0236    template<class UPtr>
0237    BOOST_INTRUSIVE_FORCEINLINE static pointer priv_const_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) BOOST_NOEXCEPT
0238    { return Ptr::const_cast_from(uptr); }
0239 
0240    template<class UPtr>
0241    BOOST_INTRUSIVE_FORCEINLINE static pointer priv_const_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) BOOST_NOEXCEPT
0242    {  return uptr ? pointer_to(const_cast<element_type&>(*uptr)) : pointer();  }
0243 
0244    //priv_dynamic_cast_from
0245    template<class UPtr>
0246    BOOST_INTRUSIVE_FORCEINLINE static pointer priv_dynamic_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) BOOST_NOEXCEPT
0247    { return Ptr::dynamic_cast_from(uptr); }
0248 
0249    template<class UPtr>
0250    BOOST_INTRUSIVE_FORCEINLINE static pointer priv_dynamic_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) BOOST_NOEXCEPT
0251    {  return uptr ? pointer_to(dynamic_cast<element_type&>(*uptr)) : pointer();  }
0252    ///@endcond
0253 };
0254 
0255 ///@cond
0256 
0257 // Remove cv qualification from Ptr parameter to pointer_traits:
0258 template <typename Ptr>
0259 struct pointer_traits<const Ptr> : pointer_traits<Ptr> {};
0260 template <typename Ptr>
0261 struct pointer_traits<volatile Ptr> : pointer_traits<Ptr> { };
0262 template <typename Ptr>
0263 struct pointer_traits<const volatile Ptr> : pointer_traits<Ptr> { };
0264 // Remove reference from Ptr parameter to pointer_traits:
0265 template <typename Ptr>
0266 struct pointer_traits<Ptr&> : pointer_traits<Ptr> { };
0267 
0268 ///@endcond
0269 
0270 //! Specialization of pointer_traits for raw pointers
0271 //!
0272 template <typename T>
0273 struct pointer_traits<T*>
0274 {
0275    typedef T               element_type;
0276    typedef T*              pointer;
0277    typedef std::ptrdiff_t  difference_type;
0278    typedef std::size_t     size_type;
0279 
0280    #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
0281       typedef T &          reference;
0282       //!typedef for <pre>U *</pre>
0283       //!
0284       //!For portable code for C++03 and C++11, <pre>typename rebind_pointer<U>::type</pre>
0285       //!shall be used instead of rebind<U> to obtain a pointer to U.
0286       template <class U> using rebind = U*;
0287    #else
0288       typedef typename boost::intrusive::detail::unvoid_ref<element_type>::type reference;
0289       #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
0290          template <class U> using rebind = U*;
0291       #endif
0292    #endif
0293 
0294    template <class U> struct rebind_pointer
0295    {  typedef U* type;  };
0296 
0297    //! <b>Returns</b>: addressof(r)
0298    //!
0299    BOOST_INTRUSIVE_FORCEINLINE static pointer pointer_to(reference r) BOOST_NOEXCEPT
0300    { return boost::intrusive::detail::addressof(r); }
0301 
0302    //! <b>Returns</b>: static_cast<pointer>(uptr)
0303    //!
0304    template<class U>
0305    BOOST_INTRUSIVE_FORCEINLINE static pointer static_cast_from(U *uptr) BOOST_NOEXCEPT
0306    {  return static_cast<pointer>(uptr);  }
0307 
0308    //! <b>Returns</b>: const_cast<pointer>(uptr)
0309    //!
0310    template<class U>
0311    BOOST_INTRUSIVE_FORCEINLINE static pointer const_cast_from(U *uptr) BOOST_NOEXCEPT
0312    {  return const_cast<pointer>(uptr);  }
0313 
0314    //! <b>Returns</b>: dynamic_cast<pointer>(uptr)
0315    //!
0316    template<class U>
0317    BOOST_INTRUSIVE_FORCEINLINE static pointer dynamic_cast_from(U *uptr) BOOST_NOEXCEPT
0318    {  return dynamic_cast<pointer>(uptr);  }
0319 };
0320 
0321 }  //namespace container {
0322 }  //namespace boost {
0323 
0324 #include <boost/intrusive/detail/config_end.hpp>
0325 
0326 #endif // ! defined(BOOST_INTRUSIVE_POINTER_TRAITS_HPP)