-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuple.h
50 lines (48 loc) · 1.32 KB
/
tuple.h
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
// Copyright (c) Mathieu Malaterre
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <iostream>
// boost::program_options does not handle std::array so write our own wrapper
// https://stackoverflow.com/questions/38465195/boostprogram-options-appears-to-cast-stdarray-to-boostarray
template<typename T, int N>
struct tuple;
template<typename T, int N>
std::istream& operator>>(std::istream& is, tuple<T, N>& rhs);
template<typename T, int N>
std::ostream& operator<<(std::ostream& os, const tuple<T, N>& rhs);
template<typename T, int N>
struct tuple
{
T values[N];
friend std::istream& operator>><>(std::istream& is, tuple<T, N>& val);
friend std::ostream& operator<<<>(std::ostream& os, const tuple<T, N>& val);
};
template<typename T, int N>
inline std::istream& operator>>(std::istream& is, tuple<T, N>& val)
{
for (int i = 0; i < N; ++i)
{
if (i)
{
if (is.peek() == ',' || is.peek() == 'x' || is.peek() == '+')
{
is.ignore();
}
}
is >> val.values[i];
}
return is;
}
template<typename T, int N>
inline std::ostream& operator<<(std::ostream& os, const tuple<T, N>& val)
{
for (int i = 0; i < N; ++i)
{
if (i)
{
os << ',';
}
os << val.values[i];
}
return os;
}