tlx
Loading...
Searching...
No Matches
call_foreach_tuple.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * tlx/meta/call_foreach_tuple.hpp
3 *
4 * Part of tlx - http://panthema.net/tlx
5 *
6 * Copyright (C) 2016-2017 Timo Bingmann <tb@panthema.net>
7 *
8 * All rights reserved. Published under the Boost Software License, Version 1.0
9 ******************************************************************************/
10
11#ifndef TLX_META_CALL_FOREACH_TUPLE_HEADER
12#define TLX_META_CALL_FOREACH_TUPLE_HEADER
13
14#include <tuple>
15
18
19namespace tlx {
20
21//! \addtogroup tlx_meta
22//! \{
23
24/******************************************************************************/
25// Variadic Template Expander: run a generic templated functor (like a generic
26// lambda) for each component of a std::tuple.
27//
28// Called with func(Argument arg).
29
30namespace meta_detail {
31
32//! helper for call_foreach_tuple
33template <typename Functor, typename Tuple, std::size_t... Is>
35 Functor&& f, Tuple&& t, index_sequence<Is...>) {
36 return call_foreach(
37 std::forward<Functor>(f), std::get<Is>(std::forward<Tuple>(t)) ...);
38}
39
40} // namespace meta_detail
41
42//! Call a generic functor (like a generic lambda) to each components of a tuple
43//! together with its zero-based index.
44template <typename Functor, typename Tuple>
45void call_foreach_tuple(Functor&& f, Tuple&& t) {
46 using Indices = make_index_sequence<
47 std::tuple_size<typename std::decay<Tuple>::type>::value>;
49 std::forward<Functor>(f), std::forward<Tuple>(t), Indices());
50}
51
52//! \}
53
54} // namespace tlx
55
56#endif // !TLX_META_CALL_FOREACH_TUPLE_HEADER
57
58/******************************************************************************/
void call_foreach_tuple(Functor &&f, Tuple &&t)
Call a generic functor (like a generic lambda) to each components of a tuple together with its zero-b...
void call_foreach(Functor &&f, Args &&... args)
Call a generic functor (like a generic lambda) for each variadic template argument.
void call_foreach_tuple_impl(Functor &&f, Tuple &&t, index_sequence< Is... >)
helper for call_foreach_tuple