implement pair/tuple input

This commit is contained in:
Johannes Kapfhammer 2019-10-10 14:28:35 +02:00
parent e3f3f6470d
commit 9709a35f46
2 changed files with 10 additions and 2 deletions

View File

@ -27,8 +27,7 @@ signed main() {
a.foo();
a.bar(3,4,"hi");
int i = read_int();
int j = read_int();
auto [i, j] = read<int, int>();
print(i, j);
print("read string",read<string>());

View File

@ -10,6 +10,15 @@ T read() {
return x;
}
template <typename T1, typename T2>
std::pair<T1, T2> read() {
return std::pair<T1, T2>{read<T1>(), read<T2>()};
}
template <typename T1, typename T2, typename T3, typename... Ts>
std::tuple<T1, T2, T3, Ts...> read() {
return std::tuple<T1, T2, T3, Ts...>{read<T1>(), read<T2>(), read<T3>(), read<Ts>()...};
}
int read_int() { return read<int>(); }
char read_char() { return read<char>(); }
double read_double() { return read<double>(); }