Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
75fe088
[libc++][ranges] P2116R9: Implements `views::enumerate`
Zingam Jun 14, 2023
5d9b919
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
Zingam Dec 20, 2023
bb520bc
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
Zingam Dec 31, 2023
eb53557
WIP: Commented out improperly completed tests temporarily
Zingam Dec 31, 2023
8f922d1
WIP: Addressed comments
Zingam Dec 31, 2023
9a9f5d3
WIP: nothing
Zingam Jan 1, 2024
9d51f6c
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
Zingam Jan 1, 2024
3b5f9f3
WIP: Address comment in `adaptor.pass.cpp`
Zingam Jan 1, 2024
20c59fb
WIP: tweak
Zingam Jan 1, 2024
963aa35
WIP: Addressed some comments
Zingam Jan 4, 2024
6c1146b
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
Zingam Jan 4, 2024
2870bbe
REMOVED: Commented out broken test (Restore them later)
Zingam Jan 4, 2024
8a02a2e
WIP: Fixed formatting
Zingam Jan 4, 2024
2dccd6c
WIP: Addressed some comments
Zingam Jan 4, 2024
b922f91
WIP: Addressed comments in iterator/subscript
Zingam Jan 4, 2024
2d7982f
WIP: Updated iterator/artithmetic.pass
Zingam Jan 4, 2024
9cfed98
WIP: do not push
Zingam Jan 23, 2024
0c80538
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
Zingam Feb 21, 2024
5089669
Fixed LLVM target version
Zingam Feb 21, 2024
44cb342
Fixed CI
Zingam Feb 21, 2024
b4813f0
Fixed formatting
Zingam Feb 21, 2024
2c66334
Refactoring
H-G-Hristov Feb 21, 2024
deda69d
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Mar 1, 2024
cc7e27a
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Mar 1, 2024
251e8ae
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov May 1, 2024
9c2019b
Generated files
H-G-Hristov May 1, 2024
35db57f
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov May 1, 2024
c176417
Mark members `[[nodiscard]] `
H-G-Hristov May 1, 2024
645b5ce
Mark more members as `[[nodiscard]] `
H-G-Hristov May 1, 2024
16f2c8c
More `[[nodiscard]] `
H-G-Hristov May 1, 2024
124eab9
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 19, 2024
ef591c5
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 19, 2024
d9bdafc
Updated Release Notes
H-G-Hristov Jul 19, 2024
28592f6
Merge remote-tracking branch 'origin/main' into hgh/libcxx/P2164R9-ra…
H-G-Hristov Jul 21, 2024
1ccf784
Fixed [[nodiscard]]
H-G-Hristov Jul 21, 2024
2757c72
Try again
H-G-Hristov Jul 21, 2024
459b1e5
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 21, 2024
4d9aa3f
Try again
H-G-Hristov Jul 21, 2024
44fc950
Removed excessive `[[nodiscard]]`, which is not practical on incremen…
H-G-Hristov Jul 21, 2024
805331b
Cleanup
H-G-Hristov Jul 22, 2024
cd1eb6b
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 22, 2024
856d129
Try to fix CI
H-G-Hristov Jul 22, 2024
0d1c1d8
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 22, 2024
5616879
WIP - nodiscard tests
H-G-Hristov Jul 23, 2024
547e1e5
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 23, 2024
43f0018
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 23, 2024
ab93ac3
WIP - nodiscard tests
H-G-Hristov Jul 23, 2024
62621dd
WIP - nodiscard tests
H-G-Hristov Jul 24, 2024
8b98539
WIP - nodiscard tests
H-G-Hristov Jul 24, 2024
7eb8c3a
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 24, 2024
82fd225
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 25, 2024
6f83477
WIP - nodiscard tests
H-G-Hristov Jul 25, 2024
a0551a5
Updated `nodiscard` tests
H-G-Hristov Jul 29, 2024
66b1019
Cleaned `nodiscard` tests
H-G-Hristov Jul 29, 2024
4e9c874
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 29, 2024
6449bc9
Minor tweaks
H-G-Hristov Jul 29, 2024
b6bceeb
Minor tweak
H-G-Hristov Jul 29, 2024
d537977
Formatting
H-G-Hristov Jul 29, 2024
d7e7c91
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
Zingam Jul 29, 2024
b699d75
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
Zingam Jul 30, 2024
1a1162d
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Oct 9, 2024
8f2d945
Post merge fixes
H-G-Hristov Oct 9, 2024
dd8cb11
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
Zingam Oct 9, 2024
749357a
Post-merge fixes
H-G-Hristov Oct 9, 2024
daf5f9e
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
Zingam Oct 9, 2024
9c20572
Try to fix build
H-G-Hristov Oct 9, 2024
4c5d08b
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
Zingam Oct 13, 2024
c6fed09
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Feb 18, 2025
a2ed592
Update status pages
H-G-Hristov Feb 18, 2025
4d86aaa
Fixed formatting
H-G-Hristov Feb 18, 2025
a103387
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Feb 18, 2025
f205395
Implemented LWG3919
H-G-Hristov Feb 18, 2025
31ddab0
Try to fix CI: mark internal aliases `_LIBCPP_NODEBUG`
H-G-Hristov Feb 18, 2025
12e9cbb
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Feb 18, 2025
1d21194
Try again
H-G-Hristov Feb 18, 2025
a5be216
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Feb 18, 2025
fbd197a
Try again
H-G-Hristov Feb 18, 2025
d3afb06
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Feb 18, 2025
6056552
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Mar 7, 2025
d98841b
Update libcxx/test/std/ranges/range.adaptors/range.enumerate/types.h
H-G-Hristov Mar 7, 2025
f964234
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov May 16, 2025
9406fee
Run generator scripts
H-G-Hristov May 16, 2025
80e3496
Apply frederick-js's suggestion to fix CI
H-G-Hristov May 16, 2025
cb285a1
Use new syntax `// REQUIRES: std-at-least-c++23`
H-G-Hristov May 16, 2025
da79bbc
Try to fix tests
H-G-Hristov May 16, 2025
7c0bf4f
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov May 16, 2025
a6b030a
Try again
H-G-Hristov May 16, 2025
bfb4ae6
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov May 16, 2025
9f630c4
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 22, 2025
790089c
LLVM22
H-G-Hristov Jul 22, 2025
3d95751
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Jul 25, 2025
4c1eb2c
CPO test
H-G-Hristov Jul 25, 2025
dc183b0
Updated CPO test
H-G-Hristov Jul 25, 2025
b887a1b
Merge branch 'main' into hgh/libcxx/P2164R9-ranges-enumerate_view
H-G-Hristov Sep 10, 2025
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
2 changes: 2 additions & 0 deletions libcxx/docs/FeatureTestMacroTable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ Status
--------------------------------------------------- -----------------
``__cpp_lib_ranges_chunk_by`` ``202202L``
--------------------------------------------------- -----------------
``__cpp_lib_ranges_enumerate`` ``202302L``
--------------------------------------------------- -----------------
``__cpp_lib_ranges_iota`` *unimplemented*
--------------------------------------------------- -----------------
``__cpp_lib_ranges_join_with`` *unimplemented*
Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx23Papers.csv
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"","","","","","",""
"`P0290R4 <https://wg21.link/P0290R4>`__","LWG", "``apply()`` for ``synchronized_value<T>``","February 2023","","","|concurrency TS|"
"`P2770R0 <https://wg21.link/P2770R0>`__","LWG", "Stashing stashing ``iterators`` for proper flattening","February 2023","|In Progress|","","|ranges|"
"`P2164R9 <https://wg21.link/P2164R9>`__","LWG", "``views::enumerate``","February 2023","","","|ranges|"
"`P2164R9 <https://wg21.link/P2164R9>`__","LWG", "``views::enumerate``","February 2023","|Complete|","18.0","|ranges|"
"`P2711R1 <https://wg21.link/P2711R1>`__","LWG", "Making multi-param constructors of ``views`` ``explicit``","February 2023","|In Progress| [#note-P2711R1]_","","|ranges|"
"`P2609R3 <https://wg21.link/P2609R3>`__","LWG", "Relaxing Ranges Just A Smidge","February 2023","","","|ranges|"
"`P2713R1 <https://wg21.link/P2713R1>`__","LWG", "Escaping improvements in ``std::format``","February 2023","","","|format|"
Expand Down
4 changes: 2 additions & 2 deletions libcxx/docs/Status/Cxx2cIssues.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"`3903 <https://wg21.link/LWG3903>`__","span destructor is redundantly noexcept","Varna June 2023","|Complete|","7.0",""
"`3904 <https://wg21.link/LWG3904>`__","``lazy_split_view::outer-iterator``'s const-converting constructor isn't setting ``trailing_empty_``","Varna June 2023","","","|ranges|"
"`3905 <https://wg21.link/LWG3905>`__","Type of ``std::fexcept_t``","Varna June 2023","|Complete|","3.4",""
"`3912 <https://wg21.link/LWG3912>`__","``enumerate_view::iterator::operator-`` should be ``noexcept``","Varna June 2023","","","|ranges|"
"`3914 <https://wg21.link/LWG3914>`__","Inconsistent template-head of ``ranges::enumerate_view``","Varna June 2023","","","|ranges|"
"`3912 <https://wg21.link/LWG3912>`__","``enumerate_view::iterator::operator-`` should be ``noexcept``","Varna June 2023","|Complete|","18.0","|ranges|"
"`3914 <https://wg21.link/LWG3914>`__","Inconsistent template-head of ``ranges::enumerate_view``","Varna June 2023","|Complete|","18.0","|ranges|"
"`3915 <https://wg21.link/LWG3915>`__","Redundant paragraph about expression variations","Varna June 2023","","","|ranges|"
"`3925 <https://wg21.link/LWG3925>`__","Concept ``formattable``'s definition is incorrect","Varna June 2023","|Complete|","17.0","|format|"
"`3927 <https://wg21.link/LWG3927>`__","Unclear preconditions for ``operator[]`` for sequence containers","Varna June 2023","|Nothing To Do|","",""
Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/Status/RangesViews.csv
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ C++23,`chunk_by <https://wg21.link/P2443R1>`_,Jakub Mazurkiewicz,`D144767 <https
C++23,`as_const <https://wg21.link/P2278R4>`_,Unassigned,No patch yet,Not started
C++23,`as_rvalue <https://wg21.link/P2446R2>`_,Nikolas Klauser,`D137637 <https://llvm.org/D137637>`_,✅
C++23,`stride <https://wg21.link/P1899R3>`_,Hristo Hristov and Will Hawkins,`D156924 <https://llvm.org/D156924>`_,In Progress
C++23,`enumerate <https://wg21.link/P2164R9>`_,Hristo Hristov,`D157193 <https://reviews.llvm.org/D157193>`_,In Progress
C++23,`enumerate <https://wg21.link/P2164R9>`_,Hristo Hristov,`D157193 <https://reviews.llvm.org/D157193>`_,
1 change: 1 addition & 0 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ set(files
__ranges/empty_view.h
__ranges/enable_borrowed_range.h
__ranges/enable_view.h
__ranges/enumerate_view.h
__ranges/filter_view.h
__ranges/from_range.h
__ranges/iota_view.h
Expand Down
333 changes: 333 additions & 0 deletions libcxx/include/__ranges/enumerate_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,333 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___RANGES_ENUMERATE_VIEW_H
#define _LIBCPP___RANGES_ENUMERATE_VIEW_H

#include <__concepts/convertible_to.h>
#include <__config>
#include <__iterator/concepts.h>
#include <__iterator/distance.h>
#include <__iterator/iter_move.h>
#include <__iterator/iterator_traits.h>
#include <__ranges/access.h>
#include <__ranges/all.h>
#include <__ranges/concepts.h>
#include <__ranges/enable_borrowed_range.h>
#include <__ranges/range_adaptor.h>
#include <__ranges/size.h>
#include <__ranges/view_interface.h>
#include <__type_traits/maybe_const.h>
#include <__utility/forward.h>
#include <__utility/move.h>
#include <tuple>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

#if _LIBCPP_STD_VER >= 23

namespace ranges {

// [concept.object]

template <class _Rp>
concept __range_with_movable_references =
ranges::input_range<_Rp> && std::move_constructible<ranges::range_reference_t<_Rp>> &&
std::move_constructible<ranges::range_rvalue_reference_t<_Rp>>;

// [range.enumerate.view]

template <view _View>
requires __range_with_movable_references<_View>
class enumerate_view : public view_interface<enumerate_view<_View>> {
_View __base_ = _View();

// [range.enumerate.iterator]
template <bool _Const>
class __iterator;

// [range.enumerate.sentinel]
template <bool _Const>
class __sentinel;

template <bool _AnyConst>
_LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const __iterator<_AnyConst>& __iter) {
return (__iter.__current_);
}

public:
_LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
requires(default_initializable<_View>)
= default;
_LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : __base_(std::move(__base)){};

_LIBCPP_HIDE_FROM_ABI constexpr auto begin()
requires(!__simple_view<_View>)
{
return __iterator<false>(ranges::begin(__base_), 0);
}
_LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
requires __range_with_movable_references<const _View>
{
return __iterator<true>(ranges::begin(__base_), 0);
}

_LIBCPP_HIDE_FROM_ABI constexpr auto end()
requires(!__simple_view<_View>)
{
if constexpr (common_range<_View> && sized_range<_View>)
return __iterator<false>(ranges::end(__base_), ranges::distance(__base_));
else
return __sentinel<false>(ranges::end(__base_));
}
_LIBCPP_HIDE_FROM_ABI constexpr auto end() const
requires __range_with_movable_references<const _View>
{
if constexpr (common_range<const _View> && sized_range<const _View>)
return __iterator<true>(ranges::end(__base_), ranges::distance(__base_));
else
return __sentinel<true>(ranges::end(__base_));
}

_LIBCPP_HIDE_FROM_ABI constexpr auto size()
requires sized_range<_View>
{
return ranges::size(__base_);
}
_LIBCPP_HIDE_FROM_ABI constexpr auto size() const
requires sized_range<const _View>
{
return ranges::size(__base_);
}

_LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
requires copy_constructible<_View>
{
return __base_;
}
_LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); }
};

