tlx
Loading...
Searching...
No Matches
vmap_foreach.hpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* tlx/meta/vmap_foreach.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_VMAP_FOREACH_HEADER
12
#define TLX_META_VMAP_FOREACH_HEADER
13
14
#include <tuple>
15
#include <utility>
16
17
namespace
tlx
{
18
19
//! \addtogroup tlx_meta
20
//! \{
21
22
/******************************************************************************/
23
// Variadic Template Expander: run a generic templated functor (like a generic
24
// lambda) for each of the variadic template parameters, and collect the return
25
// values in a generic std::tuple.
26
27
namespace
meta_detail
{
28
29
//! helper for vmap_foreach: base case
30
template
<
typename
Functor,
typename
Arg>
31
auto
vmap_foreach_impl
(Functor&& f, Arg&& arg) {
32
return
std::make_tuple(
33
std::forward<Functor>(f)(std::forward<Arg>(arg)));
34
}
35
36
//! helper for vmap_foreach: general recursive case
37
template
<
typename
Functor,
typename
Arg,
typename
... MoreArgs>
38
auto
vmap_foreach_impl
(Functor&& f, Arg&& arg, MoreArgs&& ... rest) {
39
auto
x = std::forward<Functor>(f)(std::forward<Arg>(arg));
40
return
std::tuple_cat(
41
std::make_tuple(std::move(x)),
42
vmap_foreach_impl
(
43
std::forward<Functor>(f), std::forward<MoreArgs>(rest) ...));
44
}
45
46
}
// namespace meta_detail
47
48
//! Call a generic functor (like a generic lambda) for each variadic template
49
//! argument.
50
template
<
typename
Functor,
typename
... Args>
51
auto
vmap_foreach
(Functor&& f, Args&& ... args) {
52
return
meta_detail::vmap_foreach_impl
(
53
std::forward<Functor>(f), std::forward<Args>(args) ...);
54
}
55
56
//! \}
57
58
}
// namespace tlx
59
60
#endif
// !TLX_META_VMAP_FOREACH_HEADER
61
62
/******************************************************************************/
tlx::vmap_foreach
auto vmap_foreach(Functor &&f, Args &&... args)
Call a generic functor (like a generic lambda) for each variadic template argument.
Definition
vmap_foreach.hpp:51
tlx::meta_detail
Definition
apply_tuple.hpp:28
tlx::meta_detail::vmap_foreach_impl
auto vmap_foreach_impl(Functor &&f, Arg &&arg)
helper for vmap_foreach: base case
Definition
vmap_foreach.hpp:31
tlx
Definition
exclusive_scan.hpp:17
tlx
meta
vmap_foreach.hpp
Generated on
for tlx by
1.14.0