|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +// REQUIRES: std-at-least-c++20 |
| 10 | + |
| 11 | +// [range.access.general]/1: |
| 12 | +// In addition to being available via inclusion of the <ranges> header, the customization point objects in |
| 13 | +// [range.access] are available when the header <iterator> is included. |
| 14 | + |
| 15 | +#include <iterator> |
| 16 | +#include <type_traits> |
| 17 | + |
| 18 | +#include "test_macros.h" |
| 19 | + |
| 20 | +template <class CPO, class... Args> |
| 21 | +constexpr void test(CPO& o, Args&&... args) { |
| 22 | + static_assert(std::is_const_v<CPO>); |
| 23 | + static_assert(std::is_class_v<CPO>); |
| 24 | + static_assert(std::is_trivially_copyable_v<CPO>); |
| 25 | + static_assert(std::is_trivially_default_constructible_v<CPO>); |
| 26 | + |
| 27 | + auto p = o; |
| 28 | + using T = decltype(p); |
| 29 | + (void)o(args...); // to make sure the CPO can actually be used |
| 30 | + |
| 31 | + // The type of a customization point object, ignoring cv-qualifiers, shall model semiregular. |
| 32 | + static_assert(std::semiregular<T>); |
| 33 | + |
| 34 | + // The type T of a customization point object, ignoring cv-qualifiers, shall model... |
| 35 | + static_assert(std::invocable<T&, Args...>); |
| 36 | + static_assert(std::invocable<const T&, Args...>); |
| 37 | + static_assert(std::invocable<T, Args...>); |
| 38 | + static_assert(std::invocable<const T, Args...>); |
| 39 | +} |
| 40 | + |
| 41 | +int a[10]; |
| 42 | + |
| 43 | +constexpr bool test() { |
| 44 | + test(std::ranges::begin, a); |
| 45 | + test(std::ranges::end, a); |
| 46 | + test(std::ranges::cbegin, a); |
| 47 | + test(std::ranges::cdata, a); |
| 48 | + test(std::ranges::cend, a); |
| 49 | + test(std::ranges::crbegin, a); |
| 50 | + test(std::ranges::crend, a); |
| 51 | + test(std::ranges::data, a); |
| 52 | + test(std::ranges::empty, a); |
| 53 | + test(std::ranges::rbegin, a); |
| 54 | + test(std::ranges::rend, a); |
| 55 | + test(std::ranges::size, a); |
| 56 | + test(std::ranges::ssize, a); |
| 57 | + |
| 58 | +#if TEST_STD_VER >= 26 |
| 59 | + // test(std::views::reserve_hint, a); |
| 60 | +#endif |
| 61 | + |
| 62 | + return true; |
| 63 | +} |
| 64 | + |
| 65 | +int main() { |
| 66 | + test(); |
| 67 | + static_assert(test()); |
| 68 | +} |
0 commit comments