Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_CORE_MAP_VALUE_ITERATOR_H |
| 8 | #define NFD_CORE_MAP_VALUE_ITERATOR_H |
| 9 | |
| 10 | #include "common.hpp" |
| 11 | #include <boost/iterator/transform_iterator.hpp> |
| 12 | |
| 13 | namespace nfd { |
| 14 | |
| 15 | /** \class MapValueIterator |
| 16 | * \brief ForwardIterator to iterator over map values |
| 17 | */ |
| 18 | template<typename Map> |
| 19 | class MapValueIterator |
| 20 | : public boost::transform_iterator<function<const typename Map::mapped_type&(const typename Map::value_type&)>, |
| 21 | typename Map::const_iterator> |
| 22 | { |
| 23 | public: |
| 24 | explicit |
| 25 | MapValueIterator(typename Map::const_iterator it) |
| 26 | : boost::transform_iterator<function<const typename Map::mapped_type&(const typename Map::value_type&)>, |
| 27 | typename Map::const_iterator>(it, &takeSecond) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | private: |
| 32 | static const typename Map::mapped_type& |
| 33 | takeSecond(const typename Map::value_type& pair) |
| 34 | { |
| 35 | return pair.second; |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | } // namespace nfd |
| 40 | |
| 41 | #endif // NFD_CORE_MAP_VALUE_ITERATOR_H |