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 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
10 | |
11 | // projected |
12 | |
13 | #include <iterator> |
14 | |
15 | #include <concepts> |
16 | #include <functional> |
17 | |
18 | #include "test_iterators.h" |
19 | |
20 | using IntPtr = std::projected<int const*, std::identity>; |
21 | static_assert(std::same_as<IntPtr::value_type, int>); |
22 | static_assert(std::same_as<decltype(*std::declval<IntPtr>()), int const&>); |
23 | static_assert(std::same_as<std::iter_difference_t<IntPtr>, std::ptrdiff_t>); |
24 | |
25 | struct S { }; |
26 | |
27 | using Cpp17InputIterator = std::projected<cpp17_input_iterator<S*>, int S::*>; |
28 | static_assert(std::same_as<Cpp17InputIterator::value_type, int>); |
29 | static_assert(std::same_as<decltype(*std::declval<Cpp17InputIterator>()), int&>); |
30 | static_assert(std::same_as<std::iter_difference_t<Cpp17InputIterator>, std::ptrdiff_t>); |
31 | |
32 | using Cpp20InputIterator = std::projected<cpp20_input_iterator<S*>, int S::*>; |
33 | static_assert(std::same_as<Cpp20InputIterator::value_type, int>); |
34 | static_assert(std::same_as<decltype(*std::declval<Cpp20InputIterator>()), int&>); |
35 | static_assert(std::same_as<std::iter_difference_t<Cpp20InputIterator>, std::ptrdiff_t>); |
36 | |
37 | using ForwardIterator = std::projected<forward_iterator<S*>, int (S::*)()>; |
38 | static_assert(std::same_as<ForwardIterator::value_type, int>); |
39 | static_assert(std::same_as<decltype(*std::declval<ForwardIterator>()), int>); |
40 | static_assert(std::same_as<std::iter_difference_t<ForwardIterator>, std::ptrdiff_t>); |
41 | |
42 | using BidirectionalIterator = std::projected<bidirectional_iterator<S*>, S* (S::*)() const>; |
43 | static_assert(std::same_as<BidirectionalIterator::value_type, S*>); |
44 | static_assert(std::same_as<decltype(*std::declval<BidirectionalIterator>()), S*>); |
45 | static_assert(std::same_as<std::iter_difference_t<BidirectionalIterator>, std::ptrdiff_t>); |
46 | |
47 | using RandomAccessIterator = std::projected<random_access_iterator<S*>, S && (S::*)()>; |
48 | static_assert(std::same_as<RandomAccessIterator::value_type, S>); |
49 | static_assert(std::same_as<decltype(*std::declval<RandomAccessIterator>()), S&&>); |
50 | static_assert(std::same_as<std::iter_difference_t<RandomAccessIterator>, std::ptrdiff_t>); |
51 | |
52 | using ContiguousIterator = std::projected<contiguous_iterator<S*>, S& (S::*)() const>; |
53 | static_assert(std::same_as<ContiguousIterator::value_type, S>); |
54 | static_assert(std::same_as<decltype(*std::declval<ContiguousIterator>()), S&>); |
55 | static_assert(std::same_as<std::iter_difference_t<ContiguousIterator>, std::ptrdiff_t>); |
56 | |
57 | template <class I, class F> |
58 | constexpr bool projectable = requires { |
59 | typename std::projected<I, F>; |
60 | }; |
61 | |
62 | static_assert(!projectable<int, void (*)(int)>); // int isn't indirectly_readable |
63 | static_assert(!projectable<S, void (*)(int)>); // S isn't weakly_incrementable |
64 | static_assert(!projectable<int*, void(int)>); // void(int) doesn't satisfy indirectly_regular_unary_invcable |
65 | |