Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
call_foreach.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/meta/call_foreach.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2016-2017 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #ifndef TLX_META_CALL_FOREACH_HEADER
12 #define TLX_META_CALL_FOREACH_HEADER
13 
14 #include <utility>
15 
16 namespace tlx {
17 
18 //! \addtogroup tlx_meta
19 //! \{
20 
21 /******************************************************************************/
22 // Variadic Template Expander: run a generic templated functor (like a generic
23 // lambda) for each of the variadic template parameters.
24 
25 namespace meta_detail {
26 
27 //! helper for call_foreach: base case
28 template <typename Functor, typename Arg>
29 void call_foreach_impl(Functor&& f, Arg&& arg) {
30  std::forward<Functor>(f)(std::forward<Arg>(arg));
31 }
32 
33 //! helper for call_foreach: general recursive case
34 template <typename Functor, typename Arg, typename... MoreArgs>
36  Functor&& f, Arg&& arg, MoreArgs&& ... rest) {
37  std::forward<Functor>(f)(std::forward<Arg>(arg));
39  std::forward<Functor>(f), std::forward<MoreArgs>(rest) ...);
40 }
41 
42 } // namespace meta_detail
43 
44 //! Call a generic functor (like a generic lambda) for each variadic template
45 //! argument.
46 template <typename Functor, typename... Args>
47 void call_foreach(Functor&& f, Args&& ... args) {
49  std::forward<Functor>(f), std::forward<Args>(args) ...);
50 }
51 
52 //! \}
53 
54 } // namespace tlx
55 
56 #endif // !TLX_META_CALL_FOREACH_HEADER
57 
58 /******************************************************************************/
void call_foreach(Functor &&f, Args &&...args)
void call_foreach_impl(Functor &&f, Arg &&arg)
helper for call_foreach: base case