template<typename Iterator, typename KeyGetter>
class acts_examples::GroupBy< Iterator, KeyGetter >
Proxy for iterating over groups of elements within a container.
- Note
- Each group will contain at least one element.
Consecutive elements with the same key (as defined by the KeyGetter) are placed in one group. The proxy should always be used as part of a range-based for loop. In combination with structured bindings to reduce the boilerplate, the group iteration can be written as
for (auto&& [key, elements] : GroupBy<...>(...)) {
// do something with just the key
...
// iterate over the group elements
for (const auto& element : elements) {
...
}
}
Definition at line 39 of file GroupBy.h.
template<typename Iterator , typename KeyGetter >
Find the end of the group that starts at the given position.
This uses a linear search from the start position and thus has linear complexity in the group size. It does not assume any ordering of the underlying container and is a cache-friendly access pattern.
Definition at line 121 of file GroupBy.h.
121 {
122
123 if (start == m_end_) {
124 return start;
125 }
126
127 return std::find_if_not(std::next(start), m_end_,
128 [this, start](const auto& x_) {
129 return m_key_getter_(x_) == m_key_getter_(*start);
130 });
131 }
Referenced by acts_examples::GroupBy< Iterator, KeyGetter >::GroupIterator::operator++().