From 69acdf6584be2a04094e27b395c50c071b2b15cf Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 28 Dec 2022 13:49:54 +0000 Subject: Use the existence of .substr(...) to test if a T is stringlike --- lib/stream_support.cpp | 11 ----------- lib/stream_support.hpp | 6 ++++-- 2 files changed, 4 insertions(+), 13 deletions(-) delete mode 100644 lib/stream_support.cpp (limited to 'lib') diff --git a/lib/stream_support.cpp b/lib/stream_support.cpp deleted file mode 100644 index 2054873..0000000 --- a/lib/stream_support.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "stream_support.hpp" - -#include -#include - -static_assert(spanable>); -// static_assert(spanable>); -static_assert(spanable>); -// static_assert(spanable>); -static_assert(!spanable); -static_assert(!spanable); diff --git a/lib/stream_support.hpp b/lib/stream_support.hpp index 5f45cbf..a3565d8 100644 --- a/lib/stream_support.hpp +++ b/lib/stream_support.hpp @@ -8,14 +8,16 @@ #include #include +template +concept stringlike = requires(const S & s) { s.substr(0); }; template concept spanable = std::is_constructible_v, T> && ! -std::is_same_v>; +stringlike && !std::is_same_v, T>; namespace std { template std::ostream & - operator<<(std::ostream & s, const span v) + operator<<(std::ostream & s, const span v) { s << '('; for (const auto & i : v) { -- cgit v1.2.3