LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
rndm::NuRandomServiceHelper::MapKeyIterator< Iter > Class Template Reference

Wraps a map-like object iterator to iterate on its first element. More...

#include "MapKeyIterator.h"

Inheritance diagram for rndm::NuRandomServiceHelper::MapKeyIterator< Iter >:

Public Types

using map_iterator_t = Iter
 
using iterator_traits_t = std::iterator_traits< map_iterator_t >
 
using difference_type = typename iterator_traits_t::difference_type
 
using value_type = typename std::tuple_element< 0, typename iterator_traits_t::value_type >::type
 
using pointer = typename std::add_pointer< value_type >::type
 
using reference = typename std::add_lvalue_reference< value_type >::type
 
using iterator_category = typename iterator_traits_t::iterator_category
 

Public Member Functions

 MapKeyIterator ()=default
 Default constructor is really default. More...
 
 MapKeyIterator (map_iterator_t const &from)
 Initialize from a original iterator type. More...
 
reference operator* ()
 Return the key of the original iterator value. More...
 
pointer operator-> ()
 Return a pointer to the key of the original iterator value. More...
 

Protected Types

using pair_reference = typename iterator_traits_t::reference
 

Protected Member Functions

pair_reference get_value () const
 

Static Protected Member Functions

static reference get_key (pair_reference value)
 

Detailed Description

template<typename Iter>
class rndm::NuRandomServiceHelper::MapKeyIterator< Iter >

Wraps a map-like object iterator to iterate on its first element.


Template Parameters
Iterthe iterator type

This object can wrap a map-like iterator type to iterate through its key in a for loop.

The Iter::value_type must support a std::get<0>() call, that is what's used to extract the key.

Example of usage:

std::map<int, double> my_map;
// ... fill the map ...
// print all the kets
for (MapKeyIterator<map_id_t::const_iterator> it = map_id.cbegin();
  it != map_id.cend(); ++it)
  std::cout << "Key: " << *it << std::endl;

Although the non-constant iterators are supported, this is of little use since typically the key is declared constant anyway (in the example above, the key is const int).

Definition at line 46 of file MapKeyIterator.h.

Member Typedef Documentation

template<typename Iter>
using rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::difference_type = typename iterator_traits_t::difference_type

Definition at line 52 of file MapKeyIterator.h.

template<typename Iter>
using rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::iterator_category = typename iterator_traits_t::iterator_category

Definition at line 57 of file MapKeyIterator.h.

template<typename Iter>
using rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::iterator_traits_t = std::iterator_traits<map_iterator_t>

Definition at line 49 of file MapKeyIterator.h.

template<typename Iter>
using rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::map_iterator_t = Iter

Definition at line 48 of file MapKeyIterator.h.

template<typename Iter>
using rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::pair_reference = typename iterator_traits_t::reference
protected

Definition at line 75 of file MapKeyIterator.h.

template<typename Iter>
using rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::pointer = typename std::add_pointer<value_type>::type

Definition at line 55 of file MapKeyIterator.h.

template<typename Iter>
using rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::reference = typename std::add_lvalue_reference<value_type>::type

Definition at line 56 of file MapKeyIterator.h.

template<typename Iter>
using rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::value_type = typename std::tuple_element<0, typename iterator_traits_t::value_type>::type

Definition at line 54 of file MapKeyIterator.h.

Constructor & Destructor Documentation

template<typename Iter>
rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::MapKeyIterator ( )
default

Default constructor is really default.

template<typename Iter>
rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::MapKeyIterator ( map_iterator_t const &  from)
inline

Initialize from a original iterator type.

Definition at line 65 of file MapKeyIterator.h.

Member Function Documentation

template<typename Iter>
static reference rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::get_key ( pair_reference  value)
inlinestaticprotected
template<typename Iter>
pair_reference rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::get_value ( ) const
inlineprotected
template<typename Iter>
reference rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::operator* ( )
inline

Return the key of the original iterator value.

Definition at line 69 of file MapKeyIterator.h.

69 { return get_key(get_value()); }
static reference get_key(pair_reference value)
template<typename Iter>
pointer rndm::NuRandomServiceHelper::MapKeyIterator< Iter >::operator-> ( )
inline

Return a pointer to the key of the original iterator value.

Definition at line 72 of file MapKeyIterator.h.

72 { return &get_key(get_value()); }
static reference get_key(pair_reference value)

The documentation for this class was generated from the following file: