CBMC
ranget< iteratort > Struct Template Referencefinal

A range is a pair of a begin and an end iterators. More...

#include <range.h>

Public Types

using value_type = typename iteratort::value_type
 

Public Member Functions

 ranget (iteratort begin, iteratort end)
 
ranget< filter_iteratort< iteratort > > filter (std::function< bool(const value_type &)> f)
 
template<typename functiont >
auto map (functiont &&f)
 The type of elements contained in the resulting range is deduced from the return type of f. More...
 
template<typename other_iteratort >
ranget< concat_iteratort< iteratort, other_iteratort > > concat (ranget< other_iteratort > other)
 
template<bool same_size = true, typename other_iteratort >
ranget< zip_iteratort< iteratort, other_iteratort, same_size > > zip (ranget< other_iteratort > other)
 Combine two ranges to make a range over pairs. More...
 
template<bool same_size = true, typename containert >
auto zip (containert &container) -> ranget< zip_iteratort< iteratort, decltype(container.begin()), same_size >>
 
bool empty () const
 
ranget< iteratort > drop (std::size_t count) &&
 Return an new range containing the same elements except for the first count elements. More...
 
ranget< iteratort > drop (std::size_t count) const &
 Return an new range containing the same elements except for the first count elements. More...
 
iteratort begin () const
 
const iteratort & end () const
 
template<typename containert >
containert collect () const
 Constructs a collection containing the values, which this range iterates over. More...
 
template<typename containert >
 operator containert () const
 

Private Attributes

iteratort begin_value
 
iteratort end_value
 

Detailed Description

template<typename iteratort>
struct ranget< iteratort >

A range is a pair of a begin and an end iterators.

The class provides useful methods such as map, filter and concat which only manipulate iterators and thus don't have to create instances of heavy data structures and avoid copies. For instance, to iterate over two vectors, instead of writing

std::vector new_vector;
std::copy(v1.begin(), v1.end(), std::back_inserter(new_vector));
std::copy(v2.begin(), v2.end(), std::back_inserter(new_vector));
for(const auto &a : new_vector) {...}

It is possible to write:

auto range = make_range(v1).concat(make_range(v2));
for(const auto &a : range) {...}

Which is clearer and has the advantage of avoiding the creation of the intermediary vector and the potentially expensive copies.

Definition at line 395 of file range.h.

Member Typedef Documentation

◆ value_type

template<typename iteratort >
using ranget< iteratort >::value_type = typename iteratort::value_type

Definition at line 398 of file range.h.

Constructor & Destructor Documentation

◆ ranget()

template<typename iteratort >
ranget< iteratort >::ranget ( iteratort  begin,
iteratort  end 
)
inline

Definition at line 400 of file range.h.

Member Function Documentation

◆ begin()

template<typename iteratort >
iteratort ranget< iteratort >::begin ( ) const
inline

Definition at line 492 of file range.h.

◆ collect()

template<typename iteratort >
template<typename containert >
containert ranget< iteratort >::collect ( ) const
inline

Constructs a collection containing the values, which this range iterates over.

Definition at line 505 of file range.h.

◆ concat()

template<typename iteratort >
template<typename other_iteratort >
ranget<concat_iteratort<iteratort, other_iteratort> > ranget< iteratort >::concat ( ranget< other_iteratort >  other)
inline

Definition at line 436 of file range.h.

◆ drop() [1/2]

template<typename iteratort >
ranget<iteratort> ranget< iteratort >::drop ( std::size_t  count) &&
inline

Return an new range containing the same elements except for the first count elements.

If the range has fewer elements, returns an empty range.

Definition at line 477 of file range.h.

◆ drop() [2/2]

template<typename iteratort >
ranget<iteratort> ranget< iteratort >::drop ( std::size_t  count) const &
inline

Return an new range containing the same elements except for the first count elements.

If the range has fewer elements, returns an empty range.

Definition at line 487 of file range.h.

◆ empty()

template<typename iteratort >
bool ranget< iteratort >::empty ( ) const
inline

Definition at line 469 of file range.h.

◆ end()

template<typename iteratort >
const iteratort& ranget< iteratort >::end ( ) const
inline

Definition at line 497 of file range.h.

◆ filter()

template<typename iteratort >
ranget<filter_iteratort<iteratort> > ranget< iteratort >::filter ( std::function< bool(const value_type &)>  f)
inline

Definition at line 406 of file range.h.

◆ map()

template<typename iteratort >
template<typename functiont >
auto ranget< iteratort >::map ( functiont &&  f)
inline

The type of elements contained in the resulting range is deduced from the return type of f.

Please note that the parameter to f must be a const reference. This is a limitation of the current implementation. This means that you can't move a value through f. f may take a move-only typed parameter by const reference. 'f' may also construct and return a move-only typed value.

Definition at line 421 of file range.h.

◆ operator containert()

template<typename iteratort >
template<typename containert >
ranget< iteratort >::operator containert ( ) const
inline

Definition at line 511 of file range.h.

◆ zip() [1/2]

template<typename iteratort >
template<bool same_size = true, typename containert >
auto ranget< iteratort >::zip ( containert &  container) -> ranget<zip_iteratort<iteratort, decltype(container.begin()), same_size>>
inline

Definition at line 462 of file range.h.

◆ zip() [2/2]

template<typename iteratort >
template<bool same_size = true, typename other_iteratort >
ranget<zip_iteratort<iteratort, other_iteratort, same_size> > ranget< iteratort >::zip ( ranget< other_iteratort >  other)
inline

Combine two ranges to make a range over pairs.

Template Parameters
same_sizeif true, cause an invariant violation in case the end is not reached simultaneously for both ranges

Definition at line 451 of file range.h.

Member Data Documentation

◆ begin_value

template<typename iteratort >
iteratort ranget< iteratort >::begin_value
private

Definition at line 517 of file range.h.

◆ end_value

template<typename iteratort >
iteratort ranget< iteratort >::end_value
private

Definition at line 518 of file range.h.


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