HiPipe  0.6.0
C++17 data pipeline with Python bindings.
Classes | Typedefs | Functions
Tuple and variadic template utilites.

Classes

struct  hipipe::utility::variadic_find< T1, T2, Ts >
 Get the first index of a type in a variadic template list. More...
 
struct  hipipe::utility::maybe_tuple_impl< N, Ts >
 Wrap variadic template pack in a tuple if there is more than one type. More...
 
struct  hipipe::utility::tuple_contains< T, Tuple >
 Check whether a tuple contains a given type. More...
 

Typedefs

template<std::size_t Offset, std::size_t N>
using hipipe::utility::make_offset_index_sequence = decltype(plus< Offset >(std::make_index_sequence< N >{}))
 Make std::index_sequence with the given offset. More...
 

Functions

template<std::size_t Value, std::size_t... Is>
constexpr std::index_sequence<(Value+Is)... > hipipe::utility::plus (std::index_sequence< Is... >)
 Add a number to all values in std::index_sequence. More...
 
template<typename Tuple , typename Fun >
constexpr auto hipipe::utility::tuple_for_each (Tuple &&tuple, Fun &&fun)
 Apply a function on each element of a tuple. More...
 
template<typename Tuple , typename Fun >
constexpr auto hipipe::utility::tuple_transform (Tuple &&tuple, Fun &&fun)
 Transform each element of a tuple. More...
 
template<typename Tuple , size_t... Is>
std::ostream & hipipe::utility::tuple_print (std::ostream &out, const Tuple &tuple, std::index_sequence< Is... >)
 Tuple pretty printing to std::ostream.
 
template<typename... Ts>
std::ostream & hipipe::utility::operator<< (std::ostream &out, const std::tuple< Ts... > &tuple)
 Tuple pretty printing to std::ostream.
 
template<typename Rng , CONCEPT_REQUIRES_(ranges::Range< Rng >() &&!ranges::View< Rng >()) >
auto hipipe::utility::unzip (Rng range_of_tuples)
 Unzips a range of tuples to a tuple of ranges. More...
 
template<bool Enable, typename RangeT >
decltype(auto) hipipe::utility::unzip_if (RangeT &&range)
 Unzips a range of tuples to a tuple of ranges if a constexpr condition holds. More...
 
template<typename Tuple >
decltype(auto) hipipe::utility::maybe_untuple (Tuple &&tuple)
 Extract a value from a tuple if the tuple contains only a single value. More...
 
template<std::size_t N, typename Fun >
constexpr Fun hipipe::utility::times_with_index (Fun &&fun)
 Repeat a function N times in compile time. More...
 
template<typename Tuple , typename Fun >
constexpr auto hipipe::utility::tuple_for_each_with_index (Tuple &&tuple, Fun &&fun)
 Similar to tuple_for_each(), but with index available. More...
 
template<typename Tuple , typename Fun >
constexpr auto hipipe::utility::tuple_transform_with_index (Tuple &&tuple, Fun &&fun)
 Similar to tuple_transform(), but with index available. More...
 

Detailed Description

Typedef Documentation

◆ make_offset_index_sequence

template<std::size_t Offset, std::size_t N>
using hipipe::utility::make_offset_index_sequence = typedef decltype(plus<Offset>(std::make_index_sequence<N>{}))

Make std::index_sequence with the given offset.

Example:

std::is_same<decltype(make_offset_index_sequence<3, 4>()),
std::index_sequence<3, 4, 5, 6>>;

Definition at line 91 of file tuple.hpp.

Function Documentation

◆ maybe_untuple()

template<typename Tuple >
decltype(auto) hipipe::utility::maybe_untuple ( Tuple &&  tuple)

Extract a value from a tuple if the tuple contains only a single value.

If the tuple contains zero or more than one element, this is an identity.

Example:

std::tuple<int, double> t1{1, 3.};
auto t2 = maybe_untuple(t1);
static_assert(std::is_same_v<decltype(t2), std::tuple<int, double>>);
std::tuple<int> t3{1};
auto t4 = maybe_untuple(t3);
static_assert(std::is_same_v<decltype(t4), int>);
int i = 1;
std::tuple<int&> t5{i};
auto& t6 = maybe_untuple(t5);
static_assert(std::is_same_v<decltype(t6), int&>);
t6 = 2;
BOOST_TEST(i == 2);

Definition at line 371 of file tuple.hpp.

◆ plus()

