From 9709a35f46fcee7921745acefe0c624bf8fe2dc6 Mon Sep 17 00:00:00 2001 From: Johannes Kapfhammer Date: Thu, 10 Oct 2019 14:28:35 +0200 Subject: [PATCH] implement pair/tuple input --- example.cpp | 3 +-- include/bits/soi-io.hpp | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/example.cpp b/example.cpp index 41e8b7b..5acaf1b 100644 --- a/example.cpp +++ b/example.cpp @@ -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(); print(i, j); print("read string",read()); diff --git a/include/bits/soi-io.hpp b/include/bits/soi-io.hpp index 84a06a0..4e8acfb 100644 --- a/include/bits/soi-io.hpp +++ b/include/bits/soi-io.hpp @@ -10,6 +10,15 @@ T read() { return x; } +template +std::pair read() { + return std::pair{read(), read()}; +} +template +std::tuple read() { + return std::tuple{read(), read(), read(), read()...}; +} + int read_int() { return read(); } char read_char() { return read(); } double read_double() { return read(); }