is_transparent.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifndef TRANSPARENT_H
  9. #define TRANSPARENT_H
  10. #include "test_macros.h"
  11. // testing transparent
  12. #if TEST_STD_VER > 11
  13. struct transparent_less
  14. {
  15. template <class T, class U>
  16. constexpr auto operator()(T&& t, U&& u) const
  17. noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
  18. -> decltype (std::forward<T>(t) < std::forward<U>(u))
  19. { return std::forward<T>(t) < std::forward<U>(u); }
  20. using is_transparent = void; // correct
  21. };
  22. struct transparent_less_not_referenceable
  23. {
  24. template <class T, class U>
  25. constexpr auto operator()(T&& t, U&& u) const
  26. noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
  27. -> decltype (std::forward<T>(t) < std::forward<U>(u))
  28. { return std::forward<T>(t) < std::forward<U>(u); }
  29. using is_transparent = void () const &; // it's a type; a weird one, but a type
  30. };
  31. struct transparent_less_no_type
  32. {
  33. template <class T, class U>
  34. constexpr auto operator()(T&& t, U&& u) const
  35. noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
  36. -> decltype (std::forward<T>(t) < std::forward<U>(u))
  37. { return std::forward<T>(t) < std::forward<U>(u); }
  38. private:
  39. // using is_transparent = void; // error - should exist
  40. };
  41. struct transparent_less_private
  42. {
  43. template <class T, class U>
  44. constexpr auto operator()(T&& t, U&& u) const
  45. noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
  46. -> decltype (std::forward<T>(t) < std::forward<U>(u))
  47. { return std::forward<T>(t) < std::forward<U>(u); }
  48. private:
  49. using is_transparent = void; // error - should be accessible
  50. };
  51. struct transparent_less_not_a_type
  52. {
  53. template <class T, class U>
  54. constexpr auto operator()(T&& t, U&& u) const
  55. noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
  56. -> decltype (std::forward<T>(t) < std::forward<U>(u))
  57. { return std::forward<T>(t) < std::forward<U>(u); }
  58. int is_transparent; // error - should be a type
  59. };
  60. struct C2Int { // comparable to int
  61. C2Int() : i_(0) {}
  62. C2Int(int i): i_(i) {}
  63. int get () const { return i_; }
  64. private:
  65. int i_;
  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. #endif
  71. #endif // TRANSPARENT_H