template <class _Range>
enumerate_view(_Range&&) -> enumerate_view<views::all_t<_Range>>;

// [range.enumerate.iterator]

template <view _View>
requires __range_with_movable_references<_View>
template <bool _Const>
class enumerate_view<_View>::__iterator {
using _Base = __maybe_const<_Const, _View>;

static consteval auto __get_iterator_concept() {
if constexpr (random_access_range<_Base>) {
return random_access_iterator_tag{};
} else if constexpr (bidirectional_range<_Base>) {
return bidirectional_iterator_tag{};
} else if constexpr (forward_range<_Base>) {
return forward_iterator_tag{};
} else {
return input_iterator_tag{};
}
}

friend class enumerate_view<_View>;

public:
using iterator_category = input_iterator_tag;
using iterator_concept = decltype(__get_iterator_concept());
using difference_type = range_difference_t<_Base>;
using value_type = tuple<difference_type, range_value_t<_Base>>;

private:
using __reference_type = tuple<difference_type, range_reference_t<_Base>>;
iterator_t<_Base> __current_ = iterator_t<_Base>();
difference_type __pos_ = 0;

_LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> __current, difference_type __pos)
: __current_(std::move(__current)), __pos_(__pos) {}

public:
_LIBCPP_HIDE_FROM_ABI __iterator()
requires(default_initializable<iterator_t<_Base>>)
= default;
_LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator<!_Const> __i)
requires _Const && convertible_to<iterator_t<_View>, iterator_t<_Base>>
: __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}

