Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 1 | ////////////////////////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // (C) Copyright Ion Gaztanaga 2005-2012. |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // See http://www.boost.org/libs/container for documentation. |
| 10 | // |
| 11 | ////////////////////////////////////////////////////////////////////////////// |
| 12 | |
| 13 | #ifndef BOOST_CONTAINER_CONTAINER_DETAIL_MPL_HPP |
| 14 | #define BOOST_CONTAINER_CONTAINER_DETAIL_MPL_HPP |
| 15 | |
| 16 | #if (defined _MSC_VER) && (_MSC_VER >= 1200) |
| 17 | # pragma once |
| 18 | #endif |
| 19 | |
| 20 | #include <cstddef> |
| 21 | |
| 22 | namespace ndnboost { |
| 23 | namespace container { |
| 24 | namespace container_detail { |
| 25 | |
| 26 | template <class T, T val> |
| 27 | struct integral_constant |
| 28 | { |
| 29 | static const T value = val; |
| 30 | typedef integral_constant<T,val> type; |
| 31 | }; |
| 32 | |
| 33 | template< bool C_ > |
| 34 | struct bool_ : integral_constant<bool, C_> |
| 35 | { |
| 36 | static const bool value = C_; |
| 37 | operator bool() const { return bool_::value; } |
| 38 | }; |
| 39 | |
| 40 | typedef bool_<true> true_; |
| 41 | typedef bool_<false> false_; |
| 42 | |
| 43 | typedef true_ true_type; |
| 44 | typedef false_ false_type; |
| 45 | |
| 46 | typedef char yes_type; |
| 47 | struct no_type |
| 48 | { |
| 49 | char padding[8]; |
| 50 | }; |
| 51 | |
| 52 | template <bool B, class T = void> |
| 53 | struct enable_if_c { |
| 54 | typedef T type; |
| 55 | }; |
| 56 | |
| 57 | template <class T> |
| 58 | struct enable_if_c<false, T> {}; |
| 59 | |
| 60 | template <class Cond, class T = void> |
| 61 | struct enable_if : public enable_if_c<Cond::value, T> {}; |
| 62 | |
| 63 | template <class Cond, class T = void> |
| 64 | struct disable_if : public enable_if_c<!Cond::value, T> {}; |
| 65 | |
| 66 | template <bool B, class T = void> |
| 67 | struct disable_if_c : public enable_if_c<!B, T> {}; |
| 68 | |
| 69 | template <class T, class U> |
| 70 | class is_convertible |
| 71 | { |
| 72 | typedef char true_t; |
| 73 | class false_t { char dummy[2]; }; |
| 74 | static true_t dispatch(U); |
| 75 | static false_t dispatch(...); |
| 76 | static T trigger(); |
| 77 | public: |
| 78 | enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) }; |
| 79 | }; |
| 80 | |
| 81 | template< |
| 82 | bool C |
| 83 | , typename T1 |
| 84 | , typename T2 |
| 85 | > |
| 86 | struct if_c |
| 87 | { |
| 88 | typedef T1 type; |
| 89 | }; |
| 90 | |
| 91 | template< |
| 92 | typename T1 |
| 93 | , typename T2 |
| 94 | > |
| 95 | struct if_c<false,T1,T2> |
| 96 | { |
| 97 | typedef T2 type; |
| 98 | }; |
| 99 | |
| 100 | template< |
| 101 | typename T1 |
| 102 | , typename T2 |
| 103 | , typename T3 |
| 104 | > |
| 105 | struct if_ |
| 106 | { |
| 107 | typedef typename if_c<0 != T1::value, T2, T3>::type type; |
| 108 | }; |
| 109 | |
| 110 | |
| 111 | template <class Pair> |
| 112 | struct select1st |
| 113 | // : public std::unary_function<Pair, typename Pair::first_type> |
| 114 | { |
| 115 | template<class OtherPair> |
| 116 | const typename Pair::first_type& operator()(const OtherPair& x) const |
| 117 | { return x.first; } |
| 118 | |
| 119 | const typename Pair::first_type& operator()(const typename Pair::first_type& x) const |
| 120 | { return x; } |
| 121 | }; |
| 122 | |
| 123 | // identity is an extension: it is not part of the standard. |
| 124 | template <class T> |
| 125 | struct identity |
| 126 | // : public std::unary_function<T,T> |
| 127 | { |
| 128 | typedef T type; |
| 129 | const T& operator()(const T& x) const |
| 130 | { return x; } |
| 131 | }; |
| 132 | |
| 133 | template<std::size_t S> |
| 134 | struct ls_zeros |
| 135 | { |
| 136 | static const std::size_t value = (S & std::size_t(1)) ? 0 : (1u + ls_zeros<(S >> 1u)>::value); |
| 137 | }; |
| 138 | |
| 139 | template<> |
| 140 | struct ls_zeros<0> |
| 141 | { |
| 142 | static const std::size_t value = 0; |
| 143 | }; |
| 144 | |
| 145 | template<> |
| 146 | struct ls_zeros<1> |
| 147 | { |
| 148 | static const std::size_t value = 0; |
| 149 | }; |
| 150 | |
| 151 | template <typename T> struct unvoid { typedef T type; }; |
| 152 | template <> struct unvoid<void> { struct type { }; }; |
| 153 | template <> struct unvoid<const void> { struct type { }; }; |
| 154 | |
| 155 | } //namespace container_detail { |
| 156 | } //namespace container { |
| 157 | } //namespace ndnboost { |
| 158 | |
| 159 | #endif //#ifndef BOOST_CONTAINER_CONTAINER_DETAIL_MPL_HPP |
| 160 | |