xref: /aosp_15_r20/external/libcxx/test/support/is_transparent.h (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
2*58b9f456SAndroid Build Coastguard Worker //
3*58b9f456SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*58b9f456SAndroid Build Coastguard Worker //
5*58b9f456SAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*58b9f456SAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*58b9f456SAndroid Build Coastguard Worker //
8*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*58b9f456SAndroid Build Coastguard Worker 
10*58b9f456SAndroid Build Coastguard Worker #ifndef TRANSPARENT_H
11*58b9f456SAndroid Build Coastguard Worker #define TRANSPARENT_H
12*58b9f456SAndroid Build Coastguard Worker 
13*58b9f456SAndroid Build Coastguard Worker #include "test_macros.h"
14*58b9f456SAndroid Build Coastguard Worker 
15*58b9f456SAndroid Build Coastguard Worker // testing transparent
16*58b9f456SAndroid Build Coastguard Worker #if TEST_STD_VER > 11
17*58b9f456SAndroid Build Coastguard Worker 
18*58b9f456SAndroid Build Coastguard Worker struct transparent_less
19*58b9f456SAndroid Build Coastguard Worker {
20*58b9f456SAndroid Build Coastguard Worker     template <class T, class U>
21*58b9f456SAndroid Build Coastguard Worker     constexpr auto operator()(T&& t, U&& u) const
22*58b9f456SAndroid Build Coastguard Worker     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
23*58b9f456SAndroid Build Coastguard Worker     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
24*58b9f456SAndroid Build Coastguard Worker         { return      std::forward<T>(t) < std::forward<U>(u); }
25*58b9f456SAndroid Build Coastguard Worker     using is_transparent = void;  // correct
26*58b9f456SAndroid Build Coastguard Worker };
27*58b9f456SAndroid Build Coastguard Worker 
28*58b9f456SAndroid Build Coastguard Worker struct transparent_less_not_referenceable
29*58b9f456SAndroid Build Coastguard Worker {
30*58b9f456SAndroid Build Coastguard Worker     template <class T, class U>
31*58b9f456SAndroid Build Coastguard Worker     constexpr auto operator()(T&& t, U&& u) const
32*58b9f456SAndroid Build Coastguard Worker     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
33*58b9f456SAndroid Build Coastguard Worker     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
34*58b9f456SAndroid Build Coastguard Worker         { return      std::forward<T>(t) < std::forward<U>(u); }
35*58b9f456SAndroid Build Coastguard Worker     using is_transparent = void () const &;  // it's a type; a weird one, but a type
36*58b9f456SAndroid Build Coastguard Worker };
37*58b9f456SAndroid Build Coastguard Worker 
38*58b9f456SAndroid Build Coastguard Worker struct transparent_less_no_type
39*58b9f456SAndroid Build Coastguard Worker {
40*58b9f456SAndroid Build Coastguard Worker     template <class T, class U>
41*58b9f456SAndroid Build Coastguard Worker     constexpr auto operator()(T&& t, U&& u) const
42*58b9f456SAndroid Build Coastguard Worker     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
43*58b9f456SAndroid Build Coastguard Worker     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
44*58b9f456SAndroid Build Coastguard Worker         { return      std::forward<T>(t) < std::forward<U>(u); }
45*58b9f456SAndroid Build Coastguard Worker private:
46*58b9f456SAndroid Build Coastguard Worker //    using is_transparent = void;  // error - should exist
47*58b9f456SAndroid Build Coastguard Worker };
48*58b9f456SAndroid Build Coastguard Worker 
49*58b9f456SAndroid Build Coastguard Worker struct transparent_less_private
50*58b9f456SAndroid Build Coastguard Worker {
51*58b9f456SAndroid Build Coastguard Worker     template <class T, class U>
52*58b9f456SAndroid Build Coastguard Worker     constexpr auto operator()(T&& t, U&& u) const
53*58b9f456SAndroid Build Coastguard Worker     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
54*58b9f456SAndroid Build Coastguard Worker     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
55*58b9f456SAndroid Build Coastguard Worker         { return      std::forward<T>(t) < std::forward<U>(u); }
56*58b9f456SAndroid Build Coastguard Worker private:
57*58b9f456SAndroid Build Coastguard Worker     using is_transparent = void;  // error - should be accessible
58*58b9f456SAndroid Build Coastguard Worker };
59*58b9f456SAndroid Build Coastguard Worker 
60*58b9f456SAndroid Build Coastguard Worker struct transparent_less_not_a_type
61*58b9f456SAndroid Build Coastguard Worker {
62*58b9f456SAndroid Build Coastguard Worker     template <class T, class U>
63*58b9f456SAndroid Build Coastguard Worker     constexpr auto operator()(T&& t, U&& u) const
64*58b9f456SAndroid Build Coastguard Worker     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
65*58b9f456SAndroid Build Coastguard Worker     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
66*58b9f456SAndroid Build Coastguard Worker         { return      std::forward<T>(t) < std::forward<U>(u); }
67*58b9f456SAndroid Build Coastguard Worker 
68*58b9f456SAndroid Build Coastguard Worker     int is_transparent;  // error - should be a type
69*58b9f456SAndroid Build Coastguard Worker };
70*58b9f456SAndroid Build Coastguard Worker 
71*58b9f456SAndroid Build Coastguard Worker struct C2Int { // comparable to int
C2IntC2Int72*58b9f456SAndroid Build Coastguard Worker     C2Int() : i_(0) {}
C2IntC2Int73*58b9f456SAndroid Build Coastguard Worker     C2Int(int i): i_(i) {}
getC2Int74*58b9f456SAndroid Build Coastguard Worker     int get () const { return i_; }
75*58b9f456SAndroid Build Coastguard Worker private:
76*58b9f456SAndroid Build Coastguard Worker     int i_;
77*58b9f456SAndroid Build Coastguard Worker     };
78*58b9f456SAndroid Build Coastguard Worker 
79*58b9f456SAndroid Build Coastguard Worker bool operator <(int          rhs,   const C2Int& lhs) { return rhs       < lhs.get(); }
80*58b9f456SAndroid Build Coastguard Worker bool operator <(const C2Int& rhs,   const C2Int& lhs) { return rhs.get() < lhs.get(); }
81*58b9f456SAndroid Build Coastguard Worker bool operator <(const C2Int& rhs,            int lhs) { return rhs.get() < lhs; }
82*58b9f456SAndroid Build Coastguard Worker 
83*58b9f456SAndroid Build Coastguard Worker #endif
84*58b9f456SAndroid Build Coastguard Worker 
85*58b9f456SAndroid Build Coastguard Worker #endif  // TRANSPARENT_H
86