160 changes: 160 additions & 0 deletions libcxx/test/std/ranges/range.adaptors/range.common.view/begin.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
//===----------------------------------------------------------------------===//
//
// 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: libcpp-no-concepts
// UNSUPPORTED: gcc-10

// constexpr auto begin();
// constexpr auto begin() const requires range<const V>;

#include <ranges>
#include <cassert>

#include "test_macros.h"
#include "test_iterators.h"
#include "test_range.h"

struct ContiguousView : std::ranges::view_base {
int *ptr_;
constexpr ContiguousView(int* ptr) : ptr_(ptr) {}
constexpr ContiguousView(ContiguousView&&) = default;
constexpr ContiguousView& operator=(ContiguousView&&) = default;
friend constexpr int* begin(ContiguousView& view) { return view.ptr_; }
friend constexpr int* begin(ContiguousView const& view) { return view.ptr_; }
friend constexpr sentinel_wrapper<int*> end(ContiguousView& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
friend constexpr sentinel_wrapper<int*> end(ContiguousView const& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
};

struct CopyableView : std::ranges::view_base {
int *ptr_;
constexpr CopyableView(int* ptr) : ptr_(ptr) {}
friend constexpr int* begin(CopyableView& view) { return view.ptr_; }
friend constexpr int* begin(CopyableView const& view) { return view.ptr_; }
friend constexpr sentinel_wrapper<int*> end(CopyableView& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
friend constexpr sentinel_wrapper<int*> end(CopyableView const& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
};

struct MutableView : std::ranges::view_base {
int *ptr_;
constexpr MutableView(int* ptr) : ptr_(ptr) {}
constexpr int* begin() { return ptr_; }
constexpr sentinel_wrapper<int*> end() { return sentinel_wrapper<int*>{ptr_ + 8}; }
};

using ForwardIter = forward_iterator<int*>;
struct SizedForwardView : std::ranges::view_base {
int *ptr_;
constexpr SizedForwardView(int* ptr) : ptr_(ptr) {}
friend constexpr ForwardIter begin(SizedForwardView& view) { return ForwardIter(view.ptr_); }
friend constexpr ForwardIter begin(SizedForwardView const& view) { return ForwardIter(view.ptr_); }
friend constexpr sentinel_wrapper<ForwardIter> end(SizedForwardView& view) {
return sentinel_wrapper<ForwardIter>{ForwardIter(view.ptr_ + 8)};
}
friend constexpr sentinel_wrapper<ForwardIter> end(SizedForwardView const& view) {
return sentinel_wrapper<ForwardIter>{ForwardIter(view.ptr_ + 8)};
}
};
// Required to make SizedForwardView a sized view.
constexpr auto operator-(sentinel_wrapper<ForwardIter> sent, ForwardIter iter) {
return sent.base().base() - iter.base();
}
constexpr auto operator-(ForwardIter iter, sentinel_wrapper<ForwardIter> sent) {
return iter.base() - sent.base().base();
}

using RandomAccessIter = random_access_iterator<int*>;
struct SizedRandomAccessView : std::ranges::view_base {
int *ptr_;
constexpr SizedRandomAccessView(int* ptr) : ptr_(ptr) {}
friend constexpr RandomAccessIter begin(SizedRandomAccessView& view) { return RandomAccessIter(view.ptr_); }
friend constexpr RandomAccessIter begin(SizedRandomAccessView const& view) { return RandomAccessIter(view.ptr_); }
friend constexpr sentinel_wrapper<RandomAccessIter> end(SizedRandomAccessView& view) {
return sentinel_wrapper<RandomAccessIter>{RandomAccessIter(view.ptr_ + 8)};
}
friend constexpr sentinel_wrapper<RandomAccessIter> end(SizedRandomAccessView const& view) {
return sentinel_wrapper<RandomAccessIter>{RandomAccessIter(view.ptr_ + 8)};
}
};
// Required to make SizedRandomAccessView a sized view.
constexpr auto operator-(sentinel_wrapper<RandomAccessIter> sent, RandomAccessIter iter) {
return sent.base().base() - iter.base();
}
constexpr auto operator-(RandomAccessIter iter, sentinel_wrapper<RandomAccessIter> sent) {
return iter.base() - sent.base().base();
}

template<class T>
concept BeginEnabled = requires(const std::ranges::common_view<T>& comm) {
comm.begin();
};

constexpr bool test() {
int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};

{
static_assert( BeginEnabled<CopyableView>);
static_assert(!BeginEnabled<MutableView>);
}

{
std::ranges::common_view<SizedRandomAccessView> comm(SizedRandomAccessView{buffer});
assert(comm.begin() == begin(SizedRandomAccessView(buffer)));
ASSERT_SAME_TYPE(decltype(comm.begin()), RandomAccessIter);
}

{
const std::ranges::common_view<SizedRandomAccessView> comm(SizedRandomAccessView{buffer});
assert(comm.begin() == begin(SizedRandomAccessView(buffer)));
ASSERT_SAME_TYPE(decltype(comm.begin()), RandomAccessIter);
}

return true;
}

int main(int, char**) {
test();
static_assert(test());

// The non-constexpr tests:
int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};

{
std::ranges::common_view<SizedForwardView> comm(SizedForwardView{buffer});
assert(comm.begin() == begin(SizedForwardView(buffer)));
ASSERT_SAME_TYPE(decltype(comm.begin()), std::common_iterator<ForwardIter, sentinel_wrapper<ForwardIter>>);
}

{
std::ranges::common_view<ContiguousView> comm(ContiguousView{buffer});
assert(comm.begin() == begin(ContiguousView(buffer)));
ASSERT_SAME_TYPE(decltype(comm.begin()), std::common_iterator<int*, sentinel_wrapper<int*>>);
}

{
const std::ranges::common_view<SizedForwardView> comm(SizedForwardView{buffer});
assert(comm.begin() == begin(SizedForwardView(buffer)));
ASSERT_SAME_TYPE(decltype(comm.begin()), std::common_iterator<ForwardIter, sentinel_wrapper<ForwardIter>>);
}

{
const std::ranges::common_view<CopyableView> comm(CopyableView{buffer});
assert(comm.begin() == begin(CopyableView(buffer)));
ASSERT_SAME_TYPE(decltype(comm.begin()), std::common_iterator<int*, sentinel_wrapper<int*>>);
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// 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: libcpp-no-concepts
// UNSUPPORTED: gcc-10

// template<class T>
// inline constexpr bool enable_borrowed_range<common_view<T>> = enable_borrowed_range<T>;

#include <ranges>
#include <cassert>

#include "test_iterators.h"

struct View : std::ranges::view_base {
friend int* begin(View&);
friend int* begin(View const&);
friend sentinel_wrapper<int*> end(View&);
friend sentinel_wrapper<int*> end(View const&);
};

struct BorrowableView : std::ranges::view_base {
friend int* begin(BorrowableView&);
friend int* begin(BorrowableView const&);
friend sentinel_wrapper<int*> end(BorrowableView&);
friend sentinel_wrapper<int*> end(BorrowableView const&);
};

template<>
inline constexpr bool std::ranges::enable_borrowed_range<BorrowableView> = true;

static_assert(!std::ranges::enable_borrowed_range<std::ranges::common_view<View>>);
static_assert( std::ranges::enable_borrowed_range<std::ranges::common_view<BorrowableView>>);
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// 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: libcpp-no-concepts
// UNSUPPORTED: gcc-10

// template<class R>
// common_view(R&&) -> common_view<views::all_t<R>>;

#include <ranges>
#include <cassert>

#include "test_iterators.h"

struct View : std::ranges::view_base {
friend int* begin(View&);
friend int* begin(View const&);
friend sentinel_wrapper<int*> end(View&);
friend sentinel_wrapper<int*> end(View const&);
};

struct Range {
friend int* begin(Range&);
friend int* begin(Range const&);
friend sentinel_wrapper<int*> end(Range&);
friend sentinel_wrapper<int*> end(Range const&);
};

struct BorrowedRange {
friend int* begin(BorrowedRange&);
friend int* begin(BorrowedRange const&);
friend sentinel_wrapper<int*> end(BorrowedRange&);
friend sentinel_wrapper<int*> end(BorrowedRange const&);
};

template<>
inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true;

void testCTAD() {
View v;
Range r;
BorrowedRange br;
static_assert(std::same_as<
decltype(std::ranges::common_view(v)),
std::ranges::common_view<View>
>);
static_assert(std::same_as<
decltype(std::ranges::common_view(r)),
std::ranges::common_view<std::ranges::ref_view<Range>>
>);
// std::ranges::common_view(std::move(r)) invalid. RValue range must be borrowed.
static_assert(std::same_as<
decltype(std::ranges::common_view(br)),
std::ranges::common_view<std::ranges::ref_view<BorrowedRange>>
>);
static_assert(std::same_as<
decltype(std::ranges::common_view(std::move(br))),
std::ranges::common_view<std::ranges::subrange<
int *, sentinel_wrapper<int *>, std::ranges::subrange_kind::unsized>>
>);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// 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: libcpp-no-concepts
// UNSUPPORTED: gcc-10

// common_view() requires default_initializable<V> = default;

#include <ranges>
#include <cassert>

#include "test_iterators.h"
#include "test_range.h"

int globalBuffer[4] = {1,2,3,4};

struct ContiguousView : std::ranges::view_base {
int *ptr_;
constexpr ContiguousView(int* ptr) : ptr_(ptr) {}
constexpr ContiguousView(ContiguousView&&) = default;
constexpr ContiguousView& operator=(ContiguousView&&) = default;
friend constexpr int* begin(ContiguousView& view) { return view.ptr_; }
friend constexpr int* begin(ContiguousView const& view) { return view.ptr_; }
friend constexpr sentinel_wrapper<int*> end(ContiguousView& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
friend constexpr sentinel_wrapper<int*> end(ContiguousView const& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
};

struct CopyableView : std::ranges::view_base {
int *ptr_;
constexpr CopyableView(int* ptr = globalBuffer) : ptr_(ptr) {}
friend constexpr int* begin(CopyableView& view) { return view.ptr_; }
friend constexpr int* begin(CopyableView const& view) { return view.ptr_; }
friend constexpr sentinel_wrapper<int*> end(CopyableView& view) {
return sentinel_wrapper<int*>{view.ptr_ + 4};
}
friend constexpr sentinel_wrapper<int*> end(CopyableView const& view) {
return sentinel_wrapper<int*>{view.ptr_ + 4};
}
};

struct DefaultConstructibleView : std::ranges::view_base {
DefaultConstructibleView();
friend int* begin(DefaultConstructibleView& view);
friend int* begin(DefaultConstructibleView const& view);
friend sentinel_wrapper<int*> end(DefaultConstructibleView& view);
friend sentinel_wrapper<int*> end(DefaultConstructibleView const& view);
};

int main(int, char**) {
static_assert(!std::default_initializable<std::ranges::common_view<ContiguousView>>);
static_assert( std::default_initializable<std::ranges::common_view<DefaultConstructibleView>>);

std::ranges::common_view<CopyableView> common;
assert(*common.begin() == 1);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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: libcpp-no-concepts
// UNSUPPORTED: gcc-10

// constexpr explicit common_view(V r);

#include <ranges>
#include <cassert>

#include "test_iterators.h"
#include "test_range.h"

struct ContiguousView : std::ranges::view_base {
int *ptr_;
constexpr ContiguousView(int* ptr) : ptr_(ptr) {}
constexpr ContiguousView(ContiguousView&&) = default;
constexpr ContiguousView& operator=(ContiguousView&&) = default;
friend constexpr int* begin(ContiguousView& view) { return view.ptr_; }
friend constexpr int* begin(ContiguousView const& view) { return view.ptr_; }
friend constexpr sentinel_wrapper<int*> end(ContiguousView& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
friend constexpr sentinel_wrapper<int*> end(ContiguousView const& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
};

struct CopyableView : std::ranges::view_base {
int *ptr_;
constexpr CopyableView(int* ptr) : ptr_(ptr) {}
friend constexpr int* begin(CopyableView& view) { return view.ptr_; }
friend constexpr int* begin(CopyableView const& view) { return view.ptr_; }
friend constexpr sentinel_wrapper<int*> end(CopyableView& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
friend constexpr sentinel_wrapper<int*> end(CopyableView const& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
};

constexpr bool test() {
int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};

{
std::ranges::common_view<ContiguousView> common(ContiguousView{buffer});
assert(std::move(common).base().ptr_ == buffer);
}

{
ContiguousView v{buffer};
std::ranges::common_view<ContiguousView> common(std::move(v));
assert(std::move(common).base().ptr_ == buffer);
}

{
const CopyableView v{buffer};
const std::ranges::common_view<CopyableView> common(v);
assert(common.base().ptr_ == buffer);
}

return true;
}

int main(int, char**) {
test();
static_assert(test());

int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
const std::ranges::common_view<ContiguousView> common(ContiguousView{buffer});
assert(common.begin() == buffer);

return 0;
}
132 changes: 132 additions & 0 deletions libcxx/test/std/ranges/range.adaptors/range.common.view/end.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//===----------------------------------------------------------------------===//
//
// 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: libcpp-no-concepts
// UNSUPPORTED: gcc-10

// constexpr auto end();
// constexpr auto end() const requires range<const V>;

#include <ranges>
#include <cassert>

#include "test_macros.h"
#include "test_iterators.h"
#include "test_range.h"

struct CopyableView : std::ranges::view_base {
int *ptr_;
constexpr CopyableView(int* ptr) : ptr_(ptr) {}
friend constexpr int* begin(CopyableView& view) { return view.ptr_; }
friend constexpr int* begin(CopyableView const& view) { return view.ptr_; }
friend constexpr sentinel_wrapper<int*> end(CopyableView& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
friend constexpr sentinel_wrapper<int*> end(CopyableView const& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
};

using ForwardIter = forward_iterator<int*>;
struct SizedForwardView : std::ranges::view_base {
int *ptr_;
constexpr SizedForwardView(int* ptr) : ptr_(ptr) {}
friend constexpr ForwardIter begin(SizedForwardView& view) { return ForwardIter(view.ptr_); }
friend constexpr ForwardIter begin(SizedForwardView const& view) { return ForwardIter(view.ptr_); }
friend constexpr sentinel_wrapper<ForwardIter> end(SizedForwardView& view) {
return sentinel_wrapper<ForwardIter>{ForwardIter(view.ptr_ + 8)};
}
friend constexpr sentinel_wrapper<ForwardIter> end(SizedForwardView const& view) {
return sentinel_wrapper<ForwardIter>{ForwardIter(view.ptr_ + 8)};
}
};

constexpr auto operator-(sentinel_wrapper<ForwardIter> sent, ForwardIter iter) {
return sent.base().base() - iter.base();
}
constexpr auto operator-(ForwardIter iter, sentinel_wrapper<ForwardIter> sent) {
return iter.base() - sent.base().base();
}

using RandomAccessIter = random_access_iterator<int*>;
struct SizedRandomcAccessView : std::ranges::view_base {
int *ptr_;
constexpr SizedRandomcAccessView(int* ptr) : ptr_(ptr) {}
friend constexpr RandomAccessIter begin(SizedRandomcAccessView& view) { return RandomAccessIter(view.ptr_); }
friend constexpr RandomAccessIter begin(SizedRandomcAccessView const& view) { return RandomAccessIter(view.ptr_); }
friend constexpr sentinel_wrapper<RandomAccessIter> end(SizedRandomcAccessView& view) {
return sentinel_wrapper<RandomAccessIter>{RandomAccessIter(view.ptr_ + 8)};
}
friend constexpr sentinel_wrapper<RandomAccessIter> end(SizedRandomcAccessView const& view) {
return sentinel_wrapper<RandomAccessIter>{RandomAccessIter(view.ptr_ + 8)};
}
};

constexpr auto operator-(sentinel_wrapper<RandomAccessIter> sent, RandomAccessIter iter) {
return sent.base().base() - iter.base();
}
constexpr auto operator-(RandomAccessIter iter, sentinel_wrapper<RandomAccessIter> sent) {
return iter.base() - sent.base().base();
}

constexpr bool test() {
int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};

{
std::ranges::common_view<SizedRandomcAccessView> comm(SizedRandomcAccessView{buffer});
assert(comm.end().base() == buffer + 8);
// Note this should NOT be the sentinel type.
ASSERT_SAME_TYPE(decltype(comm.end()), RandomAccessIter);
}

{
const std::ranges::common_view<SizedRandomcAccessView> comm(SizedRandomcAccessView{buffer});
assert(comm.end().base() == buffer + 8);
// Note this should NOT be the sentinel type.
ASSERT_SAME_TYPE(decltype(comm.end()), RandomAccessIter);
}

return true;
}

int main(int, char**) {
test();
static_assert(test());

int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};

using CommonForwardIter = std::common_iterator<ForwardIter, sentinel_wrapper<ForwardIter>>;
using CommonIntIter = std::common_iterator<int*, sentinel_wrapper<int*>>;

{
std::ranges::common_view<SizedForwardView> comm(SizedForwardView{buffer});
assert(comm.end() == CommonForwardIter(sentinel_wrapper<ForwardIter>(ForwardIter(buffer + 8))));
ASSERT_SAME_TYPE(decltype(comm.end()), CommonForwardIter);
}

{
std::ranges::common_view<CopyableView> comm(CopyableView{buffer});
assert(comm.end() == CommonIntIter(sentinel_wrapper<int*>(buffer + 8)));
ASSERT_SAME_TYPE(decltype(comm.end()), CommonIntIter);
}

{
const std::ranges::common_view<SizedForwardView> comm(SizedForwardView{buffer});
assert(comm.end() == CommonForwardIter(sentinel_wrapper<ForwardIter>(ForwardIter(buffer + 8))));
ASSERT_SAME_TYPE(decltype(comm.end()), CommonForwardIter);
}

{
const std::ranges::common_view<CopyableView> comm(CopyableView{buffer});
assert(comm.end() == CommonIntIter(sentinel_wrapper<int*>(buffer + 8)));
ASSERT_SAME_TYPE(decltype(comm.end()), CommonIntIter);
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//===----------------------------------------------------------------------===//
//
// 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: libcpp-no-concepts
// UNSUPPORTED: gcc-10

// constexpr auto size() requires sized_range<V>
// constexpr auto size() const requires sized_range<const V>

#include <ranges>
#include <cassert>

#include "test_iterators.h"
#include "test_range.h"

struct CopyableView : std::ranges::view_base {
int *ptr_;
constexpr CopyableView(int* ptr) : ptr_(ptr) {}
friend constexpr int* begin(CopyableView& view) { return view.ptr_; }
friend constexpr int* begin(CopyableView const& view) { return view.ptr_; }
friend constexpr sentinel_wrapper<int*> end(CopyableView& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
friend constexpr sentinel_wrapper<int*> end(CopyableView const& view) {
return sentinel_wrapper<int*>{view.ptr_ + 8};
}
};

using ForwardIter = forward_iterator<int*>;
struct SizedForwardView : std::ranges::view_base {
int *ptr_;
constexpr SizedForwardView(int* ptr) : ptr_(ptr) {}
friend constexpr ForwardIter begin(SizedForwardView& view) { return ForwardIter(view.ptr_); }
friend constexpr ForwardIter begin(SizedForwardView const& view) { return ForwardIter(view.ptr_); }
friend constexpr sentinel_wrapper<ForwardIter> end(SizedForwardView& view) {
return sentinel_wrapper<ForwardIter>{ForwardIter(view.ptr_ + 8)};
}
friend constexpr sentinel_wrapper<ForwardIter> end(SizedForwardView const& view) {
return sentinel_wrapper<ForwardIter>{ForwardIter(view.ptr_ + 8)};
}
};

constexpr auto operator-(sentinel_wrapper<ForwardIter> sent, ForwardIter iter) {
return sent.base().base() - iter.base();
}
constexpr auto operator-(ForwardIter iter, sentinel_wrapper<ForwardIter> sent) {
return iter.base() - sent.base().base();
}

template<class T>
concept SizeEnabled = requires(const std::ranges::common_view<T>& comm) {
comm.size();
};

constexpr bool test() {
int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};

{
static_assert( SizeEnabled<SizedForwardView>);
static_assert(!SizeEnabled<CopyableView>);
}

{
std::ranges::common_view<SizedForwardView> common(SizedForwardView{buffer});
assert(common.size() == 8);
}

{
const std::ranges::common_view<SizedForwardView> common(SizedForwardView{buffer});
assert(common.size() == 8);
}

return true;
}

int main(int, char**) {
test();
static_assert(test());

return 0;
}
24 changes: 12 additions & 12 deletions libcxx/test/std/ranges/range.adaptors/range.drop/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@ struct ContiguousView : std::ranges::view_base {
constexpr ContiguousView(int start = 0) : start_(start) {}
constexpr ContiguousView(ContiguousView&&) = default;
constexpr ContiguousView& operator=(ContiguousView&&) = default;
constexpr friend int* begin(ContiguousView& view) { return globalBuff + view.start_; }
constexpr friend int* begin(ContiguousView const& view) { return globalBuff + view.start_; }
constexpr friend int* end(ContiguousView&) { return globalBuff + 8; }
constexpr friend int* end(ContiguousView const&) { return globalBuff + 8; }
friend constexpr int* begin(ContiguousView& view) { return globalBuff + view.start_; }
friend constexpr int* begin(ContiguousView const& view) { return globalBuff + view.start_; }
friend constexpr int* end(ContiguousView&) { return globalBuff + 8; }
friend constexpr int* end(ContiguousView const&) { return globalBuff + 8; }
};

struct CopyableView : std::ranges::view_base {
int start_;
constexpr CopyableView(int start = 0) : start_(start) {}
constexpr CopyableView(CopyableView const&) = default;
constexpr CopyableView& operator=(CopyableView const&) = default;
constexpr friend int* begin(CopyableView& view) { return globalBuff + view.start_; }
constexpr friend int* begin(CopyableView const& view) { return globalBuff + view.start_; }
constexpr friend int* end(CopyableView&) { return globalBuff + 8; }
constexpr friend int* end(CopyableView const&) { return globalBuff + 8; }
friend constexpr int* begin(CopyableView& view) { return globalBuff + view.start_; }
friend constexpr int* begin(CopyableView const& view) { return globalBuff + view.start_; }
friend constexpr int* end(CopyableView&) { return globalBuff + 8; }
friend constexpr int* end(CopyableView const&) { return globalBuff + 8; }
};

using ForwardIter = forward_iterator<int*>;
struct ForwardView : std::ranges::view_base {
constexpr ForwardView() = default;
constexpr ForwardView(ForwardView&&) = default;
constexpr ForwardView& operator=(ForwardView&&) = default;
constexpr friend ForwardIter begin(ForwardView&) { return ForwardIter(globalBuff); }
constexpr friend ForwardIter begin(ForwardView const&) { return ForwardIter(globalBuff); }
constexpr friend ForwardIter end(ForwardView&) { return ForwardIter(globalBuff + 8); }
constexpr friend ForwardIter end(ForwardView const&) { return ForwardIter(globalBuff + 8); }
friend constexpr ForwardIter begin(ForwardView&) { return ForwardIter(globalBuff); }
friend constexpr ForwardIter begin(ForwardView const&) { return ForwardIter(globalBuff); }
friend constexpr ForwardIter end(ForwardView&) { return ForwardIter(globalBuff + 8); }
friend constexpr ForwardIter end(ForwardView const&) { return ForwardIter(globalBuff + 8); }
};

struct ForwardRange {
Expand Down
24 changes: 12 additions & 12 deletions libcxx/test/std/ranges/range.adaptors/range.transform/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ struct ContiguousView : std::ranges::view_base {
constexpr ContiguousView(int* ptr = globalBuff, int start = 0) : start_(start), ptr_(ptr) {}
constexpr ContiguousView(ContiguousView&&) = default;
constexpr ContiguousView& operator=(ContiguousView&&) = default;
constexpr friend int* begin(ContiguousView& view) { return view.ptr_ + view.start_; }
constexpr friend int* begin(ContiguousView const& view) { return view.ptr_ + view.start_; }
constexpr friend int* end(ContiguousView& view) { return view.ptr_ + 8; }
constexpr friend int* end(ContiguousView const& view) { return view.ptr_ + 8; }
friend constexpr int* begin(ContiguousView& view) { return view.ptr_ + view.start_; }
friend constexpr int* begin(ContiguousView const& view) { return view.ptr_ + view.start_; }
friend constexpr int* end(ContiguousView& view) { return view.ptr_ + 8; }
friend constexpr int* end(ContiguousView const& view) { return view.ptr_ + 8; }
};

struct CopyableView : std::ranges::view_base {
int start_;
constexpr CopyableView(int start = 0) : start_(start) {}
constexpr CopyableView(CopyableView const&) = default;
constexpr CopyableView& operator=(CopyableView const&) = default;
constexpr friend int* begin(CopyableView& view) { return globalBuff + view.start_; }
constexpr friend int* begin(CopyableView const& view) { return globalBuff + view.start_; }
constexpr friend int* end(CopyableView&) { return globalBuff + 8; }
constexpr friend int* end(CopyableView const&) { return globalBuff + 8; }
friend constexpr int* begin(CopyableView& view) { return globalBuff + view.start_; }
friend constexpr int* begin(CopyableView const& view) { return globalBuff + view.start_; }
friend constexpr int* end(CopyableView&) { return globalBuff + 8; }
friend constexpr int* end(CopyableView const&) { return globalBuff + 8; }
};

using ForwardIter = forward_iterator<int*>;
Expand All @@ -39,10 +39,10 @@ struct ForwardView : std::ranges::view_base {
constexpr ForwardView(int* ptr = globalBuff) : ptr_(ptr) {}
constexpr ForwardView(ForwardView&&) = default;
constexpr ForwardView& operator=(ForwardView&&) = default;
constexpr friend ForwardIter begin(ForwardView& view) { return ForwardIter(view.ptr_); }
constexpr friend ForwardIter begin(ForwardView const& view) { return ForwardIter(view.ptr_); }
constexpr friend ForwardIter end(ForwardView& view) { return ForwardIter(view.ptr_ + 8); }
constexpr friend ForwardIter end(ForwardView const& view) { return ForwardIter(view.ptr_ + 8); }
friend constexpr ForwardIter begin(ForwardView& view) { return ForwardIter(view.ptr_); }
friend constexpr ForwardIter begin(ForwardView const& view) { return ForwardIter(view.ptr_); }
friend constexpr ForwardIter end(ForwardView& view) { return ForwardIter(view.ptr_ + 8); }
friend constexpr ForwardIter end(ForwardView const& view) { return ForwardIter(view.ptr_ + 8); }
};

using ForwardRange = test_common_range<forward_iterator>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class X
constexpr X(int i) : i_(i) {}
constexpr X(int i, int j) : i_(i), j_(j) {}

constexpr friend bool operator==(const X& x, const X& y)
friend constexpr bool operator==(const X& x, const X& y)
{return x.i_ == y.i_ && x.j_ == y.j_;}
};

Expand Down
19 changes: 11 additions & 8 deletions libcxx/test/support/test_iterators.h
Original file line number Diff line number Diff line change
Expand Up @@ -848,25 +848,25 @@ class stride_counting_iterator {
return *this;
}

constexpr friend stride_counting_iterator operator+(stride_counting_iterator i, difference_type const n)
friend constexpr stride_counting_iterator operator+(stride_counting_iterator i, difference_type const n)
requires std::random_access_iterator<I>
{
return i += n;
}

constexpr friend stride_counting_iterator operator+(difference_type const n, stride_counting_iterator i)
friend constexpr stride_counting_iterator operator+(difference_type const n, stride_counting_iterator i)
requires std::random_access_iterator<I>
{
return i += n;
}

constexpr friend stride_counting_iterator operator-(stride_counting_iterator i, difference_type const n)
friend constexpr stride_counting_iterator operator-(stride_counting_iterator i, difference_type const n)
requires std::random_access_iterator<I>
{
return i -= n;
}

constexpr friend difference_type operator-(stride_counting_iterator const& x, stride_counting_iterator const& y)
friend constexpr difference_type operator-(stride_counting_iterator const& x, stride_counting_iterator const& y)
requires std::sized_sentinel_for<I, I>
{
return x.base() - y.base();
Expand All @@ -884,25 +884,25 @@ class stride_counting_iterator {
return base_ == last;
}

constexpr friend bool operator<(stride_counting_iterator const& x, stride_counting_iterator const& y)
friend constexpr bool operator<(stride_counting_iterator const& x, stride_counting_iterator const& y)
requires std::random_access_iterator<I>
{
return x.base_ < y.base_;
}

constexpr friend bool operator>(stride_counting_iterator const& x, stride_counting_iterator const& y)
friend constexpr bool operator>(stride_counting_iterator const& x, stride_counting_iterator const& y)
requires std::random_access_iterator<I>
{
return y < x;
}

constexpr friend bool operator<=(stride_counting_iterator const& x, stride_counting_iterator const& y)
friend constexpr bool operator<=(stride_counting_iterator const& x, stride_counting_iterator const& y)
requires std::random_access_iterator<I>
{
return !(y < x);
}

constexpr friend bool operator>=(stride_counting_iterator const& x, stride_counting_iterator const& y)
friend constexpr bool operator>=(stride_counting_iterator const& x, stride_counting_iterator const& y)
requires std::random_access_iterator<I>
{
return !(x < y);
Expand All @@ -924,6 +924,9 @@ class sentinel_wrapper {
return base_ == other;
}

constexpr const I& base() const& { return base_; }
constexpr I base() && { return std::move(base_); }

private:
I base_ = I();
};
Expand Down
14 changes: 7 additions & 7 deletions libcxx/test/support/type_classification/swappable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class lvalue_adl_swappable {
return *this;
}

constexpr friend void swap(lvalue_adl_swappable& x,
friend constexpr void swap(lvalue_adl_swappable& x,
lvalue_adl_swappable& y) noexcept {
std::ranges::swap(x.value_, y.value_);
}
Expand Down Expand Up @@ -70,7 +70,7 @@ class lvalue_rvalue_adl_swappable {
return *this;
}

constexpr friend void swap(lvalue_rvalue_adl_swappable& x,
friend constexpr void swap(lvalue_rvalue_adl_swappable& x,
lvalue_rvalue_adl_swappable&& y) noexcept {
std::ranges::swap(x.value_, y.value_);
}
Expand Down Expand Up @@ -107,7 +107,7 @@ class rvalue_lvalue_adl_swappable {
return *this;
}

constexpr friend void swap(rvalue_lvalue_adl_swappable&& x,
friend constexpr void swap(rvalue_lvalue_adl_swappable&& x,
rvalue_lvalue_adl_swappable& y) noexcept {
std::ranges::swap(x.value_, y.value_);
}
Expand Down Expand Up @@ -142,7 +142,7 @@ class rvalue_adl_swappable {
return *this;
}

constexpr friend void swap(rvalue_adl_swappable&& x,
friend constexpr void swap(rvalue_adl_swappable&& x,
rvalue_adl_swappable&& y) noexcept {
std::ranges::swap(x.value_, y.value_);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ class non_move_constructible_adl_swappable {
return *this;
}

constexpr friend void swap(non_move_constructible_adl_swappable& x,
friend constexpr void swap(non_move_constructible_adl_swappable& x,
non_move_constructible_adl_swappable& y) noexcept {
std::ranges::swap(x.value_, y.value_);
}
Expand Down Expand Up @@ -212,7 +212,7 @@ class non_move_assignable_adl_swappable {
constexpr non_move_assignable_adl_swappable&
operator=(non_move_assignable_adl_swappable&& other) noexcept = delete;

constexpr friend void swap(non_move_assignable_adl_swappable& x,
friend constexpr void swap(non_move_assignable_adl_swappable& x,
non_move_assignable_adl_swappable& y) noexcept {
std::ranges::swap(x.value_, y.value_);
}
Expand Down Expand Up @@ -248,7 +248,7 @@ class throwable_adl_swappable {
return *this;
}

constexpr friend void swap(throwable_adl_swappable& X,
friend constexpr void swap(throwable_adl_swappable& X,
throwable_adl_swappable& Y) noexcept(false) {
std::ranges::swap(X.value_, Y.value_);
}
Expand Down