From f141cb3e958be42eefdeca312910c71403648813 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 10 Aug 2024 14:18:15 +1000 Subject: [PATCH] concepts: don't check end -> legacy_iterator in iterable This doesn't work for sentinel ranges. Rather we mainly care that the begin/end results can be compared. --- cruft/util/concepts.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cruft/util/concepts.hpp b/cruft/util/concepts.hpp index 65dd727b..af9f9359 100644 --- a/cruft/util/concepts.hpp +++ b/cruft/util/concepts.hpp @@ -53,13 +53,19 @@ namespace cruft::concepts { /// Anything that can be looped over using begin/end + /// + /// We don't check end against legacy_iterator because that won't work for std::default_sentinel. + /// Rather, the important part is that it's equality comparable against whatever std::begin returns. template concept iterable = requires (T t) { { std::begin (t) } -> named::legacy_iterator; - { std::end (t) } -> named::legacy_iterator; + std::begin (t) == std::end (t); + std::begin (t) != std::end (t); + { std::cbegin (t) } -> named::legacy_iterator; - { std::cend (t) } -> named::legacy_iterator; + std::cbegin (t) == std::cend (t); + std::cbegin (t) != std::cend (t); };