summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-12-28 13:49:54 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-12-28 13:50:06 +0000
commit69acdf6584be2a04094e27b395c50c071b2b15cf (patch)
treeb9134ccb2087960637c6d7059f51af7fb02c18e3
parentNo need for the range hack, the shadow box is just centred around the origin (diff)
downloadilt-69acdf6584be2a04094e27b395c50c071b2b15cf.tar.bz2
ilt-69acdf6584be2a04094e27b395c50c071b2b15cf.tar.xz
ilt-69acdf6584be2a04094e27b395c50c071b2b15cf.zip
Use the existence of .substr(...) to test if a T is stringlike
-rw-r--r--lib/stream_support.hpp6
-rw-r--r--test/Jamfile.jam1
-rw-r--r--test/test-static-stream_support.cpp (renamed from lib/stream_support.cpp)4
3 files changed, 7 insertions, 4 deletions
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 <sstream>
#include <type_traits>
+template<typename S>
+concept stringlike = requires(const S & s) { s.substr(0); };
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>>;
+stringlike<T> && !std::is_same_v<std::span<typename T::value_type>, T>;
namespace std {
template<typename T, std::size_t L>
std::ostream &
- operator<<(std::ostream & s, const span<const T, L> v)
+ operator<<(std::ostream & s, const span<T, L> 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/lib/stream_support.cpp b/test/test-static-stream_support.cpp
index 2054873..367d5a2 100644
--- a/lib/stream_support.cpp
+++ b/test/test-static-stream_support.cpp
@@ -4,8 +4,8 @@
#include <vector>
static_assert(spanable<std::vector<int>>);
-// static_assert(spanable<std::vector<char>>);
+static_assert(spanable<std::vector<char>>);
static_assert(spanable<std::array<int, 1>>);
-// static_assert(spanable<std::array<char, 1>>);
+static_assert(spanable<std::array<char, 1>>);
static_assert(!spanable<std::string>);
static_assert(!spanable<std::string_view>);