- Timestamp:
- Aug 7, 2008, 12:52:39 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/stl_utility.h
r1387 r1399 35 35 /// extensions to STL functionality. 36 36 /// 37 38 #include <boost/iterator/transform_iterator.hpp> 39 #include <boost/mpl/if.hpp> 40 #include <boost/type_traits/is_const.hpp> 41 #include <boost/type_traits/add_const.hpp> 37 42 38 43 #include <algorithm> … … 266 271 }; 267 272 273 /** 274 \brief Functor that return std::pair.first 275 276 \see pair_first_iterator 277 278 \since New in yat 0.5 279 */ 280 template <class Pair> 281 struct PairFirst 282 { 283 /** 284 The type returned is Pair::first_type& with the exception when 285 Pair is const and Pair::first_type is non-const, in which case 286 const Pair::first_type& is return type. 287 */ 288 typedef typename boost::mpl::if_< 289 typename boost::is_const<Pair>::type, 290 typename boost::add_const<typename Pair::first_type>::type&, 291 typename Pair::first_type&>::type result_type; 292 293 /** 294 The argument type is Pair&. 295 */ 296 typedef Pair& argument_type; 297 298 /** 299 \return p.first 300 */ 301 inline result_type operator()(argument_type p) const 302 { return p.first; } 303 304 }; 305 306 307 /** 308 Creates a transform_iterator that transforms an iterator with 309 value type std::pair to an iterator with value type 310 std::pair::first_type. This can be used, for example, to 311 communicate between a std::map and std::vector 312 313 \code 314 std::map<std::string, int> map; 315 ... 316 std::vector<std::string> vec; 317 vec.resize(map.size()); 318 std::copy(pair_first_iterator(map.begin()), pair_first_iterator(map.end()), 319 vec.begin()); 320 \endcode 321 322 \since New in yat 0.5 323 */ 324 template<class Iter> 325 boost::transform_iterator< 326 PairFirst<typename std::iterator_traits<Iter>::value_type>, 327 Iter> pair_first_iterator(Iter i) 328 { 329 typedef PairFirst<typename std::iterator_traits<Iter>::value_type> PF; 330 return boost::transform_iterator<PF, Iter>(i, PF()); 331 } 332 333 334 335 268 336 /// 269 337 /// @brief Function converting a string to lower case
Note: See TracChangeset
for help on using the changeset viewer.