tlx
Loading...
Searching...
No Matches
call_for_range.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * tlx/meta/call_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_CALL_FOR_RANGE_HEADER
12#define TLX_META_CALL_FOR_RANGE_HEADER
13
14#include <utility>
15
17
18namespace tlx {
19
20//! \addtogroup tlx_meta
21//! \{
22
23/******************************************************************************/
24// Variadic Template Enumerator: run a generic templated functor (like a generic
25// lambda) for the integers 0 .. Size-1 or more general [Begin,End).
26//
27// Called with func(StaticIndex<> index).
28
29namespace meta_detail {
30
31//! helper for call_for_range: general recursive case
32template <size_t Index, size_t Size, typename Functor>
34{
35public:
36 static void call(Functor&& f) {
37 std::forward<Functor>(f)(StaticIndex<Index>());
39 std::forward<Functor>(f));
40 }
41};
42
43//! helper for call_for_range: base case
44template <size_t Index, typename Functor>
45class CallForRangeImpl<Index, 0, Functor>
46{
47public:
48 static void call(Functor&& /* f */) { }
49};
50
51} // namespace meta_detail
52
53//! Call a generic functor (like a generic lambda) for the integers [0,Size).
54template <size_t Size, typename Functor>
55void call_for_range(Functor&& f) {
57 std::forward<Functor>(f));
58}
59
60//! Call a generic functor (like a generic lambda) for the integers [Begin,End).
61template <size_t Begin, size_t End, typename Functor>
62void call_for_range(Functor&& f) {
64 std::forward<Functor>(f));
65}
66
67//! \}
68
69} // namespace tlx
70
71#endif // !TLX_META_CALL_FOR_RANGE_HEADER
72
73/******************************************************************************/
helper for call_for_range: general recursive case
static void call(Functor &&f)
void call_for_range(Functor &&f)
Call a generic functor (like a generic lambda) for the integers [0,Size).
Helper for call_foreach_with_index() to save the index as a compile-time index.