Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1807a42
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde May 8, 2024
e14469b
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde May 8, 2024
85ca069
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde May 8, 2024
b031c38
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde May 8, 2024
32b68f2
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde May 8, 2024
8e35609
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde May 8, 2024
162ce8a
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde May 8, 2024
9dd983d
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde May 8, 2024
8291917
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde May 14, 2024
30a1e6e
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Jul 28, 2024
b741665
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Jul 28, 2024
1c4122f
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 8, 2024
07a62fe
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 8, 2024
74bd185
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 8, 2024
5e37e03
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 8, 2024
cd3b4cd
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 8, 2024
bfb0e25
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 8, 2024
aacbc6b
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 8, 2024
ffc9700
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 8, 2024
4c72a3a
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 9, 2024
c2df436
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 9, 2024
5884764
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 9, 2024
752d590
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 9, 2024
93c65aa
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 13, 2024
b564478
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 18, 2024
94b9c2c
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 18, 2024
06f28a1
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Aug 28, 2024
89a36ef
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Oct 8, 2024
68a3e3f
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Oct 17, 2024
ea82cce
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Oct 17, 2024
03ccc54
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Nov 10, 2024
5ca6002
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Nov 10, 2024
2e11e43
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Nov 10, 2024
f717f55
[libc++][ranges] implement 'ranges::elements_of'
xiaoyang-sde Dec 1, 2024
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
1 change: 1 addition & 0 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ set(files
__ranges/data.h
__ranges/drop_view.h
__ranges/drop_while_view.h
__ranges/elements_of.h
__ranges/elements_view.h
__ranges/empty.h
__ranges/empty_view.h
Expand Down
49 changes: 49 additions & 0 deletions libcxx/include/__ranges/elements_of.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// -*- 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_ELEMENTS_OF_H
#define _LIBCPP___RANGES_ELEMENTS_OF_H

#include <__config>
#include <__memory/allocator.h>
#include <__ranges/concepts.h>
#include <__utility/forward.h>
#include <cstddef>

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

_LIBCPP_PUSH_MACROS
#include <__undef_macros>

_LIBCPP_BEGIN_NAMESPACE_STD

#if _LIBCPP_STD_VER >= 23

namespace ranges {

template <range _Range, class _Allocator = allocator<byte>>
struct elements_of {
_LIBCPP_NO_UNIQUE_ADDRESS _Range range;
_LIBCPP_NO_UNIQUE_ADDRESS _Allocator allocator = _Allocator();
};

template <class _Range, class _Allocator = allocator<byte>>
elements_of(_Range&&, _Allocator = _Allocator()) -> elements_of<_Range&&, _Allocator>;

} // namespace ranges

#endif // _LIBCPP_STD_VER >= 23

_LIBCPP_END_NAMESPACE_STD

_LIBCPP_POP_MACROS

#endif // _LIBCPP___RANGES_ELEMENTS_OF_H
1 change: 1 addition & 0 deletions libcxx/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,7 @@ module std [system] {
header "__ranges/drop_while_view.h"
export std.functional.bind_back
}
module elements_of { header "__ranges/elements_of.h" }
module elements_view { header "__ranges/elements_view.h" }
module empty { header "__ranges/empty.h" }
module empty_view { header "__ranges/empty_view.h" }
Expand Down
5 changes: 5 additions & 0 deletions libcxx/include/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ namespace std::ranges {
// [range.dangling], dangling iterator handling
struct dangling;

// [range.elementsof], class template elements_of
template<range R, class Allocator = allocator<byte>>
struct elements_of;

template<range R>
using borrowed_iterator_t = see below;

Expand Down Expand Up @@ -392,6 +396,7 @@ namespace std {
# include <__ranges/data.h>
# include <__ranges/drop_view.h>
# include <__ranges/drop_while_view.h>
# include <__ranges/elements_of.h>
# include <__ranges/elements_view.h>
# include <__ranges/empty.h>
# include <__ranges/empty_view.h>
Expand Down
4 changes: 3 additions & 1 deletion libcxx/modules/std/ranges.inc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ export namespace std {
// [range.dangling], dangling iterator handling
using std::ranges::dangling;

#if _LIBCPP_STD_VER >= 23
// [range.elementsof], class template elements_­of
// using std::ranges::elements_of;
using std::ranges::elements_of;
#endif

using std::ranges::borrowed_iterator_t;

Expand Down
1 change: 1 addition & 0 deletions libcxx/test/libcxx/transitive_includes/cxx23.csv
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ random version
ranges cctype
ranges compare
ranges concepts
ranges cstddef
ranges cstdint
ranges cstdio
ranges cstring
Expand Down
1 change: 1 addition & 0 deletions libcxx/test/libcxx/transitive_includes/cxx26.csv
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ random version
ranges cctype
ranges compare
ranges concepts
ranges cstddef
ranges cstdint
ranges cstdio
ranges cstring
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// 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, c++20

// std::ranges::elements_of;

#include <ranges>

#include <memory>

#include "min_allocator.h"
#include "test_allocator.h"
#include "test_iterators.h"

template <class Iterator>
struct Range {
Iterator begin() const;
sentinel_wrapper<Iterator> end() const;
};

constexpr bool test() {
types::for_each(
types::type_list<std::allocator<std::byte>, min_allocator<std::byte>, test_allocator<std::byte>>{},
[]<class Allocator> {
types::for_each(types::cpp20_input_iterator_list<int*>{}, []<class Iterator> {
Range<Iterator> r;
static_assert(std::same_as<decltype(std::ranges::elements_of(r)),
std::ranges::elements_of<Range<Iterator>&, std::allocator<std::byte>>>);
static_assert(std::same_as<decltype(std::ranges::elements_of(Range<Iterator>())),
std::ranges::elements_of<Range<Iterator>&&, std::allocator<std::byte>>>);

Allocator a;
static_assert(std::same_as<decltype(std::ranges::elements_of(r, a)),
std::ranges::elements_of<Range<Iterator>&, Allocator>>);
static_assert(std::same_as<decltype(std::ranges::elements_of(Range<Iterator>(), Allocator())),
std::ranges::elements_of<Range<Iterator>&&, Allocator>>);

static_assert(std::same_as<decltype(std::ranges::elements_of{.range = r, .allocator = a}),
std::ranges::elements_of<Range<Iterator>&, Allocator>>);
static_assert(
std::same_as<decltype(std::ranges::elements_of{.range = Range<Iterator>(), .allocator = Allocator()}),
std::ranges::elements_of<Range<Iterator>&&, Allocator>>);
});
});

return true;
}

static_assert(test());
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// 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, c++20

// std::ranges::elements_of;

#include <ranges>

#include <concepts>
#include <memory>
#include <type_traits>
#include <vector>

#include "min_allocator.h"
#include "test_allocator.h"
#include "test_iterators.h"

template <class Iterator>
struct Range {
using Sentinel = sentinel_wrapper<Iterator>;

Iterator begin() { return Iterator(data_.data()); }

Sentinel end() { return Sentinel(Iterator(data_.data() + data_.size())); }

private:
std::vector<int> data_ = {0, 1, 2, 3};
};

template <class Range, class Allocator>
constexpr bool test_range() {
Range r;

using elements_of_t = std::ranges::elements_of<Range&, Allocator>;
{
// constructor
std::same_as<elements_of_t> decltype(auto) elements_of = std::ranges::elements_of(r, Allocator());
[[maybe_unused]] std::same_as<Range&> decltype(auto) elements_of_range = elements_of.range;
if (!std::is_constant_evaluated()) {
assert(std::ranges::distance(elements_of_range) == 4);
}
[[maybe_unused]] std::same_as<Allocator> decltype(auto) elements_of_allocator = elements_of.allocator;
}
{
// designated initializer
std::same_as<elements_of_t> decltype(auto) elements_of = std::ranges::elements_of{
.range = r,
.allocator = Allocator(),
};
[[maybe_unused]] std::same_as<Range&> decltype(auto) elements_of_range = elements_of.range;
if (!std::is_constant_evaluated()) {
assert(std::ranges::distance(elements_of_range) == 4);
}
[[maybe_unused]] std::same_as<Allocator> decltype(auto) elements_of_allocator = elements_of.allocator;
}
{
// copy constructor
std::same_as<elements_of_t> decltype(auto) elements_of_1 = std::ranges::elements_of(r, Allocator());
std::same_as<elements_of_t> auto elements_of_2 = elements_of_1;
[[maybe_unused]] std::same_as<Range&> decltype(auto) elements_of_1_range = elements_of_1.range;
[[maybe_unused]] std::same_as<Range&> decltype(auto) elements_of_2_range = elements_of_2.range;
if (!std::is_constant_evaluated()) {
assert(std::ranges::distance(elements_of_1_range) == 4);
assert(std::ranges::distance(elements_of_2_range) == 4);
}
[[maybe_unused]] std::same_as<Allocator> decltype(auto) elements_of_2_allocator = elements_of_2.allocator;
}

using elements_of_r_t = std::ranges::elements_of<Range&&, Allocator>;
{
// move constructor
std::same_as<elements_of_r_t> decltype(auto) elements_of_1 = std::ranges::elements_of(std::move(r), Allocator());
std::same_as<elements_of_r_t> auto elements_of_2 = std::move(elements_of_1);
[[maybe_unused]] std::same_as<Range&&> decltype(auto) elements_of_1_range = std::move(elements_of_1.range);
[[maybe_unused]] std::same_as<Range&&> decltype(auto) elements_of_2_range = std::move(elements_of_2.range);
if (!std::is_constant_evaluated()) {
assert(std::ranges::distance(elements_of_1_range) == 4);
assert(std::ranges::distance(elements_of_2_range) == 4);
}
[[maybe_unused]] std::same_as<Allocator> decltype(auto) elements_of_2_allocator = elements_of_2.allocator;
}
return true;
}

constexpr bool test() {
types::for_each(types::type_list<std::allocator<std::byte>, min_allocator<std::byte>, test_allocator<std::byte>>{},
[]<class Allocator> {
types::for_each(types::cpp20_input_iterator_list<int*>{}, []<class Iterator> {
test_range<Range<Iterator>, Allocator>();
});
});

return true;
}

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

return 0;
}
Loading