Add pair & tuple stream output operators for tests
This commit is contained in:
parent
9edf94be0c
commit
f93383f06d
1 changed files with 20 additions and 0 deletions
|
|
@ -5,6 +5,8 @@
|
|||
#include <vector>
|
||||
#include <optional>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <tuple>
|
||||
|
||||
// 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<T> const & o)
|
|||
return s;
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
std::ostream & operator << (std::ostream & s, std::pair<T1, T2> const & p)
|
||||
{
|
||||
s << '(' << p.first << ", " << p.second << ')';
|
||||
return s;
|
||||
}
|
||||
|
||||
template <typename ... Ts>
|
||||
std::ostream & operator << (std::ostream & s, std::tuple<Ts...> const & t)
|
||||
{
|
||||
s << '(';
|
||||
[&]<std::size_t ... Is>(std::index_sequence<Is...>){
|
||||
((s << (Is == 0 ? "" : ", ") << std::get<Is>(t)), ...);
|
||||
}(std::make_index_sequence<sizeof...(Ts)>{});
|
||||
s << ')';
|
||||
return s;
|
||||
}
|
||||
|
||||
#include <psemek/util/to_string.hpp>
|
||||
|
||||
namespace psemek::test
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue