xref: /minix3/external/bsd/libc++/dist/libcxx/test/utilities/function.objects/refwrap/binary.pass.cpp (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc 
10*4684ddb6SLionel Sambuc // <functional>
11*4684ddb6SLionel Sambuc 
12*4684ddb6SLionel Sambuc // reference_wrapper
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc // check for deriving from binary_function
15*4684ddb6SLionel Sambuc 
16*4684ddb6SLionel Sambuc #include <functional>
17*4684ddb6SLionel Sambuc #include <type_traits>
18*4684ddb6SLionel Sambuc 
19*4684ddb6SLionel Sambuc class functor1
20*4684ddb6SLionel Sambuc     : public std::unary_function<int, char>
21*4684ddb6SLionel Sambuc {
22*4684ddb6SLionel Sambuc };
23*4684ddb6SLionel Sambuc 
24*4684ddb6SLionel Sambuc class functor2
25*4684ddb6SLionel Sambuc     : public std::binary_function<char, int, double>
26*4684ddb6SLionel Sambuc {
27*4684ddb6SLionel Sambuc };
28*4684ddb6SLionel Sambuc 
29*4684ddb6SLionel Sambuc class functor3
30*4684ddb6SLionel Sambuc     : public std::unary_function<int, int>,
31*4684ddb6SLionel Sambuc       public std::binary_function<char, int, double>
32*4684ddb6SLionel Sambuc {
33*4684ddb6SLionel Sambuc public:
34*4684ddb6SLionel Sambuc     typedef float result_type;
35*4684ddb6SLionel Sambuc };
36*4684ddb6SLionel Sambuc 
37*4684ddb6SLionel Sambuc class functor4
38*4684ddb6SLionel Sambuc     : public std::unary_function<int, int>,
39*4684ddb6SLionel Sambuc       public std::binary_function<char, int, double>
40*4684ddb6SLionel Sambuc {
41*4684ddb6SLionel Sambuc public:
42*4684ddb6SLionel Sambuc };
43*4684ddb6SLionel Sambuc 
44*4684ddb6SLionel Sambuc struct C
45*4684ddb6SLionel Sambuc {
46*4684ddb6SLionel Sambuc     typedef int argument_type;
47*4684ddb6SLionel Sambuc     typedef int result_type;
48*4684ddb6SLionel Sambuc };
49*4684ddb6SLionel Sambuc 
main()50*4684ddb6SLionel Sambuc int main()
51*4684ddb6SLionel Sambuc {
52*4684ddb6SLionel Sambuc     static_assert((!std::is_base_of<std::binary_function<int, char, int>,
53*4684ddb6SLionel Sambuc                                     std::reference_wrapper<functor1> >::value), "");
54*4684ddb6SLionel Sambuc     static_assert((std::is_base_of<std::binary_function<char, int, double>,
55*4684ddb6SLionel Sambuc                                    std::reference_wrapper<functor2> >::value), "");
56*4684ddb6SLionel Sambuc     static_assert((std::is_base_of<std::binary_function<char, int, double>,
57*4684ddb6SLionel Sambuc                                    std::reference_wrapper<functor3> >::value), "");
58*4684ddb6SLionel Sambuc     static_assert((std::is_base_of<std::binary_function<char, int, double>,
59*4684ddb6SLionel Sambuc                                    std::reference_wrapper<functor4> >::value), "");
60*4684ddb6SLionel Sambuc     static_assert((!std::is_base_of<std::binary_function<int, int, int>,
61*4684ddb6SLionel Sambuc                                     std::reference_wrapper<C> >::value), "");
62*4684ddb6SLionel Sambuc     static_assert((!std::is_base_of<std::binary_function<int, int, float>,
63*4684ddb6SLionel Sambuc                                     std::reference_wrapper<float ()> >::value), "");
64*4684ddb6SLionel Sambuc     static_assert((!std::is_base_of<std::binary_function<int, int, float>,
65*4684ddb6SLionel Sambuc                                    std::reference_wrapper<float (int)> >::value), "");
66*4684ddb6SLionel Sambuc     static_assert((std::is_base_of<std::binary_function<int, int, float>,
67*4684ddb6SLionel Sambuc                                     std::reference_wrapper<float (int, int)> >::value), "");
68*4684ddb6SLionel Sambuc     static_assert((!std::is_base_of<std::binary_function<int, int, float>,
69*4684ddb6SLionel Sambuc                                     std::reference_wrapper<float(*)()> >::value), "");
70*4684ddb6SLionel Sambuc     static_assert((!std::is_base_of<std::binary_function<int, int, float>,
71*4684ddb6SLionel Sambuc                                    std::reference_wrapper<float(*)(int)> >::value), "");
72*4684ddb6SLionel Sambuc     static_assert((std::is_base_of<std::binary_function<int, int, float>,
73*4684ddb6SLionel Sambuc                                     std::reference_wrapper<float(*)(int, int)> >::value), "");
74*4684ddb6SLionel Sambuc     static_assert((!std::is_base_of<std::binary_function<C*, int, float>,
75*4684ddb6SLionel Sambuc                                    std::reference_wrapper<float(C::*)()> >::value), "");
76*4684ddb6SLionel Sambuc     static_assert((std::is_base_of<std::binary_function<C*, int, float>,
77*4684ddb6SLionel Sambuc                                    std::reference_wrapper<float(C::*)(int)> >::value), "");
78*4684ddb6SLionel Sambuc     static_assert((std::is_base_of<std::binary_function<const volatile C*, int, float>,
79*4684ddb6SLionel Sambuc                                    std::reference_wrapper<float(C::*)(int) const volatile> >::value), "");
80*4684ddb6SLionel Sambuc }
81