-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
65 lines (58 loc) · 1.45 KB
/
Copy pathmain.cpp
File metadata and controls
65 lines (58 loc) · 1.45 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
#include <iostream>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <boost/version.hpp>
#if BOOST_VERSION >= 105600
#include <boost/core/demangle.hpp>
#endif
namespace reorganizer {
namespace detail {
template<typename ...Elems, std::size_t ...Indices>
auto reorganizeTuple(const std::tuple<Elems...>& tuple,
typename std::integer_sequence<std::size_t, Indices...> /*bogus*/) {
return std::make_tuple(std::get<Indices>(tuple)...);
}
}
template<std::size_t ...Indices, typename Tuple>
auto reOrganize(const Tuple& tuple) {
return detail::reorganizeTuple(tuple,
std::integer_sequence<std::size_t, Indices...>());
}
}
namespace {
template<typename In, std::size_t N = std::tuple_size<In>::value>
void printInfo(const In& /*in*/, const char* msg = nullptr) {
std::ostream& os(std::cout);
if (msg) {
os << msg;
}
char const * inname = typeid(In).name();
#if BOOST_VERSION >= 105600
os << boost::core::demangle(inname);
#else
os << inname;
#endif
os << "\n";
}
}
struct H {
};
struct E {
};
struct L {
};
struct O {
};
int main(int /*argc*/, char* /*argv*/[]) {
/*
* demonstrates how to reorganize the elements of a tuple, at compile time.
*/
auto x = std::make_tuple(H(), E(), L(), L(), O());
auto christmas = reorganizer::reOrganize<0, 4, 0, 4, 0, 4>(x);
auto manager = reorganizer::reOrganize<4, 3, 2, 1>(x);
printInfo(x, "original input:\t");
printInfo(christmas, "reorganized:\t");
printInfo(manager, "reorganized:\t");
return 0;
}