Menu

[34ec85]: / tuple / algorithm.hpp  Maximize  Restore  History

Download this file

81 lines (65 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef _CHILON_TUPLE_ALGORITHM_
#define _CHILON_TUPLE_ALGORITHM_
#include <chilon/type/algorithm.hpp>
#include <tuple>
namespace chilon {
namespace type {
template <int i, class... Args>
struct at<i, std::tuple<Args...>> : at<i, Args...> {};
template <class... T>
struct size<std::tuple<T...>> : size<T...> {};
}
namespace tuple {
namespace detail {
template <class R, template <class> class Folder, class Iterator, int i, bool final, class... T>
struct fold {
static R exec(std::tuple<T...> const& tuple) {
enum { index = Iterator::template index<i>::value };
enum { next_index = Iterator::template index<i + 2>::value };
return Folder<typename std::tuple_element<index, std::tuple<T...>>::type>::exec(
std::get<index>(tuple)) +
fold<R, Folder, Iterator, i + 1, next_index < sizeof...(T), T...>::exec(tuple);
}
};
template <class R, template <class> class Folder, class Iterator, int i, class... T>
struct fold<R, Folder, Iterator, i, false, T...> {
static R exec(std::tuple<T...> const& tuple) {
enum { index = Iterator::template index<i>::value };
return Folder<typename std::tuple_element<index, std::tuple<T...>>::type>::exec(std::get<index>(tuple));
}
};
template <class R, class Iterator, int i, bool final, class... T>
struct join {
static R exec(std::tuple<T...> const& tuple, char const * const joinString) {
enum { index = Iterator::template index<i>::value };
enum { next_index = Iterator::template index<i + 2>::value };
return std::get<index>(tuple) + joinString +
join<R, Iterator, i + 1, next_index < sizeof...(T), T...>::exec(tuple, joinString);
}
};
template <class R, class Iterator, int i, class... T>
struct join<R, Iterator, i, false, T...> {
enum { index = Iterator::template index<i>::value };
static R exec(std::tuple<T...> const& tuple, char const * const joinString) {
return std::get<index>(tuple);
}
};
}
template <class R, template <class> class Folder, class Iterator = type::identity>
struct fold {
template <class... T>
static R exec(std::tuple<T...> const& tuple) {
enum { next_index = Iterator::template index<1>::value };
return detail::fold<R, Folder, Iterator, 0, next_index < sizeof...(T), T...>::exec(tuple);
}
};
template <class R, class Iterator = type::identity>
struct join {
template <class... T>
static R exec(std::tuple<T...> const& tuple, char const * const joinString = " ") {
enum { next_index = Iterator::template index<1>::value };
return detail::join<R, Iterator, 0, next_index < sizeof...(T), T...>::exec(tuple, joinString);
}
};
} }
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.