From f93383f06d86d056d70f91d493e256df8a9e6978 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sat, 11 Jun 2022 13:59:16 +0300 Subject: [PATCH] Add pair & tuple stream output operators for tests --- tools/test/include/psemek/test/test.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/test/include/psemek/test/test.hpp b/tools/test/include/psemek/test/test.hpp index 055b93d5..129c5ad7 100644 --- a/tools/test/include/psemek/test/test.hpp +++ b/tools/test/include/psemek/test/test.hpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include // Have to put it before including to_string.hpp due to how unqualified lookup works, // see e.g. https://alexanderlobov.net/posts/2019-07-08-function-lookup-in-templates @@ -18,6 +20,24 @@ std::ostream & operator << (std::ostream & s, std::optional const & o) return s; } +template +std::ostream & operator << (std::ostream & s, std::pair const & p) +{ + s << '(' << p.first << ", " << p.second << ')'; + return s; +} + +template +std::ostream & operator << (std::ostream & s, std::tuple const & t) +{ + s << '('; + [&](std::index_sequence){ + ((s << (Is == 0 ? "" : ", ") << std::get(t)), ...); + }(std::make_index_sequence{}); + s << ')'; + return s; +} + #include namespace psemek::test