Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2278R4: cbegin should always return a constant iterator ("Ranges" and "Span" sections) #3187

Merged
merged 21 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ namespace ranges {
template <class _Ty>
inline constexpr bool _Is_initializer_list = _Is_specialization_v<remove_cvref_t<_Ty>, initializer_list>;

#if _HAS_CXX23
_EXPORT_STD template <range _Rng>
using const_iterator_t = const_iterator<iterator_t<_Rng>>;

JMazurkiewicz marked this conversation as resolved.
Show resolved Hide resolved
_EXPORT_STD template <range _Rng>
using const_sentinel_t = const_sentinel<sentinel_t<_Rng>>;

_EXPORT_STD template <range _Rng>
using range_const_reference_t = iter_const_reference_t<iterator_t<_Rng>>;
#endif // _HAS_CXX23

// clang-format off
_EXPORT_STD template <class _Rng>
JMazurkiewicz marked this conversation as resolved.
Show resolved Hide resolved
concept viewable_range = range<_Rng>
Expand All @@ -45,20 +56,19 @@ namespace ranges {
concept _Simple_view = view<_Rng> && range<const _Rng>
&& same_as<iterator_t<_Rng>, iterator_t<const _Rng>>
&& same_as<sentinel_t<_Rng>, sentinel_t<const _Rng>>;
// clang-format on

template <class _Ty>
concept _Valid_movable_box_object =
#if _HAS_CXX23
move_constructible<_Ty>
move_constructible<_Ty>
#else // ^^^ C++23 / C++20 vvv
copy_constructible<_Ty>
copy_constructible<_Ty>
#endif // C++20
&& _Destructible_object<_Ty>;
&& _Destructible_object<_Ty>;

template <class _It>
concept _Has_arrow = input_iterator<_It>
&& (is_pointer_v<_It> || _Has_member_arrow<_It&>);
// clang-format on
concept _Has_arrow = input_iterator<_It> && (is_pointer_v<_It> || _Has_member_arrow<_It&>);

template <bool _IsConst, class _Ty>
using _Maybe_const = conditional_t<_IsConst, const _Ty, _Ty>;
Expand Down
45 changes: 34 additions & 11 deletions stl/inc/span
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ _EMIT_STL_WARNING(STL4038, "The contents of <span> are available only with C++20
#include <type_traits>
#include <xutility>


#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
Expand Down Expand Up @@ -312,16 +311,20 @@ private:
using _Mybase::_Mysize;

public:
using element_type = _Ty;
using value_type = remove_cv_t<_Ty>;
using size_type = size_t;
using difference_type = ptrdiff_t;
using pointer = _Ty*;
using const_pointer = const _Ty*;
using reference = _Ty&;
using const_reference = const _Ty&;
using iterator = _Span_iterator<_Ty>;
using reverse_iterator = _STD reverse_iterator<iterator>;
using element_type = _Ty;
using value_type = remove_cv_t<_Ty>;
using size_type = size_t;
using difference_type = ptrdiff_t;
using pointer = _Ty*;
using const_pointer = const _Ty*;
using reference = _Ty&;
using const_reference = const _Ty&;
using iterator = _Span_iterator<_Ty>;
using reverse_iterator = _STD reverse_iterator<iterator>;
#if _HAS_CXX23 && defined(__cpp_lib_concepts)
using const_iterator = _STD const_iterator<iterator>;
using const_reverse_iterator = _STD const_iterator<reverse_iterator>;
#endif // _HAS_CXX23 && defined(__cpp_lib_concepts)

static constexpr size_type extent = _Extent;

Expand Down Expand Up @@ -617,6 +620,16 @@ public:
#endif // _ITERATOR_DEBUG_LEVEL
}

#if _HAS_CXX23 && defined(__cpp_lib_concepts)
_NODISCARD constexpr const_iterator cbegin() const noexcept {
return begin();
}

_NODISCARD constexpr const_iterator cend() const noexcept {
return end();
}
#endif // _HAS_CXX23 && defined(__cpp_lib_concepts)

_NODISCARD constexpr reverse_iterator rbegin() const noexcept {
return reverse_iterator{end()};
}
Expand All @@ -625,6 +638,16 @@ public:
return reverse_iterator{begin()};
}

#if _HAS_CXX23 && defined(__cpp_lib_concepts)
_NODISCARD constexpr const_reverse_iterator crbegin() const noexcept {
return rbegin();
}

_NODISCARD constexpr const_reverse_iterator crend() const noexcept {
return rend();
}
#endif // _HAS_CXX23 && defined(__cpp_lib_concepts)

_NODISCARD constexpr pointer _Unchecked_begin() const noexcept {
return _Mydata;
}
Expand Down
Loading