Debian Codegraph @

libstdc++-v3/testsuite/24_iterators/indirect_callable/projected-adl.cc

raw
1 // { dg-do compile { target c++20 } }
2
3 // P2538R1 ADL-proof std::projected
4 // https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2538r1.html
5
6 #include <iterator>
7
8 template<typename T>
9 concept has_diff_type = requires { typename T::difference_type; };
10
11 static_assert( has_diff_type<std::projected<int*, void(*)(int)>> );
12
13 struct Indy {
14 using value_type = int;
15 int operator*() const { return 0; }
16 };
17 static_assert( ! std::weakly_incrementable<Indy> );
18 static_assert( ! has_diff_type<std::projected<Indy, void(*)(int)>> );
19
20
21 // Examples from the paper:
22
23 template<class T> struct Holder { T t; };
24 struct Incomplete;
25
26 void test_concepts()
27 {
28 using T = Holder<Incomplete>*;
29 static_assert(std::equality_comparable<T>);
30 (void) std::indirectly_comparable<T*, T*, std::equal_to<>>;
31 (void) std::sortable<T*>;
32 }
33
34 #include <algorithm>
35
36 void test_count()
37 {
38 Holder<Incomplete>* a = nullptr;
39 (void) std::count(&a, &a, nullptr);
40 (void) std::ranges::count(&a, &a, nullptr); // { dg-bogus "." }
41 }