[libc++] P2770R0: Stashing stashing iterators for proper flattening (#66033)

- Partially implements P2770R0 (http://wg21.link/p2770)
- Fixes https://wg21.link/LWG3698, https://wg21.link/LWG3700, and https://wg21.link/LWG3791
- join_with_view hasn't been done yet since this type isn't implemented yet
- Rename tuple test directory to match the standard (which changed in P2770R0)
- Rename join_view test directory to match the standard
This commit is contained in:
Jakub Mazurkiewicz authored and GitHub committed 2023-12-12 09:45:14 -05:00
1 parent 87c686700f
commit 6a66467499
55 files changed
+605 -196

No files matched your search

+1
View File
@@ -45,6 +45,7 @@ Paper Status
clang doesn't issue a diagnostic for deprecated using template declarations.
.. [#note-P2520R0] P2520R0: Libc++ implemented this paper as a DR in C++20 as well.
.. [#note-P2711R1] P2711R1: ``join_with_view`` hasn't been done yet since this type isn't implemented yet.
.. [#note-P2770R0] P2770R0: ``join_with_view`` hasn't been done yet since this type isn't implemented yet.
.. [#note-P2693R1] P2693R1: The formatter for ``std::thread::id`` is implemented.
The formatter for ``stacktrace`` is not implemented, since ``stacktrace`` is
not implemented yet.
+1 -1
View File
@@ -104,7 +104,7 @@
"`P2708R1 <https://wg21.link/P2708R1>`__","LWG", "No Further Fundamentals TSes", "November 2022","|Nothing to do|","",""
"","","","","","",""
"`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|"
"`P2770R0 <https://wg21.link/P2770R0>`__","LWG", "Stashing stashing ``iterators`` for proper flattening","February 2023","|Partial| [#note-P2770R0]_","","|ranges|"
"`P2164R9 <https://wg21.link/P2164R9>`__","LWG", "``views::enumerate``","February 2023","","","|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|"
1 Paper # Group Paper Name Meeting Status First released version Labels
104 `P2708R1 <https://wg21.link/P2708R1>`__ LWG No Further Fundamentals TSes November 2022 |Nothing to do|
105
106 `P0290R4 <https://wg21.link/P0290R4>`__ LWG ``apply()`` for ``synchronized_value<T>`` February 2023 |concurrency TS|
107 `P2770R0 <https://wg21.link/P2770R0>`__ LWG Stashing stashing ``iterators`` for proper flattening February 2023 |In Progress| |Partial| [#note-P2770R0]_ |ranges|
108 `P2164R9 <https://wg21.link/P2164R9>`__ LWG ``views::enumerate`` February 2023 |ranges|
109 `P2711R1 <https://wg21.link/P2711R1>`__ LWG Making multi-param constructors of ``views`` ``explicit`` February 2023 |In Progress| [#note-P2711R1]_ |ranges|
110 `P2609R3 <https://wg21.link/P2609R3>`__ LWG Relaxing Ranges Just A Smidge February 2023 |ranges|
-1
View File
@@ -50,7 +50,6 @@ when ``-fexperimental-library`` is passed:
* ``std::stop_token``, ``std::stop_source`` and ``std::stop_callback``
* ``std::jthread``
* ``std::chrono::tzdb`` and related time zone functionality
* ``std::ranges::join_view``
.. warning::
Experimental libraries are experimental.
+1
View File
@@ -837,6 +837,7 @@ set(files
__type_traits/void_t.h
__undef_macros
__utility/as_const.h
__utility/as_lvalue.h
__utility/auto_cast.h
__utility/cmp.h
__utility/convert_to_integral.h
+84 -54
View File
@@ -32,6 +32,8 @@
#include <__ranges/view_interface.h>
#include <__type_traits/common_type.h>
#include <__type_traits/maybe_const.h>
#include <__utility/as_lvalue.h>
#include <__utility/empty.h>
#include <__utility/forward.h>
#include <optional>
@@ -41,10 +43,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
// Note: `join_view` is still marked experimental because there is an ABI-breaking change that affects `join_view` in
// the pipeline (https://isocpp.org/files/papers/D2770R0.html).
// TODO: make `join_view` non-experimental once D2770 is implemented.
#if _LIBCPP_STD_VER >= 20 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
#if _LIBCPP_STD_VER >= 20
namespace ranges {
template<class>
@@ -84,11 +83,16 @@ namespace ranges {
template <class>
friend struct std::__segmented_iterator_traits;
static constexpr bool _UseCache = !is_reference_v<_InnerRange>;
using _Cache = _If<_UseCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>;
_LIBCPP_NO_UNIQUE_ADDRESS _Cache __cache_;
_LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
static constexpr bool _UseOuterCache = !forward_range<_View>;
using _OuterCache = _If<_UseOuterCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
_LIBCPP_NO_UNIQUE_ADDRESS _OuterCache __outer_;
static constexpr bool _UseInnerCache = !is_reference_v<_InnerRange>;
using _InnerCache = _If<_UseInnerCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>;
_LIBCPP_NO_UNIQUE_ADDRESS _InnerCache __inner_;
public:
_LIBCPP_HIDE_FROM_ABI
join_view() requires default_initializable<_View> = default;
@@ -105,16 +109,22 @@ namespace ranges {
_LIBCPP_HIDE_FROM_ABI
constexpr auto begin() {
constexpr bool __use_const = __simple_view<_View> &&
is_reference_v<range_reference_t<_View>>;
return __iterator<__use_const>{*this, ranges::begin(__base_)};
if constexpr (forward_range<_View>) {
constexpr bool __use_const = __simple_view<_View> &&
is_reference_v<range_reference_t<_View>>;
return __iterator<__use_const>{*this, ranges::begin(__base_)};
} else {
__outer_.__emplace(ranges::begin(__base_));
return __iterator<false>{*this};
}
}
template<class _V2 = _View>
_LIBCPP_HIDE_FROM_ABI
constexpr auto begin() const
requires input_range<const _V2> &&
is_reference_v<range_reference_t<const _V2>>
requires forward_range<const _V2> &&
is_reference_v<range_reference_t<const _V2>> &&
input_range<range_reference_t<const _V2>>
{
return __iterator<true>{*this, ranges::begin(__base_)};
}
@@ -134,13 +144,12 @@ namespace ranges {
template<class _V2 = _View>
_LIBCPP_HIDE_FROM_ABI
constexpr auto end() const
requires input_range<const _V2> &&
is_reference_v<range_reference_t<const _V2>>
requires forward_range<const _V2> &&
is_reference_v<range_reference_t<const _V2>> &&
input_range<range_reference_t<const _V2>>
{
using _ConstInnerRange = range_reference_t<const _View>;
if constexpr (forward_range<const _View> &&
is_reference_v<_ConstInnerRange> &&
forward_range<_ConstInnerRange> &&
if constexpr (forward_range<_ConstInnerRange> &&
common_range<const _View> &&
common_range<_ConstInnerRange>) {
return __iterator<true>{*this, ranges::end(__base_)};
@@ -154,12 +163,12 @@ namespace ranges {
requires view<_View> && input_range<range_reference_t<_View>>
template<bool _Const>
struct join_view<_View>::__sentinel {
template<bool>
private:
template <bool>
friend struct __sentinel;
private:
using _Parent = __maybe_const<_Const, join_view<_View>>;
using _Base = __maybe_const<_Const, _View>;
using _Parent = __maybe_const<_Const, join_view>;
using _Base = __maybe_const<_Const, _View>;
sentinel_t<_Base> __end_ = sentinel_t<_Base>();
public:
@@ -179,7 +188,7 @@ namespace ranges {
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 __x.__outer_ == __y.__end_;
return __x.__get_outer() == __y.__end_;
}
};
@@ -191,9 +200,7 @@ namespace ranges {
template<bool _Const>
struct join_view<_View>::__iterator final
: public __join_view_iterator_category<__maybe_const<_Const, _View>> {
template<bool>
friend struct __iterator;
friend join_view;
template <class>
friend struct std::__segmented_iterator_traits;
@@ -207,23 +214,25 @@ namespace ranges {
using _Inner = iterator_t<range_reference_t<_Base>>;
using _InnerRange = range_reference_t<_View>;
static_assert(!_Const || forward_range<_Base>, "Const can only be true when Base models forward_range.");
static constexpr bool __ref_is_glvalue = is_reference_v<range_reference_t<_Base>>;
public:
_Outer __outer_ = _Outer();
static constexpr bool _OuterPresent = forward_range<_Base>;
using _OuterType = _If<_OuterPresent, _Outer, std::__empty>;
_LIBCPP_NO_UNIQUE_ADDRESS _OuterType __outer_ = _OuterType();
private:
optional<_Inner> __inner_;
_Parent *__parent_ = nullptr;
_Parent* __parent_ = nullptr;
_LIBCPP_HIDE_FROM_ABI
constexpr void __satisfy() {
for (; __outer_ != ranges::end(__parent_->__base_); ++__outer_) {
auto&& __inner = [&]() -> auto&& {
for (; __get_outer() != ranges::end(__parent_->__base_); ++__get_outer()) {
auto&& __inner = [this]() -> auto&& {
if constexpr (__ref_is_glvalue)
return *__outer_;
return *__get_outer();
else
return __parent_->__cache_.__emplace_from([&]() -> decltype(auto) { return *__outer_; });
return __parent_->__inner_.__emplace_from([&]() -> decltype(auto) { return *__get_outer(); });
}();
__inner_ = ranges::begin(__inner);
if (*__inner_ != ranges::end(__inner))
@@ -234,8 +243,37 @@ namespace ranges {
__inner_.reset();
}
_LIBCPP_HIDE_FROM_ABI constexpr _Outer& __get_outer() {
if constexpr (forward_range<_Base>) {
return __outer_;
} else {
return *__parent_->__outer_;
}
}
_LIBCPP_HIDE_FROM_ABI constexpr const _Outer& __get_outer() const {
if constexpr (forward_range<_Base>) {
return __outer_;
} else {
return *__parent_->__outer_;
}
}
_LIBCPP_HIDE_FROM_ABI constexpr __iterator(_Parent& __parent, _Outer __outer)
requires forward_range<_Base>
: __outer_(std::move(__outer)), __parent_(std::addressof(__parent)) {
__satisfy();
}
_LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(_Parent& __parent)
requires(!forward_range<_Base>)
: __parent_(std::addressof(__parent)) {
__satisfy();
}
_LIBCPP_HIDE_FROM_ABI constexpr __iterator(_Parent* __parent, _Outer __outer, _Inner __inner)
: __outer_(std::move(__outer)), __inner_(std::move(__inner)), __parent_(__parent) {}
requires forward_range<_Base>
: __outer_(std::move(__outer)), __inner_(std::move(__inner)), __parent_(__parent) {}
public:
using iterator_concept = _If<
@@ -254,15 +292,7 @@ namespace ranges {
using difference_type = common_type_t<
range_difference_t<_Base>, range_difference_t<range_reference_t<_Base>>>;
_LIBCPP_HIDE_FROM_ABI
__iterator() requires default_initializable<_Outer> = default;
_LIBCPP_HIDE_FROM_ABI
constexpr __iterator(_Parent& __parent, _Outer __outer)
: __outer_(std::move(__outer))
, __parent_(std::addressof(__parent)) {
__satisfy();
}
_LIBCPP_HIDE_FROM_ABI __iterator() = default;
_LIBCPP_HIDE_FROM_ABI
constexpr __iterator(__iterator<!_Const> __i)
@@ -287,14 +317,14 @@ namespace ranges {
_LIBCPP_HIDE_FROM_ABI
constexpr __iterator& operator++() {
auto&& __inner = [&]() -> auto&& {
auto __get_inner_range = [&]() -> decltype(auto) {
if constexpr (__ref_is_glvalue)
return *__outer_;
return *__get_outer();
else
return *__parent_->__cache_;
}();
if (++*__inner_ == ranges::end(__inner)) {
++__outer_;
return *__parent_->__inner_;
};
if (++*__inner_ == ranges::end(std::__as_lvalue(__get_inner_range()))) {
++__get_outer();
__satisfy();
}
return *this;
@@ -324,11 +354,11 @@ namespace ranges {
common_range<range_reference_t<_Base>>
{
if (__outer_ == ranges::end(__parent_->__base_))
__inner_ = ranges::end(*--__outer_);
__inner_ = ranges::end(std::__as_lvalue(*--__outer_));
// Skip empty inner ranges when going backwards.
while (*__inner_ == ranges::begin(*__outer_)) {
__inner_ = ranges::end(*--__outer_);
while (*__inner_ == ranges::begin(std::__as_lvalue(*__outer_))) {
__inner_ = ranges::end(std::__as_lvalue(*--__outer_));
}
--*__inner_;
@@ -350,7 +380,7 @@ namespace ranges {
_LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator==(const __iterator& __x, const __iterator& __y)
requires __ref_is_glvalue &&
equality_comparable<iterator_t<_Base>> &&
forward_range<_Base> &&
equality_comparable<iterator_t<range_reference_t<_Base>>>
{
return __x.__outer_ == __y.__outer_ && __x.__inner_ == __y.__inner_;
@@ -436,7 +466,7 @@ struct __segmented_iterator_traits<_JoinViewIterator> {
}
};
#endif // #if _LIBCPP_STD_VER >= 20 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
#endif // #if _LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD
+37
View File
@@ -0,0 +1,37 @@
// -*- 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___UTILITY_AS_LVALUE_H
#define _LIBCPP___UTILITY_AS_LVALUE_H
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
_LIBCPP_HIDE_FROM_ABI constexpr _Tp& __as_lvalue(_LIBCPP_LIFETIMEBOUND _Tp&& __t) {
return static_cast<_Tp&>(__t);
}
#endif // !_LIBCPP_CXX03_LANG
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___UTILITY_AS_LVALUE_H
+1
View File
@@ -2019,6 +2019,7 @@ module std_private_type_traits_unwrap_ref [system
module std_private_type_traits_void_t [system] { header "__type_traits/void_t.h" }
module std_private_utility_as_const [system] { header "__utility/as_const.h" }
module std_private_utility_as_lvalue [system] { header "__utility/as_lvalue.h" }
module std_private_utility_auto_cast [system] {
header "__utility/auto_cast.h"
export std_private_type_traits_decay
+8
View File
@@ -697,6 +697,7 @@ public:
typedef const value_type* pointer;
typedef const value_type& reference;
typedef forward_iterator_tag iterator_category;
typedef input_iterator_tag iterator_concept; // since C++20
regex_iterator();
regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
@@ -737,6 +738,7 @@ public:
typedef const value_type* pointer;
typedef const value_type& reference;
typedef forward_iterator_tag iterator_category;
typedef input_iterator_tag iterator_concept; // since C++20
regex_token_iterator();
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
@@ -6407,6 +6409,9 @@ public:
typedef const value_type* pointer;
typedef const value_type& reference;
typedef forward_iterator_tag iterator_category;
#if _LIBCPP_STD_VER >= 20
typedef input_iterator_tag iterator_concept;
#endif
private:
_BidirectionalIterator __begin_;
@@ -6542,6 +6547,9 @@ public:
typedef const value_type* pointer;
typedef const value_type& reference;
typedef forward_iterator_tag iterator_category;
#if _LIBCPP_STD_VER >= 20
typedef input_iterator_tag iterator_concept;
#endif
private:
typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
+1
View File
@@ -249,6 +249,7 @@ template <class T>
#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__utility/as_const.h>
#include <__utility/as_lvalue.h>
#include <__utility/auto_cast.h>
#include <__utility/cmp.h>
#include <__utility/declval.h>
-2
View File
@@ -204,13 +204,11 @@ export namespace std {
using std::ranges::views::drop_while;
} // namespace views
#ifdef _LIBCPP_ENABLE_EXPERIMENTAL
using std::ranges::join_view;
namespace views {
using std::ranges::views::join;
} // namespace views
#endif // _LIBCPP_ENABLE_EXPERIMENTAL
#if 0
using std::ranges::join_with_view;
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// template<class T>
// constexpr T& as-lvalue(T&& t) { // exposition only
#include <utility>
void test() {
// Check prvalue
{
[[maybe_unused]] auto& check = std::__as_lvalue(
0); // expected-warning {{temporary bound to local reference 'check' will be destroyed at the end of the full-expression}}
}
}
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11
// template<class T>
// constexpr T& as-lvalue(T&& t) { // exposition only
#include <type_traits>
#include <utility>
constexpr bool test() {
// Check glvalue
{
int lvalue{};
[[maybe_unused]] decltype(auto) check = std::__as_lvalue(lvalue);
static_assert(std::is_same<decltype(check), int&>::value, "");
}
// Check xvalue
{
int xvalue{};
[[maybe_unused]] decltype(auto) check = std::__as_lvalue(std::move(xvalue));
static_assert(std::is_same<decltype(check), int&>::value, "");
}
return true;
}
int main(int, char**) {
test();
static_assert(test(), "");
return 0;
}
@@ -0,0 +1,65 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// constexpr iterator(Parent& parent, OuterIter outer)
// requires forward_range<Base>; // exposition only
#include <cassert>
#include <ranges>
#include <string>
#include <utility>
#include "types.h"
constexpr bool test() {
std::string strings[4] = {"aaaa", "bbbb", "cccc", "dddd"};
{ // Check if `outer_` is initialized with `std::move(outer)` for `iterator<false>`
MoveOnAccessSubrange r{DieOnCopyIterator(strings), sentinel_wrapper(strings + 4)};
std::ranges::join_view jv(std::move(r));
auto iter = jv.begin(); // Calls `iterator(Parent& parent, OuterIter outer)`
assert(*iter == 'a');
}
{ // Check if `outer_` is initialized with `std::move(outer)` for `iterator<true>`
MoveOnAccessSubrange r{DieOnCopyIterator(strings), sentinel_wrapper(strings + 4)};
std::ranges::join_view jv(std::ranges::ref_view{r});
auto iter = std::as_const(jv).begin(); // Calls `iterator(Parent& parent, OuterIter outer)`
assert(*iter == 'a');
}
{
// LWG3569 Inner iterator not default_initializable
// With the current spec, the constructor under test invokes Inner iterator's default constructor
// even if it is not default constructible.
// This test is checking that this constructor can be invoked with an inner range with non default
// constructible iterator.
using NonDefaultCtrIter = cpp20_input_iterator<int*>;
static_assert(!std::default_initializable<NonDefaultCtrIter>);
using NonDefaultCtrIterView = BufferView<NonDefaultCtrIter, sentinel_wrapper<NonDefaultCtrIter>>;
static_assert(std::ranges::input_range<NonDefaultCtrIterView>);
int buffer[2][2] = {{1, 2}, {3, 4}};
NonDefaultCtrIterView inners[] = {buffer[0], buffer[1]};
auto outer = std::views::all(inners);
std::ranges::join_view jv(outer);
auto iter = jv.begin(); // Calls `iterator(Parent& parent, OuterIter outer)`
assert(*iter == 1);
}
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}
@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// constexpr explicit iterator(Parent& parent)
// requires (!forward_range<Base>); // exposition only
#include <string>
#include <ranges>
#include "types.h"
constexpr bool test() {
std::string strings[4] = {"eeee", "ffff", "gggg", "hhhh"};
MoveOnAccessSubrange r{
DieOnCopyIterator(cpp20_input_iterator(strings)), sentinel_wrapper(cpp20_input_iterator(strings + 4))};
std::ranges::join_view jv(std::move(r));
auto iter = jv.begin(); // Calls `iterator(Parent& parent)`
assert(*iter == 'e');
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}
@@ -0,0 +1,114 @@
//===----------------------------------------------------------------------===//
//
// 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 TEST_LIBCXX_RANGES_RANGE_ADAPTORS_RANGE_JOIN_RANGE_JOIN_ITERATOR_TYPES_H
#define TEST_LIBCXX_RANGES_RANGE_ADAPTORS_RANGE_JOIN_RANGE_JOIN_ITERATOR_TYPES_H
#include <cassert>
#include <cstddef>
#include <ranges>
#include "test_iterators.h"
template <std::input_iterator Iter>
struct DieOnCopyIterator {
using value_type = std::iter_value_t<Iter>;
using difference_type = std::iter_difference_t<Iter>;
DieOnCopyIterator()
requires std::default_initializable<Iter>
= default;
constexpr explicit DieOnCopyIterator(Iter iter) : iter_(std::move(iter)) {}
constexpr DieOnCopyIterator(DieOnCopyIterator&& other) = default;
DieOnCopyIterator& operator=(DieOnCopyIterator&&) = default;
constexpr DieOnCopyIterator(const DieOnCopyIterator&) { assert(false); }
constexpr DieOnCopyIterator& operator=(const DieOnCopyIterator&) { assert(false); }
constexpr DieOnCopyIterator& operator++() {
++iter_;
return *this;
}
constexpr void operator++(int) { iter_++; }
constexpr DieOnCopyIterator operator++(int)
requires std::forward_iterator<Iter>
{
auto tmp = *this;
++tmp;
return tmp;
}
constexpr decltype(auto) operator*() const { return *iter_; }
friend constexpr bool operator==(const DieOnCopyIterator& left, const DieOnCopyIterator& right)
requires std::equality_comparable<Iter>
{
return left.iter_ == right.iter_;
}
friend constexpr bool operator==(const DieOnCopyIterator& it, const sentinel_wrapper<Iter>& se) {
return it.iter_ == se;
}
private:
Iter iter_ = Iter();
};
template <class Iter>
explicit DieOnCopyIterator(Iter) -> DieOnCopyIterator<Iter>;
static_assert(std::input_iterator<DieOnCopyIterator<cpp20_input_iterator<int*>>>);
static_assert(!std::forward_iterator<DieOnCopyIterator<cpp20_input_iterator<int*>>>);
static_assert(std::forward_iterator<DieOnCopyIterator<int*>>);
static_assert(!std::bidirectional_iterator<DieOnCopyIterator<int*>>);
static_assert(std::sentinel_for<sentinel_wrapper<int*>, DieOnCopyIterator<int*>>);
template <std::input_iterator Iter, std::sentinel_for<Iter> Sent = Iter>
struct MoveOnAccessSubrange : std::ranges::view_base {
constexpr explicit MoveOnAccessSubrange(Iter iter, Sent sent) : iter_(std::move(iter)), sent_(std::move(sent)) {}
MoveOnAccessSubrange(MoveOnAccessSubrange&&) = default;
MoveOnAccessSubrange& operator=(MoveOnAccessSubrange&&) = default;
MoveOnAccessSubrange(const MoveOnAccessSubrange&) = delete;
MoveOnAccessSubrange& operator=(const MoveOnAccessSubrange&) = delete;
constexpr Iter begin() { return std::move(iter_); }
constexpr Sent end() { return std::move(sent_); }
private:
Iter iter_;
Sent sent_;
};
template <class Iter, class Sent>
MoveOnAccessSubrange(Iter, Sent) -> MoveOnAccessSubrange<Iter, Sent>;
static_assert(std::ranges::input_range<MoveOnAccessSubrange<int*, sentinel_wrapper<int*>>>);
static_assert(std::ranges::forward_range<MoveOnAccessSubrange<DieOnCopyIterator<int*>>>);
template <class Iter, class Sent>
requires(!std::same_as<Iter, Sent>)
struct BufferView : std::ranges::view_base {
using T = std::iter_value_t<Iter>;
T* data_;
std::size_t size_;
template <std::size_t N>
constexpr BufferView(T (&b)[N]) : data_(b), size_(N) {}
constexpr Iter begin() const { return Iter(data_); }
constexpr Sent end() const { return Sent(Iter(data_ + size_)); }
};
static_assert(std::ranges::input_range<BufferView<int*, sentinel_wrapper<int*>>>);
#endif // TEST_LIBCXX_RANGES_RANGE_ADAPTORS_RANGE_JOIN_RANGE_JOIN_ITERATOR_TYPES_H
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
#include <ranges>
#include <utility>
@@ -7,8 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// TODO: make `join_view` non-experimental once D2770 is implemented.
// UNSUPPORTED: !c++experimental
#include <algorithm>
#include <array>
@@ -9,8 +9,6 @@
// <algorithm>
// UNSUPPORTED: c++03, c++11, c++14, c++17
// TODO: make `join_view` non-experimental once D2770 is implemented.
// UNSUPPORTED: !c++experimental
// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
// template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
@@ -7,8 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// TODO: make `join_view` non-experimental once D2770 is implemented.
// UNSUPPORTED: !c++experimental
#include <algorithm>
#include <array>
@@ -7,8 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// TODO: make `join_view` non-experimental once D2770 is implemented.
// UNSUPPORTED: !c++experimental
#include <algorithm>
#include <array>
@@ -7,8 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// TODO: make `join_view` non-experimental once D2770 is implemented.
// UNSUPPORTED: !c++experimental
#include <algorithm>
#include <array>
@@ -7,8 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// TODO: make `join_view` non-experimental once D2770 is implemented.
// UNSUPPORTED: !c++experimental
#include <algorithm>
#include <array>
@@ -7,8 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// TODO: make `join_view` non-experimental once D2770 is implemented.
// UNSUPPORTED: !c++experimental
// [customization.point.object]
// [range.adaptor.object] "A range adaptor object is a customization point object..."
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// ADL call with nested iterators of views should not look up base's view's
// namespace
@@ -1,57 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr iterator(Parent& parent, OuterIter outer);
#include <cassert>
#include <ranges>
#include "../types.h"
using NonDefaultCtrIter = cpp20_input_iterator<int*>;
static_assert(!std::default_initializable<NonDefaultCtrIter>);
using NonDefaultCtrIterView = BufferView<NonDefaultCtrIter, sentinel_wrapper<NonDefaultCtrIter>>;
static_assert(std::ranges::input_range<NonDefaultCtrIterView>);
constexpr bool test() {
int buffer[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
{
CopyableChild children[4] = {CopyableChild(buffer[0]), CopyableChild(buffer[1]), CopyableChild(buffer[2]),
CopyableChild(buffer[3])};
CopyableParent parent{children};
std::ranges::join_view jv(parent);
std::ranges::iterator_t<decltype(jv)> iter(jv, std::ranges::begin(parent));
assert(*iter == 1);
}
{
// LWG3569 Inner iterator not default_initializable
// With the current spec, the constructor under test invokes Inner iterator's default constructor
// even if it is not default constructible
// This test is checking that this constructor can be invoked with an inner range with non default
// constructible iterator
NonDefaultCtrIterView inners[] = {buffer[0], buffer[1]};
auto outer = std::views::all(inners);
std::ranges::join_view jv(outer);
std::ranges::iterator_t<decltype(jv)> iter(jv, std::ranges::begin(outer));
assert(*iter == 1);
}
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// std::views::join
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr V base() const& requires copy_constructible<V>;
// constexpr V base() &&;
@@ -7,15 +7,17 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr auto begin();
// constexpr auto begin() const
// requires input_range<const V> &&
// is_reference_v<range_reference_t<const V>>;
// requires forward_range<const V> &&
// is_reference_v<range_reference_t<const V>> &&
// input_range<range_reference_t<const V>>;
#include <algorithm>
#include <cassert>
#include <ranges>
#include <string_view>
#include "types.h"
@@ -120,7 +122,7 @@ constexpr bool test() {
static_assert(HasConstBegin<decltype(jv)>);
}
// !input_range<const V>
// !forward_range<const V>
{
std::ranges::join_view jv{ConstNotRange{}};
static_assert(!HasConstBegin<decltype(jv)>);
@@ -146,6 +148,27 @@ constexpr bool test() {
static_assert(std::same_as<decltype(jv.begin()), decltype(std::as_const(jv).begin())>);
}
// Check stashing iterators (LWG3698: regex_iterator and join_view don't work together very well)
{
std::ranges::join_view<StashingRange> jv;
assert(std::ranges::equal(std::views::counted(jv.begin(), 10), std::string_view{"aababcabcd"}));
}
// LWG3700: The `const begin` of the `join_view` family does not require `InnerRng` to be a range
{
std::ranges::join_view<ConstNonJoinableRange> jv;
static_assert(!HasConstBegin<decltype(jv)>);
}
// Check example from LWG3700
{
auto r = std::views::iota(0, 5) | std::views::split(1);
auto s = std::views::single(r);
auto j = s | std::views::join;
auto f = j.front();
assert(std::ranges::equal(f, std::views::single(0)));
}
return true;
}
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// template<class R>
// explicit join_view(R&&) -> join_view<views::all_t<R>>;
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// template<class R>
// explicit join_view(R&&) -> join_view<views::all_t<R>>;
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// join_view() requires default_initializable<V> = default;
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr explicit join_view(V base);
@@ -7,10 +7,12 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr auto end();
// constexpr auto end() const;
// requires forward_range<const V> &&
// is_reference_v<range_reference_t<const V>> &&
// input_range<range_reference_t<const V>>
#include <cassert>
#include <ranges>
@@ -33,13 +35,13 @@ concept HasConstEnd = requires (const T& t){
// | 3 | Y | Y | Y | Y | N | Y |sentinel<true> |sentinel<true>|
// | 4 | Y | Y | Y | N | Y | Y |sentinel<true> | - |
// | 5 | Y | Y | N | Y | Y | Y |sentinel<true> |sentinel<true>|
// | 6 | Y | N | Y | Y | Y | Y |sentinel<true> |sentinel<true>|
// | 6 | Y | N | Y | Y | Y | Y |sentinel<true> | - |
// | 7 | N | Y | Y | Y | Y | Y |iterator<false>|iterator<true>|
// | 8 | N | Y | Y | Y | Y | N |sentinel<false>|sentinel<true>|
// | 9 | N | Y | Y | Y | N | Y |sentinel<false>|sentinel<true>|
// | 10 | N | Y | Y | N | Y | Y |sentinel<false>| - |
// | 11 | N | Y | N | Y | Y | Y |sentinel<false>|sentinel<true>|
// | 12 | N | N | Y | Y | Y | Y |sentinel<false>|sentinel<true>|
// | 12 | N | N | Y | Y | Y | Y |sentinel<false>| - |
//
//
@@ -131,10 +133,8 @@ constexpr bool test() {
std::ranges::join_view jv(outer);
assert(jv.end() == std::ranges::next(jv.begin(), 16));
assert(std::as_const(jv).end() == std::ranges::next(std::as_const(jv).begin(), 16));
static_assert(HasConstEnd<decltype(jv)>);
static_assert(std::same_as<decltype(jv.end()), decltype(std::as_const(jv).end())>);
static_assert(!HasConstEnd<decltype(jv)>);
static_assert(!std::ranges::common_range<decltype(jv)>);
static_assert(!std::ranges::common_range<const decltype(jv)>);
}
@@ -219,10 +219,8 @@ constexpr bool test() {
std::ranges::join_view jv(outer);
assert(jv.end() == std::ranges::next(jv.begin(), 16));
assert(std::as_const(jv).end() == std::ranges::next(std::as_const(jv).begin(), 16));
static_assert(HasConstEnd<decltype(jv)>);
static_assert(!std::same_as<decltype(jv.end()), decltype(std::as_const(jv).end())>);
static_assert(!HasConstEnd<decltype(jv)>);
static_assert(!std::ranges::common_range<decltype(jv)>);
static_assert(!std::ranges::common_range<const decltype(jv)>);
}
@@ -288,6 +286,12 @@ constexpr bool test() {
assert(jv.end() == std::ranges::next(jv.begin(), 12));
}
// LWG3700: The `const begin` of the `join_view` family does not require `InnerRng` to be a range
{
std::ranges::join_view<ConstNonJoinableRange> jv;
static_assert(!HasConstEnd<decltype(jv)>);
}
return true;
}
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// General tests for join_view. This file does not test anything specifically.
@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: no-localization
// Check LWG-3698: `regex_iterator` and `join_view` don't work together very well
#include <algorithm>
#include <array>
#include <cassert>
#include <ranges>
#include <regex>
#include <string_view>
int main(int, char**) {
char const text[] = "Hello";
std::regex regex{"[a-z]"};
auto lower =
std::ranges::subrange(
std::cregex_iterator(std::ranges::begin(text), std::ranges::end(text), regex), std::cregex_iterator{}) |
std::views::join | std::views::transform([](auto const& sm) { return std::string_view(sm.first, sm.second); });
assert(std::ranges::equal(lower, std::to_array<std::string_view>({"e", "l", "l", "o"})));
return 0;
}
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr InnerIter operator->() const
// requires has-arrow<InnerIter> && copyable<InnerIter>;
@@ -7,9 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// iterator() requires default_initializable<OuterIter> = default;
// iterator() = default;
#include <ranges>
@@ -29,19 +28,12 @@ constexpr void test_default_constructible() {
using JoinView = std::ranges::join_view<view<It>>;
using JoinIterator = std::ranges::iterator_t<JoinView>;
static_assert(std::is_default_constructible_v<JoinIterator>);
JoinIterator it; (void)it;
}
template <class It>
constexpr void test_non_default_constructible() {
using JoinView = std::ranges::join_view<view<It>>;
using JoinIterator = std::ranges::iterator_t<JoinView>;
static_assert(!std::is_default_constructible_v<JoinIterator>);
[[maybe_unused]] JoinIterator it;
}
constexpr bool test() {
test_non_default_constructible<cpp17_input_iterator<ChildView*>>();
// NOTE: cpp20_input_iterator can't be used with join_view because it is not copyable.
test_default_constructible<cpp17_input_iterator<ChildView*>>();
test_default_constructible<cpp20_input_iterator<ChildView*>>();
test_default_constructible<forward_iterator<ChildView*>>();
test_default_constructible<bidirectional_iterator<ChildView*>>();
test_default_constructible<random_access_iterator<ChildView*>>();
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr iterator(iterator<!Const> i)
// requires Const &&
@@ -37,7 +36,7 @@ constexpr bool test() {
{
CopyableChild children[4] = {CopyableChild(buffer[0]), CopyableChild(buffer[1]), CopyableChild(buffer[2]),
CopyableChild(buffer[3])};
std::ranges::join_view jv(CopyableParent{children});
std::ranges::join_view jv(ForwardCopyableParent{children});
auto iter1 = jv.begin();
using iterator = decltype(iter1);
using const_iterator = decltype(std::as_const(jv).begin());
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr iterator& operator--();
// requires ref-is-glvalue && bidirectional_range<Base> &&
@@ -18,9 +17,12 @@
// bidirectional_range<range_reference_t<Base>> &&
// common_range<range_reference_t<Base>>;
#include <algorithm>
#include <array>
#include <cassert>
#include <ranges>
#include <type_traits>
#include <vector>
#include "../types.h"
@@ -150,6 +152,15 @@ constexpr bool test() {
static_assert(!CanPostDecrement<decltype(iter)>);
}
{
// LWG3791: `join_view::iterator::operator--` may be ill-formed
std::vector<std::vector<int>> vec = {{1, 2}, {3, 4}, {5, 6}};
auto r = vec | std::views::transform([](auto& x) -> auto&& { return std::move(x); }) | std::views::join;
auto e = --r.end();
assert(*e == 6);
assert(std::ranges::equal(std::views::reverse(r), std::array{6, 5, 4, 3, 2, 1}));
}
return true;
}
@@ -7,10 +7,9 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// friend constexpr bool operator==(const iterator& x, const iterator& y);
// requires ref-is-glvalue && equality_comparable<iterator_t<Base>> &&
// requires ref-is-glvalue && forward_range<Base> &&
// equality_comparable<iterator_t<range_reference_t<Base>>>;
#include <cassert>
@@ -43,7 +42,7 @@ constexpr bool test() {
}
{
// !equality_comparable<iterator_t<Base>>
// !forward_range<Base>
using Inner = BufferView<int*>;
using Outer = BufferView<cpp20_input_iterator<Inner*>, sentinel_wrapper<cpp20_input_iterator<Inner*>>>;
static_assert(!std::equality_comparable<std::ranges::iterator_t<Outer>>);
@@ -51,8 +50,6 @@ constexpr bool test() {
std::ranges::join_view jv(Outer{inners});
auto iter = jv.begin();
static_assert(!std::equality_comparable<decltype(iter)>);
auto const_iter = std::as_const(jv).begin();
static_assert(!std::equality_comparable<decltype(const_iter)>);
}
{
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr iterator& operator++();
// constexpr void operator++(int);
@@ -205,6 +204,23 @@ constexpr bool test() {
static_assert(std::is_void_v<decltype(iter++)>);
}
{
// Check stashing iterators (LWG3698: regex_iterator and join_view don't work together very well)
std::ranges::join_view<StashingRange> jv;
auto it = jv.begin();
assert(*it == 'a');
++it;
assert(*it == 'a');
++it;
assert(*it == 'b');
it++;
assert(*it == 'a');
it++;
assert(*it == 'b');
++it;
assert(*it == 'c');
}
return true;
}
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// friend constexpr decltype(auto) iter_move(const iterator& i);
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// friend constexpr void iter_swap(const iterator& x, const iterator& y);
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// Iterator traits and member typedefs in join_view::<iterator>.
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr decltype(auto) operator*() const;
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// sentinel() = default;
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr sentinel(sentinel<!Const> s);
// requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>;
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// constexpr explicit sentinel(Parent& parent);
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: !c++experimental
// template<bool OtherConst>
// requires sentinel_for<sentinel_t<Base>, iterator_t<maybe-const<OtherConst, V>>>
@@ -17,6 +16,7 @@
#include <concepts>
#include <functional>
#include <ranges>
#include <type_traits>
#include "../types.h"
@@ -61,18 +61,27 @@ static_assert(EqualityComparable<std::ranges::iterator_t<const ConstComparableVi
constexpr bool test() {
int buffer[4][4] = {{1111, 2222, 3333, 4444}, {555, 666, 777, 888}, {99, 1010, 1111, 1212}, {13, 14, 15, 16}};
// test iterator<false> == sentinel<false>
{
ChildView children[4] = {ChildView(buffer[0]), ChildView(buffer[1]), ChildView(buffer[2]), ChildView(buffer[3])};
auto jv = std::ranges::join_view(ParentView(children));
auto jv = std::ranges::join_view(ParentView(children));
assert(jv.end() == std::ranges::next(jv.begin(), 16));
static_assert(!EqualityComparable<decltype(std::as_const(jv).begin()), decltype(jv.end())>);
static_assert(!EqualityComparable<decltype(jv.begin()), decltype(std::as_const(jv).end())>);
}
// test iterator<false> == sentinel<true>
{
ChildView children[4] = {ChildView(buffer[0]), ChildView(buffer[1]), ChildView(buffer[2]), ChildView(buffer[3])};
using ParentT = std::remove_all_extents_t<decltype(children)>;
auto jv = std::ranges::join_view(ForwardParentView<ParentT>(children));
assert(std::as_const(jv).end() == std::ranges::next(jv.begin(), 16));
}
// test iterator<true> == sentinel<true>
{
CopyableChild children[4] = {CopyableChild(buffer[0]), CopyableChild(buffer[1]), CopyableChild(buffer[2]),
CopyableChild(buffer[3])};
const auto jv = std::ranges::join_view(ParentView(children));
using ParentT = std::remove_all_extents_t<decltype(children)>;
const auto jv = std::ranges::join_view(ForwardParentView<ParentT>(children));
assert(jv.end() == std::ranges::next(jv.begin(), 16));
}
@@ -11,6 +11,7 @@
#include <concepts>
#include <cstdint>
#include <string>
#include <tuple>
#include "test_macros.h"
@@ -52,13 +53,13 @@ inline ChildView globalChildren[4] = {
ChildView(globalBuffer[3]),
};
template <class T>
template <class T, template<class...> class Iter = cpp17_input_iterator>
struct ParentView : std::ranges::view_base {
T* ptr_;
unsigned size_;
using iterator = cpp20_input_iterator<T*>;
using const_iterator = cpp20_input_iterator<const T*>;
using iterator = Iter<T*>;
using const_iterator = Iter<const T*>;
using sentinel = sentinel_wrapper<iterator>;
using const_sentinel = sentinel_wrapper<const_iterator>;
@@ -80,6 +81,9 @@ struct ParentView : std::ranges::view_base {
template <class T>
ParentView(T*) -> ParentView<T>;
template<class T>
using ForwardParentView = ParentView<T, forward_iterator>;
struct CopyableChild : std::ranges::view_base {
int* ptr_;
unsigned size_;
@@ -97,15 +101,16 @@ struct CopyableChild : std::ranges::view_base {
constexpr const_sentinel end() const { return const_sentinel(const_iterator(ptr_ + size_)); }
};
struct CopyableParent : std::ranges::view_base {
template<template<class...> class Iter>
struct CopyableParentTemplate : std::ranges::view_base {
CopyableChild* ptr_;
using iterator = cpp17_input_iterator<CopyableChild*>;
using const_iterator = cpp17_input_iterator<const CopyableChild*>;
using iterator = Iter<CopyableChild*>;
using const_iterator = Iter<const CopyableChild*>;
using sentinel = sentinel_wrapper<iterator>;
using const_sentinel = sentinel_wrapper<const_iterator>;
constexpr CopyableParent(CopyableChild* ptr) : ptr_(ptr) {}
constexpr CopyableParentTemplate(CopyableChild* ptr) : ptr_(ptr) {}
constexpr iterator begin() { return iterator(ptr_); }
constexpr const_iterator begin() const { return const_iterator(ptr_); }
@@ -113,6 +118,9 @@ struct CopyableParent : std::ranges::view_base {
constexpr const_sentinel end() const { return const_sentinel(const_iterator(ptr_ + 4)); }
};
using CopyableParent = CopyableParentTemplate<cpp17_input_iterator>;
using ForwardCopyableParent = CopyableParentTemplate<forward_iterator>;
struct Box {
int x;
};
@@ -392,4 +400,48 @@ struct IterMoveSwapAwareView : BufferView<int*> {
};
static_assert(std::ranges::input_range<IterMoveSwapAwareView>);
class StashingIterator {
public:
using difference_type = std::ptrdiff_t;
using value_type = std::string;
constexpr StashingIterator() : letter_('a') {}
constexpr StashingIterator& operator++() {
str_ += letter_;
++letter_;
return *this;
}
constexpr void operator++(int) { ++*this; }
constexpr value_type operator*() const { return str_; }
constexpr bool operator==(std::default_sentinel_t) const { return letter_ > 'z'; }
private:
char letter_;
value_type str_;
};
using StashingRange = std::ranges::subrange<StashingIterator, std::default_sentinel_t>;
static_assert(std::ranges::input_range<StashingRange>);
static_assert(!std::ranges::forward_range<StashingRange>);
class ConstNonJoinableRange : public std::ranges::view_base {
public:
constexpr StashingIterator begin() { return {}; }
constexpr std::default_sentinel_t end() { return {}; }
constexpr const int* begin() const { return &val_; }
constexpr const int* end() const { return &val_ + 1; }
private:
int val_ = 1;
};
static_assert(std::ranges::input_range<ConstNonJoinableRange>);
static_assert(std::ranges::input_range<const ConstNonJoinableRange>);
static_assert(std::ranges::input_range<std::ranges::range_reference_t<ConstNonJoinableRange>>);
static_assert(!std::ranges::input_range<std::ranges::range_reference_t<const ConstNonJoinableRange>>);
#endif // TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_JOIN_TYPES_H
@@ -14,8 +14,8 @@
#include <iterator>
static_assert(std::forward_iterator<std::cregex_iterator>);
static_assert(!std::bidirectional_iterator<std::cregex_iterator>);
static_assert(std::input_iterator<std::cregex_iterator>);
static_assert(!std::forward_iterator<std::cregex_iterator>);
static_assert(!std::indirectly_writable<std::cregex_iterator, char>);
static_assert(std::sentinel_for<std::cregex_iterator, std::cregex_iterator>);
static_assert(!std::sized_sentinel_for<std::cregex_iterator, std::cregex_iterator>);
@@ -20,6 +20,7 @@
// typedef const value_type* pointer;
// typedef const value_type& reference;
// typedef forward_iterator_tag iterator_category;
// typedef input_iterator_tag iterator_concept; // since C++20
#include <regex>
#include <type_traits>
@@ -36,6 +37,9 @@ test()
static_assert((std::is_same<typename I::pointer, const std::match_results<const CharT*>*>::value), "");
static_assert((std::is_same<typename I::reference, const std::match_results<const CharT*>&>::value), "");
static_assert((std::is_same<typename I::iterator_category, std::forward_iterator_tag>::value), "");
#if TEST_STD_VER >= 20
static_assert(std::is_same_v<typename I::iterator_concept, std::input_iterator_tag>);
#endif
}
int main(int, char**)
@@ -14,8 +14,8 @@
#include <iterator>
static_assert(std::forward_iterator<std::cregex_token_iterator>);
static_assert(!std::bidirectional_iterator<std::cregex_token_iterator>);
static_assert(std::input_iterator<std::cregex_token_iterator>);
static_assert(!std::forward_iterator<std::cregex_token_iterator>);
static_assert(!std::indirectly_writable<std::cregex_token_iterator, char>);
static_assert(std::sentinel_for<std::cregex_token_iterator, std::cregex_token_iterator>);
static_assert(!std::sized_sentinel_for<std::cregex_token_iterator, std::cregex_token_iterator>);
@@ -20,6 +20,7 @@
// typedef const value_type* pointer;
// typedef const value_type& reference;
// typedef forward_iterator_tag iterator_category;
// typedef input_iterator_tag iterator_concept; // since C++20
#include <regex>
#include <type_traits>
@@ -36,6 +37,9 @@ test()
static_assert((std::is_same<typename I::pointer, const std::sub_match<const CharT*>*>::value), "");
static_assert((std::is_same<typename I::reference, const std::sub_match<const CharT*>&>::value), "");
static_assert((std::is_same<typename I::iterator_category, std::forward_iterator_tag>::value), "");
#if TEST_STD_VER >= 20
static_assert(std::is_same_v<typename I::iterator_concept, std::input_iterator_tag>);
#endif
}
int main(int, char**)