• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "test_macros.h"
14 
15 // testing transparent
16 #if TEST_STD_VER > 11
17 
18 struct transparent_less
19 {
20     template <class T, class U>
21     constexpr auto operator()(T&& t, U&& u) const
22     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
23     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
24         { return      std::forward<T>(t) < std::forward<U>(u); }
25     typedef void is_transparent;  // correct
26 };
27 
28 struct transparent_less_no_type
29 {
30     template <class T, class U>
31     constexpr auto operator()(T&& t, U&& u) const
32     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
33     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
34         { return      std::forward<T>(t) < std::forward<U>(u); }
35 private:
36 //    typedef void is_transparent;  // error - should exist
37 };
38 
39 struct transparent_less_private
40 {
41     template <class T, class U>
42     constexpr auto operator()(T&& t, U&& u) const
43     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
44     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
45         { return      std::forward<T>(t) < std::forward<U>(u); }
46 private:
47     typedef void is_transparent;  // error - should be accessible
48 };
49 
50 struct transparent_less_not_a_type
51 {
52     template <class T, class U>
53     constexpr auto operator()(T&& t, U&& u) const
54     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
55     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
56         { return      std::forward<T>(t) < std::forward<U>(u); }
57 
58     int is_transparent;  // error - should be a type
59 };
60 
61 struct C2Int { // comparable to int
C2IntC2Int62     C2Int() : i_(0) {}
C2IntC2Int63     C2Int(int i): i_(i) {}
getC2Int64     int get () const { return i_; }
65 private:
66     int i_;
67     };
68 
69 bool operator <(int          rhs,   const C2Int& lhs) { return rhs       < lhs.get(); }
70 bool operator <(const C2Int& rhs,   const C2Int& lhs) { return rhs.get() < lhs.get(); }
71 bool operator <(const C2Int& rhs,            int lhs) { return rhs.get() < lhs; }
72 
73 #endif
74 
75 #endif  // TRANSPARENT_H
76