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 // <functional>
11 
12 // reference_wrapper
13 
14 // check for deriving from binary_function
15 
16 #include <functional>
17 #include <type_traits>
18 
19 class functor1
20     : public std::unary_function<int, char>
21 {
22 };
23 
24 class functor2
25     : public std::binary_function<char, int, double>
26 {
27 };
28 
29 class functor3
30     : public std::unary_function<int, int>,
31       public std::binary_function<char, int, double>
32 {
33 public:
34     typedef float result_type;
35 };
36 
37 class functor4
38     : public std::unary_function<int, int>,
39       public std::binary_function<char, int, double>
40 {
41 public:
42 };
43 
44 struct C
45 {
46     typedef int argument_type;
47     typedef int result_type;
48 };
49 
main()50 int main()
51 {
52     static_assert((!std::is_base_of<std::binary_function<int, char, int>,
53                                     std::reference_wrapper<functor1> >::value), "");
54     static_assert((std::is_base_of<std::binary_function<char, int, double>,
55                                    std::reference_wrapper<functor2> >::value), "");
56     static_assert((std::is_base_of<std::binary_function<char, int, double>,
57                                    std::reference_wrapper<functor3> >::value), "");
58     static_assert((std::is_base_of<std::binary_function<char, int, double>,
59                                    std::reference_wrapper<functor4> >::value), "");
60     static_assert((!std::is_base_of<std::binary_function<int, int, int>,
61                                     std::reference_wrapper<C> >::value), "");
62     static_assert((!std::is_base_of<std::binary_function<int, int, float>,
63                                     std::reference_wrapper<float ()> >::value), "");
64     static_assert((!std::is_base_of<std::binary_function<int, int, float>,
65                                    std::reference_wrapper<float (int)> >::value), "");
66     static_assert((std::is_base_of<std::binary_function<int, int, float>,
67                                     std::reference_wrapper<float (int, int)> >::value), "");
68     static_assert((!std::is_base_of<std::binary_function<int, int, float>,
69                                     std::reference_wrapper<float(*)()> >::value), "");
70     static_assert((!std::is_base_of<std::binary_function<int, int, float>,
71                                    std::reference_wrapper<float(*)(int)> >::value), "");
72     static_assert((std::is_base_of<std::binary_function<int, int, float>,
73                                     std::reference_wrapper<float(*)(int, int)> >::value), "");
74     static_assert((!std::is_base_of<std::binary_function<C*, int, float>,
75                                    std::reference_wrapper<float(C::*)()> >::value), "");
76     static_assert((std::is_base_of<std::binary_function<C*, int, float>,
77                                    std::reference_wrapper<float(C::*)(int)> >::value), "");
78     static_assert((std::is_base_of<std::binary_function<const volatile C*, int, float>,
79                                    std::reference_wrapper<float(C::*)(int) const volatile> >::value), "");
80 }
81