1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef TRANSPARENT_H 11 #define TRANSPARENT_H 12 13 // testing transparent 14 #if _LIBCPP_STD_VER > 11 15 16 struct transparent_less 17 { 18 template <class T, class U> 19 constexpr auto operator()(T&& t, U&& u) const 20 noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u))) 21 -> decltype (std::forward<T>(t) < std::forward<U>(u)) 22 { return std::forward<T>(t) < std::forward<U>(u); } 23 typedef void is_transparent; // correct 24 }; 25 26 struct transparent_less_no_type 27 { 28 template <class T, class U> 29 constexpr auto operator()(T&& t, U&& u) const 30 noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u))) 31 -> decltype (std::forward<T>(t) < std::forward<U>(u)) 32 { return std::forward<T>(t) < std::forward<U>(u); } 33 private: 34 // typedef void is_transparent; // error - should exist 35 }; 36 37 struct transparent_less_private 38 { 39 template <class T, class U> 40 constexpr auto operator()(T&& t, U&& u) const 41 noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u))) 42 -> decltype (std::forward<T>(t) < std::forward<U>(u)) 43 { return std::forward<T>(t) < std::forward<U>(u); } 44 private: 45 typedef void is_transparent; // error - should be accessible 46 }; 47 48 struct transparent_less_not_a_type 49 { 50 template <class T, class U> 51 constexpr auto operator()(T&& t, U&& u) const 52 noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u))) 53 -> decltype (std::forward<T>(t) < std::forward<U>(u)) 54 { return std::forward<T>(t) < std::forward<U>(u); } 55 56 int is_transparent; // error - should be a type 57 }; 58 59 struct C2Int { // comparable to int 60 C2Int() : i_(0) {} 61 C2Int(int i): i_(i) {} 62 int get () const { return i_; } 63 private: 64 int i_; 65 }; 66 67 bool operator <(int rhs, const C2Int& lhs) { return rhs < lhs.get(); } 68 bool operator <(const C2Int& rhs, const C2Int& lhs) { return rhs.get() < lhs.get(); } 69 bool operator <(const C2Int& rhs, int lhs) { return rhs.get() < lhs; } 70 71 #endif 72 73 #endif // TRANSPARENT_H 74