xref: /llvm-project/libcxx/test/support/is_transparent.h (revision d5db71d19f11d7c31257066aea6bd41ef04f28b7)
15b03e1adSMarshall Clow //===----------------------------------------------------------------------===//
25b03e1adSMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65b03e1adSMarshall Clow //
75b03e1adSMarshall Clow //===----------------------------------------------------------------------===//
85b03e1adSMarshall Clow 
95b03e1adSMarshall Clow #ifndef TRANSPARENT_H
105b03e1adSMarshall Clow #define TRANSPARENT_H
115b03e1adSMarshall Clow 
120f901c7eSStephan T. Lavavej #include "test_macros.h"
130f901c7eSStephan T. Lavavej 
14*e5ec94a1SRuslan Arutyunyan #include <functional> // for std::equal_to
15*e5ec94a1SRuslan Arutyunyan 
165b03e1adSMarshall Clow // testing transparent
170f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11
185b03e1adSMarshall Clow 
195b03e1adSMarshall Clow struct transparent_less
205b03e1adSMarshall Clow {
215b03e1adSMarshall Clow     template <class T, class U>
225b03e1adSMarshall Clow     constexpr auto operator()(T&& t, U&& u) const
235b03e1adSMarshall Clow     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
245b03e1adSMarshall Clow     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
255b03e1adSMarshall Clow         { return      std::forward<T>(t) < std::forward<U>(u); }
26b707e7f3SMarshall Clow     using is_transparent = void;  // correct
27b707e7f3SMarshall Clow };
28b707e7f3SMarshall Clow 
29b707e7f3SMarshall Clow struct transparent_less_not_referenceable
30b707e7f3SMarshall Clow {
31b707e7f3SMarshall Clow     template <class T, class U>
32b707e7f3SMarshall Clow     constexpr auto operator()(T&& t, U&& u) const
33b707e7f3SMarshall Clow     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
34b707e7f3SMarshall Clow     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
35b707e7f3SMarshall Clow         { return      std::forward<T>(t) < std::forward<U>(u); }
36b707e7f3SMarshall Clow     using is_transparent = void () const &;  // it's a type; a weird one, but a type
375b03e1adSMarshall Clow };
385b03e1adSMarshall Clow 
395b03e1adSMarshall Clow struct transparent_less_no_type
405b03e1adSMarshall Clow {
415b03e1adSMarshall Clow     template <class T, class U>
425b03e1adSMarshall Clow     constexpr auto operator()(T&& t, U&& u) const
435b03e1adSMarshall Clow     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
445b03e1adSMarshall Clow     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
455b03e1adSMarshall Clow         { return      std::forward<T>(t) < std::forward<U>(u); }
465b03e1adSMarshall Clow private:
47b707e7f3SMarshall Clow //    using is_transparent = void;  // error - should exist
485b03e1adSMarshall Clow };
495b03e1adSMarshall Clow 
505b03e1adSMarshall Clow struct transparent_less_private
515b03e1adSMarshall Clow {
525b03e1adSMarshall Clow     template <class T, class U>
535b03e1adSMarshall Clow     constexpr auto operator()(T&& t, U&& u) const
545b03e1adSMarshall Clow     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
555b03e1adSMarshall Clow     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
565b03e1adSMarshall Clow         { return      std::forward<T>(t) < std::forward<U>(u); }
575b03e1adSMarshall Clow private:
58b707e7f3SMarshall Clow     using is_transparent = void;  // error - should be accessible
595b03e1adSMarshall Clow };
605b03e1adSMarshall Clow 
615b03e1adSMarshall Clow struct transparent_less_not_a_type
625b03e1adSMarshall Clow {
635b03e1adSMarshall Clow     template <class T, class U>
645b03e1adSMarshall Clow     constexpr auto operator()(T&& t, U&& u) const
655b03e1adSMarshall Clow     noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
665b03e1adSMarshall Clow     -> decltype      (std::forward<T>(t) < std::forward<U>(u))
675b03e1adSMarshall Clow         { return      std::forward<T>(t) < std::forward<U>(u); }
685b03e1adSMarshall Clow 
695b03e1adSMarshall Clow     int is_transparent;  // error - should be a type
705b03e1adSMarshall Clow };
715b03e1adSMarshall Clow 
725b03e1adSMarshall Clow struct C2Int { // comparable to int
C2IntC2Int735b03e1adSMarshall Clow     C2Int() : i_(0) {}
C2IntC2Int745b03e1adSMarshall Clow     C2Int(int i): i_(i) {}
getC2Int755b03e1adSMarshall Clow     int get () const { return i_; }
765b03e1adSMarshall Clow private:
775b03e1adSMarshall Clow     int i_;
785b03e1adSMarshall Clow     };
795b03e1adSMarshall Clow 
805b03e1adSMarshall Clow bool operator <(int          rhs,   const C2Int& lhs) { return rhs       < lhs.get(); }
815b03e1adSMarshall Clow bool operator <(const C2Int& rhs,   const C2Int& lhs) { return rhs.get() < lhs.get(); }
825b03e1adSMarshall Clow bool operator <(const C2Int& rhs,            int lhs) { return rhs.get() < lhs; }
835b03e1adSMarshall Clow 
84*e5ec94a1SRuslan Arutyunyan #endif // TEST_STD_VER > 11
85*e5ec94a1SRuslan Arutyunyan 
865b03e1adSMarshall Clow #endif // TRANSPARENT_H
87