142 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// [customization.point.object]12// [range.adaptor.object] "A range adaptor object is a customization point object..."13 14#include <compare>15#include <concepts>16#include <iterator>17#include <ranges>18#include <sstream>19#include <type_traits>20#include <utility>21 22#include "test_macros.h"23 24// Test for basic properties of C++20 16.3.3.3.6 [customization.point.object].25template <class CPO, class... Args>26constexpr bool test(CPO& o, Args&&...) {27 static_assert(std::is_const_v<CPO>);28 static_assert(std::is_class_v<CPO>);29 static_assert(std::is_trivially_copyable_v<CPO>);30 static_assert(std::is_trivially_default_constructible_v<CPO>);31 32 auto p = o;33 using T = decltype(p);34 35 // The type of a customization point object, ignoring cv-qualifiers, shall model semiregular.36 static_assert(std::semiregular<T>);37 38 // The type T of a customization point object, ignoring cv-qualifiers, shall model...39 static_assert(std::invocable<T&, Args...>);40 static_assert(std::invocable<const T&, Args...>);41 static_assert(std::invocable<T, Args...>);42 static_assert(std::invocable<const T, Args...>);43 44 return true;45}46 47int a[10];48int arrays[10][10];49std::pair<int, int> pairs[10];50#ifndef TEST_HAS_NO_LOCALIZATION51std::istringstream stream;52#endif53 54// [concept.swappable]55static_assert(test(std::ranges::swap, a, a));56 57// [iterator.cust]58static_assert(test(std::ranges::iter_move, a + 0));59static_assert(test(std::ranges::iter_swap, a + 0, a + 1));60 61// [cmp.alg]62static_assert(test(std::partial_order, 1, 2));63static_assert(test(std::strong_order, 1, 2));64static_assert(test(std::weak_order, 1, 2));65static_assert(test(std::compare_partial_order_fallback, 1, 2));66static_assert(test(std::compare_strong_order_fallback, 1, 2));67static_assert(test(std::compare_weak_order_fallback, 1, 2));68 69// [range.access]70static_assert(test(std::ranges::begin, a));71static_assert(test(std::ranges::end, a));72static_assert(test(std::ranges::cbegin, a));73static_assert(test(std::ranges::cdata, a));74static_assert(test(std::ranges::cend, a));75static_assert(test(std::ranges::crbegin, a));76static_assert(test(std::ranges::crend, a));77static_assert(test(std::ranges::data, a));78static_assert(test(std::ranges::empty, a));79static_assert(test(std::ranges::rbegin, a));80static_assert(test(std::ranges::rend, a));81static_assert(test(std::ranges::size, a));82static_assert(test(std::ranges::ssize, a));83 84#if TEST_STD_VER >= 2685// static_assert(test(std::views::reserve_hint, a));86#endif87 88// [range.factories]89// views::empty<T> is not a CPO90static_assert(test(std::views::iota, 1));91static_assert(test(std::views::iota, 1, 10));92#if TEST_STD_VER >= 2693static_assert(test(std::views::indices, 10));94#endif95#ifndef TEST_HAS_NO_LOCALIZATION96static_assert(test(std::views::istream<int>, stream));97#endif98static_assert(test(std::views::single, 4));99 100#if TEST_STD_VER >= 23101static_assert(test(std::views::repeat, 1));102#endif103 104// [range.adaptors]105static_assert(test(std::views::all, a));106static_assert(test(std::views::common, a));107static_assert(test(std::views::counted, a, 10));108static_assert(test(std::views::drop, a, 10));109static_assert(test(std::views::drop_while, a, [](int x) { return x < 10; }));110static_assert(test(std::views::elements<0>, pairs));111static_assert(test(std::views::filter, a, [](int x) { return x < 10; }));112static_assert(test(std::views::join, arrays));113static_assert(test(std::views::keys, pairs));114static_assert(test(std::views::lazy_split, a, 4));115static_assert(test(std::views::reverse, a));116static_assert(test(std::views::split, a, 4));117static_assert(test(std::views::take, a, 10));118static_assert(test(std::views::take_while, a, [](int x) { return x < 10; }));119static_assert(test(std::views::transform, a, [](int x) { return x + 1; }));120static_assert(test(std::views::values, pairs));121 122#if TEST_STD_VER >= 23123// static_assert(test(std::views::adjacent_transform<2>, [](int x, int y) { return x + y; }, a));124// static_assert(test(std::views::adjacent<2>, a));125// static_assert(test(std::views::as_const, a));126static_assert(test(std::views::as_rvalue, a));127// static_assert(test(std::views::cartesian_product, a, a, a));128static_assert(test(std::views::chunk_by, a, [](int x, int y) { return x < y; }));129// static_assert(test(std::views::chunk, a, 1));130// static_assert(test(std::views::enumerate, a));131static_assert(test(std::views::join_with, 1));132// static_assert(test(std::views::stride, a, 1));133static_assert(test(std::views::zip_transform, [](int x, int y) { return x + y; }, a, a));134static_assert(test(std::views::zip, a, a));135#endif136 137#if TEST_STD_VER >= 26138// static_assert(test(std::views::cache_latest, a));139// static_assert(test(std::views::concat, a, a));140// static_assert(test(std::views::to_input, a));141#endif142