annotate DEPENDENCIES/generic/include/boost/phoenix/stl/container/detail/container.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*=============================================================================
Chris@16 2 Copyright (c) 2004 Angus Leeming
Chris@16 3 Copyright (c) 2004 Joel de Guzman
Chris@16 4
Chris@16 5 Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7 ==============================================================================*/
Chris@16 8 #ifndef BOOST_PHOENIX_CONTAINER_DETAIL_CONTAINER_HPP
Chris@16 9 #define BOOST_PHOENIX_CONTAINER_DETAIL_CONTAINER_HPP
Chris@16 10
Chris@16 11 #include <utility>
Chris@16 12 #include <boost/mpl/eval_if.hpp>
Chris@16 13 #include <boost/type_traits/is_same.hpp>
Chris@16 14 #include <boost/type_traits/is_const.hpp>
Chris@16 15
Chris@16 16 namespace boost { namespace phoenix { namespace stl
Chris@16 17 {
Chris@16 18 ///////////////////////////////////////////////////////////////////////////////
Chris@16 19 //
Chris@16 20 // Metafunctions "value_type_of", "key_type_of" etc.
Chris@16 21 //
Chris@16 22 // These metafunctions define a typedef "type" that returns the nested
Chris@16 23 // type if it exists. If not then the typedef returns void.
Chris@16 24 //
Chris@16 25 // For example, "value_type_of<std::vector<int> >::type" is "int" whilst
Chris@16 26 // "value_type_of<double>::type" is "void".
Chris@16 27 //
Chris@16 28 // I use a macro to define structs "value_type_of" etc simply to cut
Chris@16 29 // down on the amount of code. The macro is #undef-ed immediately after
Chris@16 30 // its final use.
Chris@16 31 //
Chris@16 32 /////////////////////////////////////////////////////////////////c//////////////
Chris@16 33 #define MEMBER_TYPE_OF(MEMBER_TYPE) \
Chris@16 34 template <typename C> \
Chris@16 35 struct BOOST_PP_CAT(MEMBER_TYPE, _of) \
Chris@16 36 { \
Chris@16 37 typedef typename C::MEMBER_TYPE type; \
Chris@16 38 }
Chris@16 39
Chris@16 40 MEMBER_TYPE_OF(allocator_type);
Chris@16 41 MEMBER_TYPE_OF(const_iterator);
Chris@16 42 MEMBER_TYPE_OF(const_reference);
Chris@16 43 MEMBER_TYPE_OF(const_reverse_iterator);
Chris@16 44 MEMBER_TYPE_OF(container_type);
Chris@16 45 MEMBER_TYPE_OF(data_type);
Chris@16 46 MEMBER_TYPE_OF(iterator);
Chris@16 47 MEMBER_TYPE_OF(key_compare);
Chris@16 48 MEMBER_TYPE_OF(key_type);
Chris@16 49 MEMBER_TYPE_OF(reference);
Chris@16 50 MEMBER_TYPE_OF(reverse_iterator);
Chris@16 51 MEMBER_TYPE_OF(size_type);
Chris@16 52 MEMBER_TYPE_OF(value_compare);
Chris@16 53 MEMBER_TYPE_OF(value_type);
Chris@16 54
Chris@16 55 #undef MEMBER_TYPE_OF
Chris@16 56
Chris@16 57 ///////////////////////////////////////////////////////////////////////////////
Chris@16 58 //
Chris@16 59 // Const-Qualified types.
Chris@16 60 //
Chris@16 61 // Many of the stl member functions have const and non-const
Chris@16 62 // overloaded versions that return distinct types. For example:
Chris@16 63 //
Chris@16 64 // iterator begin();
Chris@16 65 // const_iterator begin() const;
Chris@16 66 //
Chris@16 67 // The three class templates defined below,
Chris@16 68 // const_qualified_reference_of, const_qualified_iterator_of
Chris@16 69 // and const_qualified_reverse_iterator_of provide a means to extract
Chris@16 70 // this return type automatically.
Chris@16 71 //
Chris@16 72 ///////////////////////////////////////////////////////////////////////////////
Chris@16 73 template <typename C>
Chris@16 74 struct const_qualified_reference_of
Chris@16 75 {
Chris@16 76 typedef typename
Chris@16 77 boost::mpl::eval_if_c<
Chris@16 78 boost::is_const<C>::value
Chris@16 79 , const_reference_of<C>
Chris@16 80 , reference_of<C>
Chris@16 81 >::type
Chris@16 82 type;
Chris@16 83 };
Chris@16 84
Chris@16 85 template <typename C>
Chris@16 86 struct const_qualified_iterator_of
Chris@16 87 {
Chris@16 88 typedef typename
Chris@16 89 boost::mpl::eval_if_c<
Chris@16 90 boost::is_const<C>::value
Chris@16 91 , const_iterator_of<C>
Chris@16 92 , iterator_of<C>
Chris@16 93 >::type
Chris@16 94 type;
Chris@16 95 };
Chris@16 96
Chris@16 97 template <typename C>
Chris@16 98 struct const_qualified_reverse_iterator_of
Chris@16 99 {
Chris@16 100 typedef typename
Chris@16 101 boost::mpl::eval_if_c<
Chris@16 102 boost::is_const<C>::value
Chris@16 103 , const_reverse_iterator_of<C>
Chris@16 104 , reverse_iterator_of<C>
Chris@16 105 >::type
Chris@16 106 type;
Chris@16 107 };
Chris@16 108
Chris@16 109 ///////////////////////////////////////////////////////////////////////////////
Chris@16 110 //
Chris@16 111 // has_mapped_type<C>
Chris@16 112 //
Chris@16 113 // Given a container C, determine if it is a map or multimap
Chris@16 114 // by checking if it has a member type named "mapped_type".
Chris@16 115 //
Chris@16 116 ///////////////////////////////////////////////////////////////////////////////
Chris@16 117 namespace stl_impl
Chris@16 118 {
Chris@16 119 struct one { char a[1]; };
Chris@16 120 struct two { char a[2]; };
Chris@16 121
Chris@16 122 template <typename C>
Chris@16 123 one has_mapped_type(typename C::mapped_type(*)());
Chris@16 124
Chris@16 125 template <typename C>
Chris@16 126 two has_mapped_type(...);
Chris@16 127
Chris@16 128 template<typename T>
Chris@16 129 struct enable_if_is_void
Chris@16 130 {};
Chris@16 131
Chris@16 132 template<>
Chris@16 133 struct enable_if_is_void<void>
Chris@16 134 {
Chris@16 135 typedef void type;
Chris@16 136 };
Chris@16 137
Chris@16 138 template<typename T>
Chris@16 139 struct disable_if_is_void
Chris@16 140 {
Chris@16 141 typedef T type;
Chris@16 142 };
Chris@16 143
Chris@16 144 template<>
Chris@16 145 struct disable_if_is_void<void>
Chris@16 146 {};
Chris@16 147 }
Chris@16 148
Chris@16 149 template <typename C>
Chris@16 150 struct has_mapped_type
Chris@16 151 : boost::mpl::bool_<
Chris@16 152 sizeof(stl_impl::has_mapped_type<C>(0)) == sizeof(stl_impl::one)
Chris@16 153 >
Chris@16 154 {};
Chris@16 155
Chris@16 156 ///////////////////////////////////////////////////////////////////////////////
Chris@16 157 //
Chris@16 158 // map_insert_returns_pair<C>
Chris@16 159 //
Chris@16 160 // Distinguish a map from a multimap by checking the return type
Chris@16 161 // of its "insert" member function. A map returns a pair while
Chris@16 162 // a multimap returns an iterator.
Chris@16 163 //
Chris@16 164 ///////////////////////////////////////////////////////////////////////////////
Chris@16 165 namespace stl_impl
Chris@16 166 {
Chris@16 167 // Cool implementation of map_insert_returns_pair by Daniel Wallin.
Chris@16 168 // Thanks Daniel!!! I owe you a Pizza!
Chris@16 169
Chris@16 170 template<class A, class B>
Chris@16 171 one map_insert_returns_pair_check(std::pair<A,B> const&);
Chris@16 172
Chris@16 173 template <typename T>
Chris@16 174 two map_insert_returns_pair_check(T const&);
Chris@16 175
Chris@16 176 template <typename C>
Chris@16 177 struct map_insert_returns_pair
Chris@16 178 {
Chris@16 179 static typename C::value_type const& get;
Chris@16 180 BOOST_STATIC_CONSTANT(int,
Chris@16 181 value = sizeof(
Chris@16 182 map_insert_returns_pair_check(((C*)0)->insert(get))));
Chris@16 183 typedef boost::mpl::bool_<value == sizeof(one)> type;
Chris@16 184 };
Chris@16 185 }
Chris@16 186
Chris@16 187 template <typename C>
Chris@16 188 struct map_insert_returns_pair
Chris@16 189 : stl_impl::map_insert_returns_pair<C>::type {};
Chris@16 190
Chris@16 191 }}} // namespace boost::phoenix::stl
Chris@16 192
Chris@16 193 #endif // BOOST_PHOENIX_STL_CONTAINER_TRAITS_HPP