//===----------------------------------------------------------------------===// // // 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 // // // template> // struct std::ranges::elements_of; #include #include #include #include #include #include #include #include "min_allocator.h" #include "test_allocator.h" #include "test_iterators.h" template struct Range { using Sentinel = sentinel_wrapper; constexpr Iterator begin() { return Iterator(data_.data()); } constexpr Sentinel end() { return Sentinel(Iterator(data_.data() + data_.size())); } private: std::vector data_ = {0, 1, 2, 3}; }; template constexpr bool test_range() { Range r; using elements_of_t = std::ranges::elements_of; { // constructor std::same_as decltype(auto) e = std::ranges::elements_of(r, Allocator()); std::same_as decltype(auto) range = e.range; assert(std::ranges::distance(range) == 4); [[maybe_unused]] std::same_as decltype(auto) allocator = e.allocator; } { // designated initializer std::same_as decltype(auto) e = std::ranges::elements_of{ .range = r, .allocator = Allocator(), }; std::same_as decltype(auto) range = e.range; assert(&range == &r); assert(std::ranges::distance(range) == 4); [[maybe_unused]] std::same_as decltype(auto) allocator = e.allocator; } { // copy constructor std::same_as decltype(auto) e = std::ranges::elements_of(r, Allocator()); std::same_as auto copy = e; std::same_as decltype(auto) range = e.range; std::same_as decltype(auto) copy_range = copy.range; assert(&range == &r); assert(&range == ©_range); assert(std::ranges::distance(range) == 4); [[maybe_unused]] std::same_as decltype(auto) copy_allocator = copy.allocator; } using elements_of_r_t = std::ranges::elements_of; { // move constructor std::same_as decltype(auto) e = std::ranges::elements_of(std::move(r), Allocator()); std::same_as auto copy = std::move(e); std::same_as decltype(auto) range = std::move(e.range); std::same_as decltype(auto) copy_range = std::move(copy.range); assert(&range == &r); assert(&range == ©_range); assert(std::ranges::distance(range) == 4); [[maybe_unused]] std::same_as decltype(auto) copy_allocator = copy.allocator; } return true; } constexpr bool test() { types::for_each(types::type_list, min_allocator, test_allocator>{}, [] { types::for_each(types::cpp20_input_iterator_list{}, [] { test_range, Allocator>(); }); }); return true; } int main(int, char**) { test(); static_assert(test()); return 0; }