diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-08-29 12:54:18 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-08-29 12:54:18 +0100 |
commit | 8dfe3d339dc1542ee7bd59c000302765648e972c (patch) | |
tree | 791e61bfe13cdee69206478317cfcf1170412ff0 /lib/stream_support.hpp | |
parent | Use utf8_string_view for processing text to renderings (diff) | |
download | ilt-8dfe3d339dc1542ee7bd59c000302765648e972c.tar.bz2 ilt-8dfe3d339dc1542ee7bd59c000302765648e972c.tar.xz ilt-8dfe3d339dc1542ee7bd59c000302765648e972c.zip |
Generic solution for streaming collections that can be spanned
Diffstat (limited to 'lib/stream_support.hpp')
-rw-r--r-- | lib/stream_support.hpp | 18 |
1 files changed, 8 insertions, 10 deletions
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 <maths.h> #include <span> #include <sstream> +#include <type_traits> + +template<typename T> +concept spanable = std::is_constructible_v<std::span<const typename T::value_type>, T> && !std::is_same_v<char, + std::decay_t<typename T::value_type>>; namespace std { template<typename T, std::size_t L> @@ -34,16 +39,9 @@ namespace std { return (s << std::span {&v[0], L}); } - template<typename T, std::size_t L> - std::ostream & - operator<<(std::ostream & s, const array<T, L> & v) - { - return (s << std::span {v}); - } - - template<typename T> + template<spanable T> std::ostream & - operator<<(std::ostream & s, const vector<T> & 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"; |