diff --git a/include/beman/utf_view/to_utf_view.hpp b/include/beman/utf_view/to_utf_view.hpp index deaad99..f13aee2 100644 --- a/include/beman/utf_view/to_utf_view.hpp +++ b/include/beman/utf_view/to_utf_view.hpp @@ -229,13 +229,20 @@ class to_utf_view : public std::ranges::view_interface return std::ranges::empty(exposition_only_base_); } - constexpr std::size_t size() + constexpr auto size() requires std::ranges::sized_range && std::same_as> && std::same_as { return std::ranges::size(exposition_only_base_); } + constexpr auto size() const + requires std::ranges::sized_range && + std::same_as> && + std::same_as { + return std::ranges::size(exposition_only_base_); + } + /* !PAPER */ #if defined(__cpp_lib_ranges_reserve_hint) /* PAPER: constexpr auto reserve_hint() requires approximately_sized_range; */ diff --git a/papers/P2728.md b/papers/P2728.md index 6a0720c..a7564d5 100644 --- a/papers/P2728.md +++ b/papers/P2728.md @@ -709,12 +709,18 @@ public: constexpr bool empty() const { return empty(@*base_*@); } - constexpr size_t size() + constexpr auto size() requires sized_range && same_as> && same_as { return size(@*base_*@); } + constexpr auto size() const + requires sized_range && same_as> && same_as + { + return size(@*base_*@); + } + constexpr auto reserve_hint() requires approximately_sized_range; constexpr auto reserve_hint() const requires approximately_sized_range; }; diff --git a/tests/beman/utf_view/to_utf_view.test.cpp b/tests/beman/utf_view/to_utf_view.test.cpp index 97052fb..9beaed1 100644 --- a/tests/beman/utf_view/to_utf_view.test.cpp +++ b/tests/beman/utf_view/to_utf_view.test.cpp @@ -84,6 +84,19 @@ static_assert( test_bidi_iterator, test_bidi_iterator>, to_utf_view_kind::replacement, char8_t>>>); +// size() is only available when a UTF-32 -> UTF-32 view is transcoding a sized range. +static_assert(std::ranges::sized_range< + to_utf_view>); +static_assert(std::ranges::sized_range< + const to_utf_view>); +static_assert(!std::ranges::sized_range< + to_utf_view>); +static_assert(!std::ranges::sized_range< + to_utf_view>); +static_assert(!std::ranges::sized_range< + to_utf_view, std::default_sentinel_t>, + to_utf_view_kind::replacement, char32_t>>); + template using test_case_code_unit_result = std::expected;