From 8dfe3d339dc1542ee7bd59c000302765648e972c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 29 Aug 2022 12:54:18 +0100 Subject: Generic solution for streaming collections that can be spanned --- lib/stream_support.hpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lib/stream_support.hpp') diff --git a/lib/stream_support.hpp b/lib/stream_support.hpp index 0552b9d..3f0165c 100644 --- a/lib/stream_support.hpp +++ b/lib/stream_support.hpp @@ -5,6 +5,11 @@ #include #include #include +#include + +template +concept spanable = std::is_constructible_v, T> && !std::is_same_v>; namespace std { template @@ -34,16 +39,9 @@ namespace std { return (s << std::span {&v[0], L}); } - template - std::ostream & - operator<<(std::ostream & s, const array & v) - { - return (s << std::span {v}); - } - - template + template std::ostream & - operator<<(std::ostream & s, const vector & v) + operator<<(std::ostream & s, const T & v) { return (s << std::span {v}); } @@ -61,7 +59,7 @@ streamed_string(const T & v) { std::stringstream ss; ss << v; - return ss.str(); + return std::move(ss).str(); } #define CLOG(x) std::cerr << #x " : " << x << "\n"; -- cgit v1.2.3