template<std::size_t Value, std::size_t... Is>
constexpr std::index_sequence<(Value + Is)...> hipipe::utility::plus ( std::index_sequence< Is... >  )

Add a number to all values in std::index_sequence.

Example:

std::is_same<decltype(plus<2>(std::index_sequence<1, 3, 4>{})),
std::index_sequence<3, 5, 6>>;

Definition at line 77 of file tuple.hpp.

◆ times_with_index()

template<std::size_t N, typename Fun >
constexpr Fun hipipe::utility::times_with_index ( Fun &&  fun)

Repeat a function N times in compile time.

Example:

auto tpl = std::make_tuple(1, 0.25, 'a');
times_with_index<3>([&tpl](auto index) {
++std::get<index>(tpl);
});
assert(tpl == std::make_tuple(2, 1.25, 'b'));

Definition at line 403 of file tuple.hpp.

◆ tuple_for_each()

template<typename Tuple , typename Fun >
constexpr auto hipipe::utility::tuple_for_each ( Tuple &&  tuple,
Fun &&  fun 
)

Apply a function on each element of a tuple.

The order of application is from the first to the last element.

Example:

auto tpl = std::make_tuple(5, 2.);
tuple_for_each(tpl, [](auto& val) { std::cout << val << '\n'; });
Returns
The function after application.

Definition at line 119 of file tuple.hpp.

◆ tuple_for_each_with_index()

template<typename Tuple , typename Fun >
constexpr auto hipipe::utility::tuple_for_each_with_index ( Tuple &&  tuple,
Fun &&  fun 
)

Similar to tuple_for_each(), but with index available.

Example:

auto tpl = std::make_tuple(1, 2.);
tuple_for_each_with_index(tpl, [](auto& val, auto index) {
val += index;
});
assert(tpl == std::make_tuple(1, 3.));

Definition at line 422 of file tuple.hpp.

◆ tuple_transform()

template<typename Tuple , typename Fun >
constexpr auto hipipe::utility::tuple_transform ( Tuple &&  tuple,
Fun &&  fun 
)

Transform each element of a tuple.

The order of application is unspecified.

Example:

auto t1 = std::make_tuple(0, 10L, 5.);
auto t2 = tuple_transform(t1, [](const auto &v) { return v + 1; });
static_assert(std::is_same<std::tuple<int, long, double>, decltype(t2)>{});
assert(t2 == std::make_tuple(0 + 1, 10L + 1, 5. + 1));
Returns
The transformed tuple.

Definition at line 154 of file tuple.hpp.

◆ tuple_transform_with_index()

template<typename Tuple , typename Fun >
constexpr auto hipipe::utility::tuple_transform_with_index ( Tuple &&  tuple,
Fun &&  fun 
)

Similar to tuple_transform(), but with index available.

Example:

auto tpl = std::make_tuple(1, 0.25, 'a');
auto tpl2 = tuple_transform_with_index(tpl, [](auto&& elem, auto index) {
return elem + index;
});
assert(tpl2 == std::make_tuple(1, 1.25, 'c'));

Definition at line 458 of file tuple.hpp.

◆ unzip()

template<typename Rng , CONCEPT_REQUIRES_(ranges::Range< Rng >() &&!ranges::View< Rng >()) >
auto hipipe::utility::unzip ( Rng  range_of_tuples)

Unzips a range of tuples to a tuple of ranges.

Specialization of unzip function for views.

Example:

std::vector<std::tuple<int, double>> data{};
data.emplace_back(1, 5.);
data.emplace_back(2, 6.);
data.emplace_back(3, 7.);
std::vector<int> va;
std::vector<double> vb;
std::tie(va, vb) = unzip(data);

Definition at line 257 of file tuple.hpp.

◆ unzip_if()

template<bool Enable, typename RangeT >
decltype(auto) hipipe::utility::unzip_if ( RangeT &&  range)

Unzips a range of tuples to a tuple of ranges if a constexpr condition holds.

This method is enabled or disabled by its first template parameter. If disabled, it returns identity. If enabled, it returns the same thing as unzip() would return.

Example:

std::vector<std::tuple<int, double>> data{};
data.emplace_back(1, 5.);
data.emplace_back(2, 6.);
data.emplace_back(3, 7.);
std::vector<int> va;
std::vector<double> vb;
std::tie(va, vb) = unzip_if<true>(data);
std::vector<int> vc = unzip_if<false>(va);

Definition at line 317 of file tuple.hpp.