_LIBCPP_HIDE_FROM_ABI constexpr const iterator_t<_Base>& base() const& noexcept { return __current_; }
_LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Base> base() && { return std::move(__current_); }

_LIBCPP_HIDE_FROM_ABI constexpr difference_type index() const noexcept { return __pos_; }

_LIBCPP_HIDE_FROM_ABI constexpr auto operator*() const { return __reference_type(__pos_, *__current_); }

_LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() {
++__current_;
++__pos_;
return *this;
}
_LIBCPP_HIDE_FROM_ABI constexpr void operator++(int) { return ++*this; }
_LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int)
requires forward_range<_Base>
{
auto __temp = *this;
++*this;
return __temp;
}

_LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--()
requires bidirectional_range<_Base>
{
--__current_;
--__pos_;
return *this;
}
_LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int)
requires bidirectional_range<_Base>
{
auto __temp = *this;
--*this;
return *__temp;
}

_LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator+=(difference_type __n)
requires random_access_range<_Base>
{
__current_ += __n;
__pos_ += __n;
return *this;
}
_LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator-=(difference_type __n)
requires random_access_range<_Base>
{
__current_ -= __n;
__pos_ -= __n;
return *this;
}

_LIBCPP_HIDE_FROM_ABI constexpr auto operator[](difference_type __n) const
requires random_access_range<_Base>
{
return __reference_type(__pos_ + __n, __current_[__n]);
}

