Predefined ranges

Tuple

template <class... Types>
class range::tuple

Heterogeneous fixed-length container. That is, the types contained can all be different, and the list of types is given explicitly as template parameters.

The container can be constructed in three ways. One is default construction. The next is construction from a value for each contained type. The third is construction from another range. If the length of this range is known at compile time to be of the same length and all elements can be implicitly converted, this constructor is implicit. If the length of this range is not know at compile time and/or not all elements can be implicitly converted (though the types must be constructible), then the constructor is explicit.

The implementation aims to instantiate as few template classes as possible.

Unlike for std::tuple, there is no get function; its functionality is provided by range::at and range::at_c.

Tuples can be compared for equality and order. They are equal if the number of elements is equal and the elements compare equal in parallel. The ordering operators perform lexicographical comparison. Views on tuples do not define comparison operators.

The layout of the elements in memory is undefined. Connected with this is the layout

Public Functions

template <class Types2 = meta::vector <Types ...>, class Enable = typename boost::enable_if < utility::are_default_constructible <Types2>>::type>
tuple()

Default-construct all elements. This is provided only if all elements are default-constructible.

template <class... Arguments, class Enable = typename boost::enable_if <utility::are_constructible < stored_types, meta::vector <Arguments ...>> >::type>
tuple(Arguments &&... arguments)

Construct element-wise. Each type must be constructible from the corresponding argument passed in.

The order in which the elements are constructed is not defined.

template <class Range, class Enable = typename boost::enable_if <boost::mpl::and_< not_this_tuple <Range>, is_range <Range>, range_is_convertible <Range>>>::type>
tuple(Range && range, dummy_type = dummy_type())

Construct from another range. If the range is known to be the same length, and the types are pairwise convertible, then this implicit constructor is provided.

The order in which the range is traversed and in which the elements are constructed is not defined.

template <class Range, class Enable = typename boost::enable_if <boost::mpl::and_< not_this_tuple <Range>, is_range <Range>, range_is_constructible_but_not_convertible <Range> >>::type>
tuple(Range && range)

Construct from another range. If the range is not known to be the same length, or the types are pairwise constructible but not convertible, then this explicit constructor is provided.

The order in which the range is traversed and in which the elements are constructed is not defined.

Exceptions
  • size_mismatch -

    Iff the size of the range passed in is not the size of this.

template <class Range, class Enable = typename boost::enable_if < boost::mpl::and_<not_this_tuple <Range>, is_range <Range>, range_is_assignable <Range> >>::type>
tuple & operator=(Range && range)

Assign from another range.

If traversal of the range or assignment of any element throws an exception, then it is not defined which elements will have their new values and which ones do not.

Exceptions
  • size_mismatch -

    Iff the size of the range passed in is not the size of this.

void swap(tuple & that)

Call swap (found with argument-dependent lookup or using std::swap) for each pair of elements.

template <class... Types>
tuple< Types...> make_tuple(Types const &... arguments)

Make a tuple from the arguments passed in.

The arguments are stripped of qualifications.

This is equivalent to std::make_tuple except that it returns a range::tuple.

template <class Range>
auto make_tuple_from(Range && range)

Make a tuple from the range passed in, stripping the types of qualifications.

The range is traversed in direction::front. The range must be known to end after a fixed number of elements. This could be a heterogeneous container, like std::tuple. It could also be an adapted heterogeneous container.

For a variable-length range, the resulting tuple has the longest number of elements possible. If range is a standard homogeneous container, this is obviously impossible, and a compile error about recursive template instantiations will result.

Exceptions
  • size_mismatch -

    If the range turns out at run time to finish sooner than it should. In this case, the tuple type will have more elements than the range turns out to have, so constructing the tuple type elicits the exception.

Parameters
  • range -

    The range to construct the range from.

template <class... Types>
tuple< Types &...> tie(Types &... arguments)

Make a tuple of references to each of the arguments.

This is equivalent to std::tie except that it returns a range::tuple.

template <class Range>
auto tie_from(Range && range)

Make a tuple of references to the elements of the range passed in.

The range is traversed in direction::front. The range must be known to end after a fixed number of elements. This could be a heterogeneous container, like std::tuple. It could also be an adapted heterogeneous container.

For a variable-length range, the resulting tuple has the longest number of elements possible. If range is a standard homogeneous container, this is obviously impossible, and a compile error about recursive template instantiations will result.

Exceptions
  • size_mismatch -

    If the range turns out at run time to finish sooner than it should. In this case, the tuple type will have more elements than the range turns out to have, so constructing the tuple type elicits the exception.

Parameters
  • range -

    The range to construct the range from.

template <class... Types>
tuple< Types &&...> forward_as_tuple(Types &&... arguments)

Make a tuple of rvalue references to each of the arguments.

This is equivalent to std::forward_as_tuple except that it returns a range::tuple.

template <class Range>
auto copy_tuple_from(Range && range)

Make a tuple that is a copy of the range passed in, down to the exact element types that first() returns.

The types will often be references. Notably, copy_tuple_from applied to a tuple will usually result in a tuple with a different type.

The range is traversed in direction::front. The range must be known to end after a fixed number of elements. This could be a heterogeneous container, like std::tuple. It could also be an adapted heterogeneous container.

For a variable-length range, the resulting tuple has the longest number of elements possible. If range is a standard homogeneous container, this is obviously impossible, and a compile error about recursive template instantiations will result.

Exceptions
  • size_mismatch -

    If the range turns out at run time to finish sooner than it should. In this case, the tuple type will have more elements than the range turns out to have, so constructing the tuple type elicits the exception.

Parameters
  • range -

    The range to construct the range from.

auto const ignore

Object that anything can be assigned to syntactically, but it has no effect. This is useful in conjunction with tie. std::ignore could be used just as well, but this can be awkward in practice. Because of argument-dependent lookup, is ambiguous between range::tie and std::tie.

using range::tie; tie (std::ignore);

On the other hand, is fine.

using range::tie; tie (range::ignore);

Counting

template <class Begin>
infinite_count_range< Begin > count_from(Begin const & begin)

Return an infinite range that contains an arithmetic progression of integers.

It starts with begin, the next element is begin + 1, etc. If begin is a run-time value, then the range is homogeneous, i.e., the other elements have the same type. If begin is a constant, the other elements are also constants of the same type. However, if begin is a constant and drop (increment, r) is called with non-constant increment, then the resulting range will have a run-time value of the same type as the value type of the original constant.

template <class Begin, class End>
auto count(Begin const & begin, End const & end)

Return a range that contains an arithmetic progression of integers.

It starts with begin, and finishes one before end. begin and end can be run-time values or compile-time values. If they are run-time values, like int, then the resulting range is homogeneous. If not, then the range is heterogeneous.

Pre
begin <= end.
Parameters
  • begin -

    First value in the range.

  • end -

    One-past-last value in the range.

template <class End>
boost::disable_if< rime::is_constant< End >, count_range< End, End >>::type count(End const & end)

Return a range with end elements that starts with 0.

If end is a run-time value, then the range is homogeneous. If end is a constant, then the range is heterogeneous.

Pre
end >= 0.
Parameters
  • end -

    One-past-last value in the range.

auto count()

Return an infinite range starting from 0.

This is equivalent to count_from (std::size_t (0)).

Function range

template <class Function>
function_range< Function > make_function_range(Function const & function)

Create a range whose elements are the results of consecutive function calls.

The resulting range implements operations on rvalues only: it is not possible to make a copy of it. The range is noncopyable, but movable.

Table Of Contents

Previous topic

Existing ranges

Next topic

Iteration

This Page