https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116399
--- Comment #19 from Jonathan Wakely <redi at gcc dot gnu.org> --- We could do this, and rely on the fact that the number of aliases is always small so that we can claim it's O(1): --- a/libstdc++-v3/include/std/text_encoding +++ b/libstdc++-v3/include/std/text_encoding @@ -644,6 +644,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __i; } + friend constexpr difference_type + operator-(_Sentinel __s, _Iterator __i) + { + __glibcxx_assert(__i._M_rep != nullptr); + difference_type __n = 0; + if (const _Rep* __rep = __i._M_rep) + while (__rep[__n]._M_id == __i._M_id) + ++__n; + return __n; + } + + friend constexpr difference_type + operator-(_Iterator __i, _Sentinel __s) + { return -(__s - __i); } + private: friend struct text_encoding;