_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) noexcept {
return __x.__pos_ == __y.__pos_;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering
operator<=>(const __iterator& __x, const __iterator& __y) noexcept {
return __x.__pos_ <=> __y.__pos_;
}

_LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n)
requires random_access_range<_Base>
{
auto __temp = __i;
__temp += __n;
return __temp;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i)
requires random_access_range<_Base>
{
return __i + __n;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n)
requires random_access_range<_Base>
{
auto __temp = __i;
__temp -= __n;
return __temp;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr difference_type
operator-(const __iterator& __x, const __iterator& __y) noexcept {
return __x.__pos_ - __y.__pos_;
}

_LIBCPP_HIDE_FROM_ABI friend constexpr auto iter_move(const __iterator& __i) noexcept(
noexcept(ranges::iter_move(__i.__current_)) && is_nothrow_move_constructible_v<range_rvalue_reference_t<_Base>>) {
return tuple<difference_type, range_rvalue_reference_t<_Base>>(__i.__pos_, ranges::iter_move(__i.__current_));
}
};

// [range.enumerate.sentinel]

template <view _View>
requires __range_with_movable_references<_View>
template <bool _Const>
class enumerate_view<_View>::__sentinel {
using _Base = __maybe_const<_Const, _View>;
sentinel_t<_Base> __end_ = sentinel_t<_Base>();
_LIBCPP_HIDE_FROM_ABI constexpr explicit __sentinel(sentinel_t<_Base> __end) : __end_(std::move(__end)) {}

friend class enumerate_view<_View>;

public:
_LIBCPP_HIDE_FROM_ABI __sentinel() = default;
_LIBCPP_HIDE_FROM_ABI constexpr __sentinel(__sentinel<!_Const> __other)
requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
: __end_(std::move(__other.__end_)) {}

_LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Base> base() const { return __end_; }

template <bool _OtherConst>
requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
return __get_current(__x) == __y.__end_;
}

