Interface Documentation
Version: invalid
tuple_visitor.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Triad National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #include <tuple>
19 
20 namespace flecsi {
21 namespace util {
22 
23 template<typename _Tuple, typename _Fn, size_t... _Idx>
24 void
25 tuple_visitor_impl(_Tuple && t, _Fn && f, std::index_sequence<_Idx...>) {
26  /*
27  This creates an initializer list so that the index sequence is
28  expanded properly. The (f(x), 0) uses the comma operator so
29  that f is evaluated, but the resulting value is discarded. The value
30  of the entire expression is 0.
31 
32  Attribution: Andy Prowl on stackoverflow.
33  */
34  auto _l = {(f(_Idx, std::get<_Idx>(t)), 0)...};
35 }
36 
50 template<typename _Tuple, typename _Fn>
51 void
52 tuple_visitor(_Tuple && t, _Fn && f) {
53  using _Indices =
54  std::make_index_sequence<std::tuple_size_v<std::decay_t<_Tuple>>>;
55 
56  tuple_visitor_impl(std::forward<_Tuple>(t), std::forward<_Fn>(f), _Indices{});
57 }
58 
73 template<typename _Tuple, typename _Fn>
74 void
75 tuple_visitor(_Fn && f) {
76  static_assert(std::is_default_constructible<_Tuple>::value,
77  "tuple_vist tuple type is not default constructible");
78 
79  using _Indices =
80  std::make_index_sequence<std::tuple_size_v<std::decay_t<_Tuple>>>;
81 
82  tuple_visitor_impl(
83  std::forward<_Tuple>({}), std::forward<_Fn>(f), _Indices{});
84 }
85 
86 } // namespace util
87 } // namespace flecsi
void tuple_visitor(_Tuple &&t, _Fn &&f)
Definition: tuple_visitor.hh:52
Definition: control.hh:31