LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
MapKeyIterator.h
Go to the documentation of this file.
1 
9 #ifndef NUTOOLS_RANDOMUTILS_PROVIDERS_MAPKEYITERATOR_H
10 #define NUTOOLS_RANDOMUTILS_PROVIDERS_MAPKEYITERATOR_H 1
11 
12 // C++ standard libraries
13 #include <iterator>
14 #include <tuple>
15 #include <type_traits>
16 
17 
18 namespace rndm {
19  namespace NuRandomServiceHelper {
20 
21 
45  template <typename Iter>
46  class MapKeyIterator: public Iter {
47  public:
48  using map_iterator_t = Iter;
49  using iterator_traits_t = std::iterator_traits<map_iterator_t>;
50 
51  // iterator traits
52  using difference_type = typename iterator_traits_t::difference_type;
53  using value_type
54  = typename std::tuple_element<0, typename iterator_traits_t::value_type>::type;
55  using pointer = typename std::add_pointer<value_type>::type;
56  using reference = typename std::add_lvalue_reference<value_type>::type;
57  using iterator_category = typename iterator_traits_t::iterator_category;
58 
60  MapKeyIterator() = default;
61 
62  // accept quietly all the other constructery C++ provides
63 
66  map_iterator_t(from) {}
67 
70 
72  pointer operator->() { return &get_key(get_value()); }
73 
74  protected:
75  using pair_reference = typename iterator_traits_t::reference;
76 
78 
80  { return std::get<0>(value); }
81 
82  }; // MapKeyIterator<>
83 
84 
85 
103  template <typename Map>
105  public:
106  using map_t = Map;
107 
109 
111  beginKey(map.cbegin()), endKey(map.cend())
112  {}
113 
114  const_iterator begin() { return beginKey; }
115  const_iterator end() { return endKey; }
116  const_iterator cbegin() { return beginKey; }
117  const_iterator cend() { return endKey; }
118 
119  protected:
122 
123  }; // class MapKeyConstIteratorBox<>
124 
125  } // namespace NuRandomServiceHelper
126 } // namespace rndm
127 
128 #endif // NUTOOLS_RANDOMUTILS_PROVIDERS_MAPKEYITERATOR_H
MapKeyIterator(map_iterator_t const &from)
Initialize from a original iterator type.
typename std::add_lvalue_reference< value_type >::type reference
Wraps a map-like object iterator to iterate on its first element.
pointer operator->()
Return a pointer to the key of the original iterator value.
static reference get_key(pair_reference value)
const_iterator beginKey
iterator pointing to the begin key
std::string value(boost::any const &)
Definition: G4Helper.h:37
reference operator*()
Return the key of the original iterator value.
MapKeyIterator()=default
Default constructor is really default.
QuadExpr operator*(double v, const QuadExpr &e)
Definition: QuadExpr.h:39
Provides iterators for std::begin() and std::end()
const_iterator endKey
iterator pointing to the endkey
typename std::tuple_element< 0, typename iterator_traits_t::value_type >::type value_type