tlx
Toggle main menu visibility
Loading...
Searching...
No Matches
vmap_for_range.hpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* tlx/meta/vmap_for_range.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_FOR_RANGE_HEADER
12
#define TLX_META_VMAP_FOR_RANGE_HEADER
13
14
#include <tuple>
15
#include <utility>
16
17
#include <
tlx/meta/static_index.hpp
>
18
19
namespace
tlx
{
20
21
//! \addtogroup tlx_meta
22
//! \{
23
24
/******************************************************************************/
25
// Variadic Template Enumerate Mapper: run a generic templated functor (like a
26
// generic lambda) for each value from [Begin,End), and collect the return
27
// values in a generic std::tuple.
28
//
29
// Called with func(StaticIndex<> index).
30
31
namespace
meta_detail
{
32
33
//! helper for vmap_for_range: general recursive case
34
template
<
size_t
Index,
size_t
Size,
typename
Functor>
35
class
VMapForRangeImpl
36
{
37
public
:
38
static
auto
call
(Functor&& f) {
39
// call this index before recursion
40
auto
x = std::forward<Functor>(f)(
StaticIndex<Index>
());
41
return
std::tuple_cat(
42
std::make_tuple(std::move(x)),
43
VMapForRangeImpl<Index + 1, Size - 1, Functor>::call
(
44
std::forward<Functor>(f)));
45
}
46
};
47
48
//! helper for vmap_for_range: base case
49
template
<
size_t
Index,
typename
Functor>
50
class
VMapForRangeImpl
<Index, 0, Functor>
51
{
52
public
:
53
static
auto
call
(Functor&&
/* f */
) {
54
return
std::tuple<>();
55
}
56
};
57
58
}
// namespace meta_detail
59
60
//! Vmap a generic functor (like a generic lambda) for the integers [0,Size).
61
template
<
size_t
Size,
typename
Functor>
62
auto
vmap_for_range
(Functor&& f) {
63
return
meta_detail::VMapForRangeImpl<0, Size, Functor>::call
(
64
std::forward<Functor>(f));
65
}
66
67
//! Vmap a generic functor (like a generic lambda) for the integers [Begin,End).
68
template
<
size_t
Begin,
size_t
End,
typename
Functor>
69
auto
vmap_for_range
(Functor&& f) {
70
return
meta_detail::VMapForRangeImpl<Begin, End - Begin, Functor>::call
(
71
std::forward<Functor>(f));
72
}
73
74
//! \}
75
76
}
// namespace tlx
77
78
#endif
// !TLX_META_VMAP_FOR_RANGE_HEADER
79
80
/******************************************************************************/
tlx::meta_detail::VMapForRangeImpl< Index, 0, Functor >::call
static auto call(Functor &&)
Definition
vmap_for_range.hpp:53
tlx::meta_detail::VMapForRangeImpl
helper for vmap_for_range: general recursive case
Definition
vmap_for_range.hpp:36
tlx::meta_detail::VMapForRangeImpl::call
static auto call(Functor &&f)
Definition
vmap_for_range.hpp:38
tlx::vmap_for_range
auto vmap_for_range(Functor &&f)
Vmap a generic functor (like a generic lambda) for the integers [0,Size).
Definition
vmap_for_range.hpp:62
tlx::meta_detail
Definition
apply_tuple.hpp:28
tlx
Definition
exclusive_scan.hpp:17
static_index.hpp
tlx::StaticIndex
Helper for call_foreach_with_index() to save the index as a compile-time index.
Definition
static_index.hpp:24
tlx
meta
vmap_for_range.hpp
Generated on
for tlx by
1.17.0