cprover
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_typet = typename iteratort::value_type
 

Public Member Functions

 ranget (iteratort begin, iteratort end)
 
ranget< filter_iteratort< iteratort > > filter (std::function< bool(const value_typet &)> f)
 
template<typename functiont >
auto map (functiont &&f) -> ranget< map_iteratort< iteratort, typename std::result_of< functiont(value_typet)>::type >>
 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)
 
bool empty () const
 
iteratort begin ()
 
const iteratort & end () 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 311 of file range.h.

Member Typedef Documentation

◆ value_typet

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

Definition at line 314 of file range.h.

Constructor & Destructor Documentation

◆ ranget()

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

Definition at line 316 of file range.h.

Member Function Documentation

◆ begin()

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

Definition at line 368 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 353 of file range.h.

◆ empty()

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

Definition at line 363 of file range.h.

◆ end()

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

Definition at line 373 of file range.h.

◆ filter()

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

Definition at line 321 of file range.h.

◆ map()

template<typename iteratort >
template<typename functiont >
auto ranget< iteratort >::map ( functiont &&  f) -> ranget<map_iteratort< iteratort, typename std::result_of<functiont(value_typet)>::type>>
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 336 of file range.h.

Member Data Documentation

◆ begin_value

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

Definition at line 379 of file range.h.

◆ end_value

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

Definition at line 380 of file range.h.


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