-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_integral_template_tuple.cpp
53 lines (45 loc) · 1.71 KB
/
examples_integral_template_tuple.cpp
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
#include <dice/template-library/integral_template_tuple.hpp>
#include <array>
#include <iostream>
using namespace dice::template_library;
template<std::size_t N>
struct int_array : std::array<int, N> {
private:
template<std::size_t... IDs>
int_array(int value, std::index_sequence<IDs...>) : std::array<int, N>{((void) IDs, value)...} {}
public:
int_array() = default;
int_array(int value) : int_array(value, std::make_index_sequence<N>{}) {}
};
template<std::size_t N>
std::ostream &operator<<(std::ostream &os, int_array<N> const &arr) {
if (N == 0) { return os << "0: []"; }
os << N << ": [";
for (std::size_t i = 0; i < N - 1; ++i) { os << arr[i] << ", "; }
return os << arr[N - 1] << ']';
}
int main() {
{
std::cout << "tuple of integer arrays, size 5 to 8, default constructor:\n";
integral_template_tuple<5UL, 8, int_array> itt;
std::cout << " " << itt.template get<5>() << '\n';
std::cout << " " << itt.template get<6>() << '\n';
std::cout << " " << itt.template get<7>() << '\n';
std::cout << " " << itt.template get<8>() << "\n\n";
}
{
std::cout << "tuple of integer arrays, size 5 to 8, specific constructor:\n";
integral_template_tuple<5UL, 8, int_array> itt{uniform_construct, 42};
std::cout << " " << itt.template get<5>() << '\n';
std::cout << " " << itt.template get<6>() << '\n';
std::cout << " " << itt.template get<7>() << '\n';
std::cout << " " << itt.template get<8>() << "\n\n";
}
{
std::cout << "tuple of integer arrays, size 5 to 8, subtuple:\n";
integral_template_tuple<5UL, 8, int_array> itt;
auto &sub_itt = itt.template subtuple<6, 7>();
std::cout << " " << sub_itt.template get<6>() << '\n';
std::cout << " " << sub_itt.template get<7>() << '\n';
}
}