Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
tuples.h
Go to the documentation of this file.
1
/* Brush
2
copyright 2020 William La Cava
3
license: GNU/GPL v3
4
*/
5
6
#ifndef TUPLES_H
7
#define TUPLES_H
8
9
#include <variant>
10
using namespace
std
;
11
/* This code taken from
12
https://changkun.de/modern-cpp/en-us/04-containers/index.html#4-3-Tuples
13
to enable run-time indexing of tuples
14
*/
15
16
/* template <size_t n, typename... T> */
17
/* constexpr std::variant<T...> _tuple_index(const std::tuple<T...>& tpl, size_t i) */
18
/* { */
19
/* if constexpr (n >= sizeof...(T)) */
20
/* throw std::out_of_range("Tuple index out of range."); */
21
/* if (i == n) */
22
/* return std::variant<T...>{ std::in_place_index<n>, std::get<n>(tpl) }; */
23
/* return _tuple_index<(n < sizeof...(T)-1 ? n+1 : 0)>(tpl, i); */
24
/* } */
25
26
/* template <typename... T> */
27
/* constexpr std::variant<T...> tuple_index(const std::tuple<T...>& tpl, size_t i) */
28
/* { */
29
/* return _tuple_index<0>(tpl, i); */
30
/* } */
31
32
/* template <typename T0, typename ... Ts> */
33
/* std::ostream & operator<< (std::ostream & s, std::variant<T0, Ts...> const & v) */
34
/* { */
35
/* std::visit([&](auto && x){ s << x;}, v); */
36
/* return s; */
37
/* } */
38
39
40
// trying to implement constant index access for tuples
41
42
/* template <std::size_t... Is> */
43
/* struct indices {}; */
44
45
/* template <std::size_t N, std::size_t... Is> */
46
/* struct build_indices : build_indices<N-1, N-1, Is...> {}; */
47
48
/* template <std::size_t... Is> */
49
/* struct build_indices<0, Is...> : indices<Is...> {}; */
50
51
/* template <typename Tuple> */
52
/* using IndicesFor = build_indices<std::tuple_size<Tuple>::value>; */
53
54
/* template <typename Tuple, std::size_t... Indices> */
55
/* std::array<int, std::tuple_size<Tuple>::value> f_them_all(Tuple&& t, */
56
/* indices<Indices...>) */
57
/* { */
58
/* return std::array<int, std::tuple_size<Tuple>::value> { */
59
/* { f(std::get<Indices>(std::forward<Tuple>(t)))... } */
60
/* }; */
61
/* } */
62
63
/* template <typename Tuple> */
64
/* std::array<int, std::tuple_size<Tuple>::value> f_them_all(Tuple&& t) */
65
/* { */
66
/* return f_them_all(std::forward<Tuple>(t), IndicesFor<Tuple> {}); */
67
/* } */
68
69
#endif
std
STL namespace.
src
util
tuples.h
Generated by
1.10.0