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 ++++-- test/Jamfile.jam | 1 + test/test-static-stream_support.cpp | 11 +++++++++++ 4 files changed, 16 insertions(+), 13 deletions(-) delete mode 100644 lib/stream_support.cpp create mode 100644 test/test-static-stream_support.cpp 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) { diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 32c522b..6a83f9c 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -33,3 +33,4 @@ run test-enumDetails.cpp ; run test-render.cpp ; run test-glContextBhvr.cpp ; compile test-static-enumDetails.cpp ; +compile test-static-stream_support.cpp ; diff --git a/test/test-static-stream_support.cpp b/test/test-static-stream_support.cpp new file mode 100644 index 0000000..367d5a2 --- /dev/null +++ b/test/test-static-stream_support.cpp @@ -0,0 +1,11 @@ +#include "stream_support.hpp" + +#include +#include + +static_assert(spanable>); +static_assert(spanable>); +static_assert(spanable>); +static_assert(spanable>); +static_assert(!spanable); +static_assert(!spanable); -- cgit v1.2.3