Home | History | Annotate | Download | only in refwrap
      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 unary_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 
     50 int main()
     51 {
     52     static_assert((std::is_base_of<std::unary_function<int, char>,
     53                                    std::reference_wrapper<functor1> >::value), "");
     54     static_assert((!std::is_base_of<std::unary_function<char, int>,
     55                                     std::reference_wrapper<functor2> >::value), "");
     56     static_assert((std::is_base_of<std::unary_function<int, int>,
     57                                    std::reference_wrapper<functor3> >::value), "");
     58     static_assert((std::is_base_of<std::unary_function<int, int>,
     59                                    std::reference_wrapper<functor4> >::value), "");
     60     static_assert((!std::is_base_of<std::unary_function<int, int>,
     61                                     std::reference_wrapper<C> >::value), "");
     62     static_assert((!std::is_base_of<std::unary_function<int, float>,
     63                                     std::reference_wrapper<float(*)()> >::value), "");
     64     static_assert((std::is_base_of<std::unary_function<int, float>,
     65                                    std::reference_wrapper<float (int)> >::value), "");
     66     static_assert((!std::is_base_of<std::unary_function<int, float>,
     67                                     std::reference_wrapper<float (int, int)> >::value), "");
     68     static_assert((std::is_base_of<std::unary_function<int, float>,
     69                                    std::reference_wrapper<float(*)(int)> >::value), "");
     70     static_assert((!std::is_base_of<std::unary_function<int, float>,
     71                                     std::reference_wrapper<float(*)(int, int)> >::value), "");
     72     static_assert((std::is_base_of<std::unary_function<C*, float>,
     73                                    std::reference_wrapper<float(C::*)()> >::value), "");
     74     static_assert((std::is_base_of<std::unary_function<const volatile C*, float>,
     75                                    std::reference_wrapper<float(C::*)() const volatile> >::value), "");
     76     static_assert((!std::is_base_of<std::unary_function<C*, float>,
     77                                    std::reference_wrapper<float(C::*)(int)> >::value), "");
     78 }
     79