template <bool _OtherConst>
requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
_LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>>
operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
return __get_current(__x) - __y.__end_;
}

template <bool _OtherConst>
requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
_LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>>
operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) {
return __x.__end_ - __get_current(__y);
}
};

template <class _View>
constexpr bool enable_borrowed_range<enumerate_view<_View>> = enable_borrowed_range<_View>;

namespace views {
namespace __enumerate {

struct __fn : __range_adaptor_closure<__fn> {
template <class _Range>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range) const
noexcept(noexcept(/**/ enumerate_view(std::forward<_Range>(__range))))
-> decltype(/*--*/ enumerate_view(std::forward<_Range>(__range))) {
return /*-------------*/ enumerate_view(std::forward<_Range>(__range));
}
};

} // namespace __enumerate

inline namespace __cpo {

inline constexpr auto enumerate = __enumerate::__fn{};

} // namespace __cpo
} // namespace views
} // namespace ranges

#endif // _LIBCPP_STD_VER >= 23

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___RANGES_ENUMERATE_VIEW_H
1 change: 1 addition & 0 deletions libcxx/include/module.modulemap.in
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,7 @@ module std_private_ranges_empty [system] { header "__ranges
module std_private_ranges_empty_view [system] { header "__ranges/empty_view.h" }
module std_private_ranges_enable_borrowed_range [system] { header "__ranges/enable_borrowed_range.h" }
module std_private_ranges_enable_view [system] { header "__ranges/enable_view.h" }
module std_private_ranges_enumerate_view [system] { header "__ranges/enumerate_view.h" }
module std_private_ranges_filter_view [system] {
header "__ranges/filter_view.h"
export std_private_ranges_range_adaptor
Expand Down
Loading