Volume Cartographer 2.27.0
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
volcart::EnumerateIterable< Iterable > Class Template Reference

#include <vc/core/util/Iteration.hpp>

Classes

class  EnumerateIterator
 

Public Types

using iterator = EnumerateIterator< IteratorType >
 
using const_iterator = EnumerateIterator< const IteratorType >
 

Public Member Functions

iterator begin () const
 
iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 

Private Types

using IteratorType = decltype(std::begin(std::declval< Iterable >()))
 

Private Member Functions

 EnumerateIterable (Iterable &&container)
 
template<typename... Args>
 EnumerateIterable (Args &&... args)
 

Private Attributes

Iterable container_
 

Friends

auto enumerate (Iterable &&it)
 Wrap an Iterable into a new one whose iterators return an [index, value] pair. More...
 
template<typename... Args>
EnumerateIterable< std::vector< std::common_type_t< Args... > > > enumerate (Args &&... args)
 Wrap an Iterable into a new one whose iterators return an [index, value] pair. More...
 

Detailed Description

template<class Iterable>
class volcart::EnumerateIterable< Iterable >

Iterable wrapper for enumerating elements of a container by index and value

Use volcart::enumerate, which provides a convenient method for constructing an EnumerateIterable.

Definition at line 401 of file Iteration.hpp.

Member Typedef Documentation

◆ const_iterator

template<class Iterable >
using volcart::EnumerateIterable< Iterable >::const_iterator = EnumerateIterator<const IteratorType>

Definition at line 472 of file Iteration.hpp.

◆ iterator

template<class Iterable >
using volcart::EnumerateIterable< Iterable >::iterator = EnumerateIterator<IteratorType>

Definition at line 471 of file Iteration.hpp.

◆ IteratorType

template<class Iterable >
using volcart::EnumerateIterable< Iterable >::IteratorType = decltype(std::begin(std::declval<Iterable>()))
private

Definition at line 452 of file Iteration.hpp.

Constructor & Destructor Documentation

◆ EnumerateIterable() [1/2]

template<class Iterable >
volcart::EnumerateIterable< Iterable >::EnumerateIterable ( Iterable &&  container)
inlineprivate

Definition at line 454 of file Iteration.hpp.

◆ EnumerateIterable() [2/2]

template<class Iterable >
template<typename... Args>
volcart::EnumerateIterable< Iterable >::EnumerateIterable ( Args &&...  args)
inlineprivate

Definition at line 460 of file Iteration.hpp.

Member Function Documentation

◆ begin()

template<class Iterable >
iterator volcart::EnumerateIterable< Iterable >::begin ( ) const
inline

Get a new EnumerateIterable::iterator

Definition at line 475 of file Iteration.hpp.

◆ cbegin()

template<class Iterable >
const_iterator volcart::EnumerateIterable< Iterable >::cbegin ( ) const
inline

Get a new ProgressIterable::const_iterator

Definition at line 481 of file Iteration.hpp.

◆ cend()

template<class Iterable >
const_iterator volcart::EnumerateIterable< Iterable >::cend ( ) const
inline

Get the end-valued ProgressIterable::const_iterator

Definition at line 487 of file Iteration.hpp.

◆ end()

template<class Iterable >
iterator volcart::EnumerateIterable< Iterable >::end ( ) const
inline

Get the end-valued EnumerateIterable::iterator

Definition at line 478 of file Iteration.hpp.

Friends And Related Function Documentation

◆ enumerate [1/2]

template<class Iterable >
template<typename... Args>
EnumerateIterable< std::vector< std::common_type_t< Args... > > > enumerate ( Args &&...  args)
friend

Wrap an Iterable into a new one whose iterators return an [index, value] pair.

This is an overload for lists of arguments:

for(auto val : enumerate(0, 1, 2, 3)) {
std::cout "values[" << val.first << "] == " << val.second << std::endl;
}
friend auto enumerate(Iterable &&it)
Wrap an Iterable into a new one whose iterators return an [index, value] pair.
Definition: Iteration.hpp:527

Definition at line 549 of file Iteration.hpp.

◆ enumerate [2/2]

template<class Iterable >
auto enumerate ( Iterable &&  it)
friend

Wrap an Iterable into a new one whose iterators return an [index, value] pair.

This roughly approximates the functionality of Python's enumerate function.

// Use as std::pair
std::vector<int> values{1, 2, 3, 4};
for(auto val : enumerate(values)) {
std::cout "values[" << val.first << "] == " << val.second << std::endl;
}
// Use structured bindings (C++17 and up)
// Update the underlying data
for(auto [idx, val] : enumerate(values) {
std::cout << val == values[idx] std::endl;
val++;
std::cout << val == values[idx] std::endl;
}
Template Parameters
IterableIterable container class. Iterable::iterator must meet LegacyIterator requirements
Parameters
itObject of type Iterable

Definition at line 527 of file Iteration.hpp.

Member Data Documentation

◆ container_

template<class Iterable >
Iterable volcart::EnumerateIterable< Iterable >::container_
private

Definition at line 493 of file Iteration.hpp.


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