diff --git a/common/main/d_zip.h b/common/main/d_zip.h index 3327b148a..c84355905 100644 --- a/common/main/d_zip.h +++ b/common/main/d_zip.h @@ -121,6 +121,11 @@ index_type range_index_type(std::tuple *); */ template +requires( + requires { + typename std::iterator_traits::difference_type; + } +) class zip_iterator : std::tuple { using base_type = std::tuple; diff --git a/common/unittest/zip.cpp b/common/unittest/zip.cpp index e2e6fc07d..0af1f9928 100644 --- a/common/unittest/zip.cpp +++ b/common/unittest/zip.cpp @@ -99,6 +99,12 @@ static_assert(assert_same_type, decltype(d_zip::detail::get_static_size(std::declval()))>::value); static_assert(assert_same_type, decltype(d_zip::detail::get_static_size(std::declval &>()))>::value); +template +requires(std::ranges::range) +struct check_is_range : std::true_type +{ +}; + template requires(std::ranges::borrowed_range) struct check_is_borrowed_range : std::true_type @@ -106,3 +112,25 @@ struct check_is_borrowed_range : std::true_type }; static_assert(check_is_borrowed_range()))>::value); + +struct difference_range +{ + struct iterator { + int *operator *() const; + iterator &operator++(); + iterator operator++(int); + constexpr auto operator<=>(const iterator &) const = default; + using difference_type = short; + using value_type = int; + using pointer = value_type *; + using reference = value_type &; + using iterator_category = std::forward_iterator_tag; + }; + struct index_type {}; + iterator begin(); + iterator end(); +}; + +static_assert(check_is_range())>::value); +static_assert(check_is_borrowed_range())>::value); +static_assert(assert_same_type()).begin())::difference_type>::value);