Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:43

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/intrusive for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_INTRUSIVE_POINTER_REBIND_HPP
0012 #define BOOST_INTRUSIVE_POINTER_REBIND_HPP
0013 
0014 #ifndef BOOST_INTRUSIVE_DETAIL_WORKAROUND_HPP
0015 #include <boost/intrusive/detail/workaround.hpp>
0016 #endif   //BOOST_INTRUSIVE_DETAIL_WORKAROUND_HPP
0017 
0018 #ifndef BOOST_CONFIG_HPP
0019 #  include <boost/config.hpp>
0020 #endif
0021 
0022 #if defined(BOOST_HAS_PRAGMA_ONCE)
0023 #  pragma once
0024 #endif
0025 
0026 namespace boost {
0027 namespace intrusive {
0028 
0029 ///////////////////////////
0030 //struct pointer_rebind_mode
0031 ///////////////////////////
0032 template <typename Ptr, typename U>
0033 struct pointer_has_rebind
0034 {
0035    template <typename V> struct any
0036    {  any(const V&) { } };
0037 
0038    template <typename X>
0039    static char test(int, typename X::template rebind<U>*);
0040 
0041    template <typename X>
0042    static int test(any<int>, void*);
0043 
0044    static const bool value = (1 == sizeof(test<Ptr>(0, 0)));
0045 };
0046 
0047 template <typename Ptr, typename U>
0048 struct pointer_has_rebind_other
0049 {
0050    template <typename V> struct any
0051    {  any(const V&) { } };
0052 
0053    template <typename X>
0054    static char test(int, typename X::template rebind<U>::other*);
0055 
0056    template <typename X>
0057    static int test(any<int>, void*);
0058 
0059    static const bool value = (1 == sizeof(test<Ptr>(0, 0)));
0060 };
0061 
0062 template <typename Ptr, typename U>
0063 struct pointer_rebind_mode
0064 {
0065    static const unsigned int rebind =       (unsigned int)pointer_has_rebind<Ptr, U>::value;
0066    static const unsigned int rebind_other = (unsigned int)pointer_has_rebind_other<Ptr, U>::value;
0067    static const unsigned int mode =         rebind + rebind*rebind_other;
0068 };
0069 
0070 ////////////////////////
0071 //struct pointer_rebinder
0072 ////////////////////////
0073 template <typename Ptr, typename U, unsigned int RebindMode>
0074 struct pointer_rebinder;
0075 
0076 // Implementation of pointer_rebinder<U>::type if Ptr has
0077 // its own rebind<U>::other type (C++03)
0078 template <typename Ptr, typename U>
0079 struct pointer_rebinder< Ptr, U, 2u >
0080 {
0081    typedef typename Ptr::template rebind<U>::other type;
0082 };
0083 
0084 // Implementation of pointer_rebinder<U>::type if Ptr has
0085 // its own rebind template.
0086 template <typename Ptr, typename U>
0087 struct pointer_rebinder< Ptr, U, 1u >
0088 {
0089    typedef typename Ptr::template rebind<U> type;
0090 };
0091 
0092 // Specialization of pointer_rebinder if Ptr does not
0093 // have its own rebind template but has a the form Ptr<A, An...>,
0094 // where An... comprises zero or more type parameters.
0095 // Many types fit this form, hence many pointers will get a
0096 // reasonable default for rebind.
0097 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0098 
0099 template <template <class, class...> class Ptr, typename A, class... An, class U>
0100 struct pointer_rebinder<Ptr<A, An...>, U, 0u >
0101 {
0102    typedef Ptr<U, An...> type;
0103 };
0104 
0105 //Needed for non-conforming compilers like GCC 4.3
0106 template <template <class> class Ptr, typename A, class U>
0107 struct pointer_rebinder<Ptr<A>, U, 0u >
0108 {
0109    typedef Ptr<U> type;
0110 };
0111 
0112 #else //C++03 compilers
0113 
0114 template <template <class> class Ptr  //0arg
0115          , typename A
0116          , class U>
0117 struct pointer_rebinder<Ptr<A>, U, 0u>
0118 {  typedef Ptr<U> type;   };
0119 
0120 template <template <class, class> class Ptr  //1arg
0121          , typename A, class P0
0122          , class U>
0123 struct pointer_rebinder<Ptr<A, P0>, U, 0u>
0124 {  typedef Ptr<U, P0> type;   };
0125 
0126 template <template <class, class, class> class Ptr  //2arg
0127          , typename A, class P0, class P1
0128          , class U>
0129 struct pointer_rebinder<Ptr<A, P0, P1>, U, 0u>
0130 {  typedef Ptr<U, P0, P1> type;   };
0131 
0132 template <template <class, class, class, class> class Ptr  //3arg
0133          , typename A, class P0, class P1, class P2
0134          , class U>
0135 struct pointer_rebinder<Ptr<A, P0, P1, P2>, U, 0u>
0136 {  typedef Ptr<U, P0, P1, P2> type;   };
0137 
0138 template <template <class, class, class, class, class> class Ptr  //4arg
0139          , typename A, class P0, class P1, class P2, class P3
0140          , class U>
0141 struct pointer_rebinder<Ptr<A, P0, P1, P2, P3>, U, 0u>
0142 {  typedef Ptr<U, P0, P1, P2, P3> type;   };
0143 
0144 template <template <class, class, class, class, class, class> class Ptr  //5arg
0145          , typename A, class P0, class P1, class P2, class P3, class P4
0146          , class U>
0147 struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4>, U, 0u>
0148 {  typedef Ptr<U, P0, P1, P2, P3, P4> type;   };
0149 
0150 template <template <class, class, class, class, class, class, class> class Ptr  //6arg
0151          , typename A, class P0, class P1, class P2, class P3, class P4, class P5
0152          , class U>
0153 struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4, P5>, U, 0u>
0154 {  typedef Ptr<U, P0, P1, P2, P3, P4, P5> type;   };
0155 
0156 template <template <class, class, class, class, class, class, class, class> class Ptr  //7arg
0157          , typename A, class P0, class P1, class P2, class P3, class P4, class P5, class P6
0158          , class U>
0159 struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4, P5, P6>, U, 0u>
0160 {  typedef Ptr<U, P0, P1, P2, P3, P4, P5, P6> type;   };
0161 
0162 template <template <class, class, class, class, class, class, class, class, class> class Ptr  //8arg
0163          , typename A, class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7
0164          , class U>
0165 struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4, P5, P6, P7>, U, 0u>
0166 {  typedef Ptr<U, P0, P1, P2, P3, P4, P5, P6, P7> type;   };
0167 
0168 template <template <class, class, class, class, class, class, class, class, class, class> class Ptr  //9arg
0169          , typename A, class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8
0170          , class U>
0171 struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4, P5, P6, P7, P8>, U, 0u>
0172 {  typedef Ptr<U, P0, P1, P2, P3, P4, P5, P6, P7, P8> type;   };
0173 
0174 #endif   //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0175 
0176 template <typename Ptr, typename U>
0177 struct pointer_rebind
0178    : public pointer_rebinder<Ptr, U, pointer_rebind_mode<Ptr, U>::mode>
0179 {};
0180 
0181 template <typename T, typename U>
0182 struct pointer_rebind<T*, U>
0183 {  typedef U* type; };
0184 
0185 }  //namespace container {
0186 }  //namespace boost {
0187 
0188 #endif // defined(BOOST_INTRUSIVE_POINTER_REBIND_HPP)