annotate DEPENDENCIES/generic/include/boost/range/detail/collection_traits.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Boost string_algo library collection_traits.hpp header file -------------//
Chris@16 2
Chris@16 3 // Copyright Pavol Droba 2002-2003. Use, modification and
Chris@16 4 // distribution is subject to the Boost Software License, Version
Chris@16 5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7
Chris@16 8 // (C) Copyright Thorsten Ottosen 2002-2003. Use, modification and
Chris@16 9 // distribution is subject to the Boost Software License, Version
Chris@16 10 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 11 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 12
Chris@16 13 // (C) Copyright Jeremy Siek 2001. Use, modification and
Chris@16 14 // distribution is subject to the Boost Software License, Version
Chris@16 15 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 16 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 17
Chris@16 18 // Original idea of container traits was proposed by Jeremy Siek and
Chris@16 19 // Thorsten Ottosen. This implementation is lightweighted version
Chris@16 20 // of container_traits adapter for usage with string_algo library
Chris@16 21
Chris@16 22 #ifndef BOOST_RANGE_STRING_COLLECTION_TRAITS_HPP
Chris@16 23 #define BOOST_RANGE_STRING_COLLECTION_TRAITS_HPP
Chris@16 24
Chris@16 25 #include <boost/type_traits/is_array.hpp>
Chris@16 26 #include <boost/type_traits/is_pointer.hpp>
Chris@16 27 #include <boost/mpl/eval_if.hpp>
Chris@16 28
Chris@16 29 // Implementation
Chris@16 30 #include <boost/range/detail/collection_traits_detail.hpp>
Chris@16 31
Chris@16 32 /*! \file
Chris@16 33 Defines collection_traits class and related free-standing functions.
Chris@16 34 This facility is used to unify the access to different types of collections.
Chris@16 35 It allows the algorithms in the library to work with STL collections, c-style
Chris@16 36 array, null-terminated c-strings (and more) using the same interface.
Chris@16 37 */
Chris@16 38
Chris@16 39 namespace boost {
Chris@16 40 namespace algorithm {
Chris@16 41
Chris@16 42 // collection_traits template class -----------------------------------------//
Chris@16 43
Chris@16 44 //! collection_traits class
Chris@16 45 /*!
Chris@16 46 Collection traits provide uniform access to different types of
Chris@16 47 collections. This functionality allows to write generic algorithms
Chris@16 48 which work with several different kinds of collections.
Chris@16 49
Chris@16 50 Currently following collection types are supported:
Chris@16 51 - containers with STL compatible container interface ( see ContainerConcept )
Chris@16 52 ( i.e. \c std::vector<>, \c std::list<>, \c std::string<> ... )
Chris@16 53 - c-style array
Chris@16 54 ( \c char[10], \c int[15] ... )
Chris@16 55 - null-terminated c-strings
Chris@16 56 ( \c char*, \c wchar_T* )
Chris@16 57 - std::pair of iterators
Chris@16 58 ( i.e \c std::pair<vector<int>::iterator,vector<int>::iterator> )
Chris@16 59
Chris@16 60 Collection traits provide an external collection interface operations.
Chris@16 61 All are accessible using free-standing functions.
Chris@16 62
Chris@16 63 The following operations are supported:
Chris@16 64 - \c size()
Chris@16 65 - \c empty()
Chris@16 66 - \c begin()
Chris@16 67 - \c end()
Chris@16 68
Chris@16 69 Container traits have somewhat limited functionality on compilers not
Chris@16 70 supporting partial template specialization and partial template ordering.
Chris@16 71 */
Chris@16 72 template< typename T >
Chris@16 73 struct collection_traits
Chris@16 74 {
Chris@16 75 private:
Chris@101 76 typedef typename ::boost::mpl::eval_if<
Chris@16 77 ::boost::algorithm::detail::is_pair<T>,
Chris@16 78 detail::pair_container_traits_selector<T>,
Chris@101 79 typename ::boost::mpl::eval_if<
Chris@16 80 ::boost::is_array<T>,
Chris@16 81 detail::array_container_traits_selector<T>,
Chris@101 82 typename ::boost::mpl::eval_if<
Chris@16 83 ::boost::is_pointer<T>,
Chris@16 84 detail::pointer_container_traits_selector<T>,
Chris@16 85 detail::default_container_traits_selector<T>
Chris@16 86 >
Chris@16 87 >
Chris@16 88 >::type container_helper_type;
Chris@16 89 public:
Chris@16 90 //! Function type
Chris@16 91 typedef container_helper_type function_type;
Chris@16 92 //! Value type
Chris@101 93 typedef typename
Chris@16 94 container_helper_type::value_type value_type;
Chris@16 95 //! Size type
Chris@101 96 typedef typename
Chris@16 97 container_helper_type::size_type size_type;
Chris@16 98 //! Iterator type
Chris@101 99 typedef typename
Chris@16 100 container_helper_type::iterator iterator;
Chris@16 101 //! Const iterator type
Chris@101 102 typedef typename
Chris@16 103 container_helper_type::const_iterator const_iterator;
Chris@16 104 //! Result iterator type ( iterator of const_iterator, depending on the constness of the container )
Chris@101 105 typedef typename
Chris@16 106 container_helper_type::result_iterator result_iterator;
Chris@16 107 //! Difference type
Chris@101 108 typedef typename
Chris@16 109 container_helper_type::difference_type difference_type;
Chris@16 110
Chris@16 111 }; // 'collection_traits'
Chris@16 112
Chris@16 113 // collection_traits metafunctions -----------------------------------------//
Chris@16 114
Chris@16 115 //! Container value_type trait
Chris@16 116 /*!
Chris@16 117 Extract the type of elements contained in a container
Chris@16 118 */
Chris@16 119 template< typename C >
Chris@16 120 struct value_type_of
Chris@16 121 {
Chris@101 122 typedef typename collection_traits<C>::value_type type;
Chris@16 123 };
Chris@16 124
Chris@16 125 //! Container difference trait
Chris@16 126 /*!
Chris@16 127 Extract the container's difference type
Chris@16 128 */
Chris@16 129 template< typename C >
Chris@16 130 struct difference_type_of
Chris@16 131 {
Chris@101 132 typedef typename collection_traits<C>::difference_type type;
Chris@16 133 };
Chris@16 134
Chris@16 135 //! Container iterator trait
Chris@16 136 /*!
Chris@16 137 Extract the container's iterator type
Chris@16 138 */
Chris@16 139 template< typename C >
Chris@16 140 struct iterator_of
Chris@16 141 {
Chris@101 142 typedef typename collection_traits<C>::iterator type;
Chris@16 143 };
Chris@16 144
Chris@16 145 //! Container const_iterator trait
Chris@16 146 /*!
Chris@16 147 Extract the container's const_iterator type
Chris@16 148 */
Chris@16 149 template< typename C >
Chris@16 150 struct const_iterator_of
Chris@16 151 {
Chris@101 152 typedef typename collection_traits<C>::const_iterator type;
Chris@16 153 };
Chris@16 154
Chris@16 155
Chris@16 156 //! Container result_iterator
Chris@16 157 /*!
Chris@16 158 Extract the container's result_iterator type. This type maps to \c C::iterator
Chris@16 159 for mutable container and \c C::const_iterator for const containers.
Chris@16 160 */
Chris@16 161 template< typename C >
Chris@16 162 struct result_iterator_of
Chris@16 163 {
Chris@101 164 typedef typename collection_traits<C>::result_iterator type;
Chris@16 165 };
Chris@16 166
Chris@16 167 // collection_traits related functions -----------------------------------------//
Chris@16 168
Chris@16 169 //! Free-standing size() function
Chris@16 170 /*!
Chris@16 171 Get the size of the container. Uses collection_traits.
Chris@16 172 */
Chris@16 173 template< typename C >
Chris@101 174 inline typename collection_traits<C>::size_type
Chris@16 175 size( const C& c )
Chris@16 176 {
Chris@16 177 return collection_traits<C>::function_type::size( c );
Chris@16 178 }
Chris@16 179
Chris@16 180 //! Free-standing empty() function
Chris@16 181 /*!
Chris@16 182 Check whether the container is empty. Uses container traits.
Chris@16 183 */
Chris@16 184 template< typename C >
Chris@16 185 inline bool empty( const C& c )
Chris@16 186 {
Chris@16 187 return collection_traits<C>::function_type::empty( c );
Chris@16 188 }
Chris@16 189
Chris@16 190 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
Chris@16 191
Chris@16 192 //! Free-standing begin() function
Chris@16 193 /*!
Chris@16 194 Get the begin iterator of the container. Uses collection_traits.
Chris@16 195 */
Chris@16 196 template< typename C >
Chris@101 197 inline typename collection_traits<C>::iterator
Chris@16 198 begin( C& c )
Chris@16 199 {
Chris@16 200 return collection_traits<C>::function_type::begin( c );
Chris@16 201 }
Chris@16 202
Chris@16 203 //! Free-standing begin() function
Chris@16 204 /*!
Chris@16 205 \overload
Chris@16 206 */
Chris@16 207 template< typename C >
Chris@101 208 inline typename collection_traits<C>::const_iterator
Chris@16 209 begin( const C& c )
Chris@16 210 {
Chris@16 211 return collection_traits<C>::function_type::begin( c );
Chris@16 212 }
Chris@16 213
Chris@16 214 //! Free-standing end() function
Chris@16 215 /*!
Chris@16 216 Get the begin iterator of the container. Uses collection_traits.
Chris@16 217 */
Chris@16 218 template< typename C >
Chris@101 219 inline typename collection_traits<C>::iterator
Chris@16 220 end( C& c )
Chris@16 221 {
Chris@16 222 return collection_traits<C>::function_type::end( c );
Chris@16 223 }
Chris@16 224
Chris@16 225 //! Free-standing end() function
Chris@16 226 /*!
Chris@16 227 \overload
Chris@16 228 */
Chris@16 229 template< typename C >
Chris@101 230 inline typename collection_traits<C>::const_iterator
Chris@16 231 end( const C& c )
Chris@16 232 {
Chris@16 233 return collection_traits<C>::function_type::end( c );
Chris@16 234 }
Chris@16 235
Chris@16 236 #else // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
Chris@16 237
Chris@16 238 //! Free-standing begin() function
Chris@16 239 /*!
Chris@16 240 \overload
Chris@16 241 */
Chris@16 242 template< typename C >
Chris@101 243 inline typename collection_traits<C>::result_iterator
Chris@16 244 begin( C& c )
Chris@16 245 {
Chris@16 246 return collection_traits<C>::function_type::begin( c );
Chris@16 247 }
Chris@16 248
Chris@16 249 //! Free-standing end() function
Chris@16 250 /*!
Chris@16 251 \overload
Chris@16 252 */
Chris@16 253 template< typename C >
Chris@101 254 inline typename collection_traits<C>::result_iterator
Chris@16 255 end( C& c )
Chris@16 256 {
Chris@16 257 return collection_traits<C>::function_type::end( c );
Chris@16 258 }
Chris@16 259
Chris@16 260 #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
Chris@16 261
Chris@16 262 } // namespace algorithm
Chris@16 263 } // namespace boost
Chris@16 264
Chris@16 265 #endif // BOOST_STRING_COLLECTION_TRAITS_HPP