Home | History | Annotate | Download | only in meta.trans.other
      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 // result_of<Fn(ArgTypes...)>
     13 
     14 #include <type_traits>
     15 #include <memory>
     16 #include "test_macros.h"
     17 
     18 struct S
     19 {
     20     typedef short (*FreeFunc)(long);
     21     operator FreeFunc() const;
     22     double operator()(char, int&);
     23     double const& operator()(char, int&) const;
     24     double volatile& operator()(char, int&) volatile;
     25     double const volatile& operator()(char, int&) const volatile;
     26 };
     27 
     28 template <class Tp>
     29 struct Voider {
     30     typedef void type;
     31 };
     32 
     33 template <class T, class = void>
     34 struct HasType : std::false_type {};
     35 
     36 template <class T>
     37 struct HasType<T, typename Voider<typename T::type>::type> : std::true_type {};
     38 
     39 template <class T, class U>
     40 void test_result_of()
     41 {
     42     static_assert((std::is_same<typename std::result_of<T>::type, U>::value), "");
     43 }
     44 
     45 template <class T>
     46 void test_no_result()
     47 {
     48 #if TEST_STD_VER >= 11
     49     static_assert((!HasType<std::result_of<T> >::value), "");
     50 #endif
     51 }
     52 
     53 int main()
     54 {
     55     { // functor object
     56     test_result_of<S(int), short> ();
     57     test_result_of<S&(unsigned char, int&), double> ();
     58     test_result_of<S const&(unsigned char, int&), double const &> ();
     59     test_result_of<S volatile&(unsigned char, int&), double volatile&> ();
     60     test_result_of<S const volatile&(unsigned char, int&), double const volatile&> ();
     61     }
     62     { // pointer to function
     63     typedef bool         (&RF0)();
     64     typedef bool*       (&RF1)(int);
     65     typedef bool&       (&RF2)(int, int);
     66     typedef bool const& (&RF3)(int, int, int);
     67     typedef bool        (*PF0)();
     68     typedef bool*       (*PF1)(int);
     69     typedef bool&       (*PF2)(int, int);
     70     typedef bool const& (*PF3)(int, int, int);
     71     typedef bool        (*&PRF0)();
     72     typedef bool*       (*&PRF1)(int);
     73     typedef bool&       (*&PRF2)(int, int);
     74     typedef bool const& (*&PRF3)(int, int, int);
     75     test_result_of<RF0(), bool>();
     76     test_result_of<RF1(int), bool*>();
     77     test_result_of<RF2(int, long), bool&>();
     78     test_result_of<RF3(int, long, int), bool const&>();
     79     test_result_of<PF0(), bool>();
     80     test_result_of<PF1(int), bool*>();
     81     test_result_of<PF2(int, long), bool&>();
     82     test_result_of<PF3(int, long, int), bool const&>();
     83     test_result_of<PRF0(), bool>();
     84     test_result_of<PRF1(int), bool*>();
     85     test_result_of<PRF2(int, long), bool&>();
     86     test_result_of<PRF3(int, long, int), bool const&>();
     87     }
     88     { // pointer to member function
     89 
     90     typedef int         (S::*PMS0)();
     91     typedef int*        (S::*PMS1)(long);
     92     typedef int&        (S::*PMS2)(long, int);
     93     test_result_of<PMS0(               S),   int> ();
     94     test_result_of<PMS0(               S&),  int> ();
     95     test_result_of<PMS0(               S*),  int> ();
     96     test_result_of<PMS0(               S*&), int> ();
     97     test_result_of<PMS0(std::unique_ptr<S>), int> ();
     98     test_no_result<PMS0(const          S&)>();
     99     test_no_result<PMS0(volatile       S&)>();
    100     test_no_result<PMS0(const volatile S&)>();
    101 
    102     test_result_of<PMS1(               S,   int), int*> ();
    103     test_result_of<PMS1(               S&,  int), int*> ();
    104     test_result_of<PMS1(               S*,  int), int*> ();
    105     test_result_of<PMS1(               S*&, int), int*> ();
    106     test_result_of<PMS1(std::unique_ptr<S>, int), int*> ();
    107     test_no_result<PMS1(const          S&, int)>();
    108     test_no_result<PMS1(volatile       S&, int)>();
    109     test_no_result<PMS1(const volatile S&, int)>();
    110 
    111     test_result_of<PMS2(               S,   int, int), int&> ();
    112     test_result_of<PMS2(               S&,  int, int), int&> ();
    113     test_result_of<PMS2(               S*,  int, int), int&> ();
    114     test_result_of<PMS2(               S*&, int, int), int&> ();
    115     test_result_of<PMS2(std::unique_ptr<S>, int, int), int&> ();
    116     test_no_result<PMS2(const          S&, int, int)>();
    117     test_no_result<PMS2(volatile       S&, int, int)>();
    118     test_no_result<PMS2(const volatile S&, int, int)>();
    119 
    120     typedef int        (S::*PMS0C)() const;
    121     typedef int*       (S::*PMS1C)(long) const;
    122     typedef int&       (S::*PMS2C)(long, int) const;
    123     test_result_of<PMS0C(               S),   int> ();
    124     test_result_of<PMS0C(               S&),  int> ();
    125     test_result_of<PMS0C(const          S&),  int> ();
    126     test_result_of<PMS0C(               S*),  int> ();
    127     test_result_of<PMS0C(const          S*),  int> ();
    128     test_result_of<PMS0C(               S*&), int> ();
    129     test_result_of<PMS0C(const          S*&), int> ();
    130     test_result_of<PMS0C(std::unique_ptr<S>), int> ();
    131     test_no_result<PMS0C(volatile       S&)>();
    132     test_no_result<PMS0C(const volatile S&)>();
    133 
    134     test_result_of<PMS1C(               S,   int), int*> ();
    135     test_result_of<PMS1C(               S&,  int), int*> ();
    136     test_result_of<PMS1C(const          S&,  int), int*> ();
    137     test_result_of<PMS1C(               S*,  int), int*> ();
    138     test_result_of<PMS1C(const          S*,  int), int*> ();
    139     test_result_of<PMS1C(               S*&, int), int*> ();
    140     test_result_of<PMS1C(const          S*&, int), int*> ();
    141     test_result_of<PMS1C(std::unique_ptr<S>, int), int*> ();
    142     test_no_result<PMS1C(volatile       S&, int)>();
    143     test_no_result<PMS1C(const volatile S&, int)>();
    144 
    145     test_result_of<PMS2C(               S,   int, int), int&> ();
    146     test_result_of<PMS2C(               S&,  int, int), int&> ();
    147     test_result_of<PMS2C(const          S&,  int, int), int&> ();
    148     test_result_of<PMS2C(               S*,  int, int), int&> ();
    149     test_result_of<PMS2C(const          S*,  int, int), int&> ();
    150     test_result_of<PMS2C(               S*&, int, int), int&> ();
    151     test_result_of<PMS2C(const          S*&, int, int), int&> ();
    152     test_result_of<PMS2C(std::unique_ptr<S>, int, int), int&> ();
    153     test_no_result<PMS2C(volatile       S&, int, int)>();
    154     test_no_result<PMS2C(const volatile S&, int, int)>();
    155 
    156     typedef int       (S::*PMS0V)() volatile;
    157     typedef int*       (S::*PMS1V)(long) volatile;
    158     typedef int&       (S::*PMS2V)(long, int) volatile;
    159     test_result_of<PMS0V(               S),   int> ();
    160     test_result_of<PMS0V(               S&),  int> ();
    161     test_result_of<PMS0V(volatile       S&),  int> ();
    162     test_result_of<PMS0V(               S*),  int> ();
    163     test_result_of<PMS0V(volatile       S*),  int> ();
    164     test_result_of<PMS0V(               S*&), int> ();
    165     test_result_of<PMS0V(volatile       S*&), int> ();
    166     test_result_of<PMS0V(std::unique_ptr<S>), int> ();
    167     test_no_result<PMS0V(const          S&)>();
    168     test_no_result<PMS0V(const volatile S&)>();
    169 
    170     test_result_of<PMS1V(               S,   int), int*> ();
    171     test_result_of<PMS1V(               S&,  int), int*> ();
    172     test_result_of<PMS1V(volatile       S&,  int), int*> ();
    173     test_result_of<PMS1V(               S*,  int), int*> ();
    174     test_result_of<PMS1V(volatile       S*,  int), int*> ();
    175     test_result_of<PMS1V(               S*&, int), int*> ();
    176     test_result_of<PMS1V(volatile       S*&, int), int*> ();
    177     test_result_of<PMS1V(std::unique_ptr<S>, int), int*> ();
    178     test_no_result<PMS1V(const          S&, int)>();
    179     test_no_result<PMS1V(const volatile S&, int)>();
    180 
    181     test_result_of<PMS2V(               S,   int, int), int&> ();
    182     test_result_of<PMS2V(               S&,  int, int), int&> ();
    183     test_result_of<PMS2V(volatile       S&,  int, int), int&> ();
    184     test_result_of<PMS2V(               S*,  int, int), int&> ();
    185     test_result_of<PMS2V(volatile       S*,  int, int), int&> ();
    186     test_result_of<PMS2V(               S*&, int, int), int&> ();
    187     test_result_of<PMS2V(volatile       S*&, int, int), int&> ();
    188     test_result_of<PMS2V(std::unique_ptr<S>, int, int), int&> ();
    189     test_no_result<PMS2V(const          S&, int, int)>();
    190     test_no_result<PMS2V(const volatile S&, int, int)>();
    191 
    192     typedef int        (S::*PMS0CV)() const volatile;
    193     typedef int*       (S::*PMS1CV)(long) const volatile;
    194     typedef int&       (S::*PMS2CV)(long, int) const volatile;
    195     test_result_of<PMS0CV(               S),   int> ();
    196     test_result_of<PMS0CV(               S&),  int> ();
    197     test_result_of<PMS0CV(const          S&),  int> ();
    198     test_result_of<PMS0CV(volatile       S&),  int> ();
    199     test_result_of<PMS0CV(const volatile S&),  int> ();
    200     test_result_of<PMS0CV(               S*),  int> ();
    201     test_result_of<PMS0CV(const          S*),  int> ();
    202     test_result_of<PMS0CV(volatile       S*),  int> ();
    203     test_result_of<PMS0CV(const volatile S*),  int> ();
    204     test_result_of<PMS0CV(               S*&), int> ();
    205     test_result_of<PMS0CV(const          S*&), int> ();
    206     test_result_of<PMS0CV(volatile       S*&), int> ();
    207     test_result_of<PMS0CV(const volatile S*&), int> ();
    208     test_result_of<PMS0CV(std::unique_ptr<S>), int> ();
    209 
    210     test_result_of<PMS1CV(               S,   int), int*> ();
    211     test_result_of<PMS1CV(               S&,  int), int*> ();
    212     test_result_of<PMS1CV(const          S&,  int), int*> ();
    213     test_result_of<PMS1CV(volatile       S&,  int), int*> ();
    214     test_result_of<PMS1CV(const volatile S&,  int), int*> ();
    215     test_result_of<PMS1CV(               S*,  int), int*> ();
    216     test_result_of<PMS1CV(const          S*,  int), int*> ();
    217     test_result_of<PMS1CV(volatile       S*,  int), int*> ();
    218     test_result_of<PMS1CV(const volatile S*,  int), int*> ();
    219     test_result_of<PMS1CV(               S*&, int), int*> ();
    220     test_result_of<PMS1CV(const          S*&, int), int*> ();
    221     test_result_of<PMS1CV(volatile       S*&, int), int*> ();
    222     test_result_of<PMS1CV(const volatile S*&, int), int*> ();
    223     test_result_of<PMS1CV(std::unique_ptr<S>, int), int*> ();
    224 
    225     test_result_of<PMS2CV(               S,   int, int), int&> ();
    226     test_result_of<PMS2CV(               S&,  int, int), int&> ();
    227     test_result_of<PMS2CV(const          S&,  int, int), int&> ();
    228     test_result_of<PMS2CV(volatile       S&,  int, int), int&> ();
    229     test_result_of<PMS2CV(const volatile S&,  int, int), int&> ();
    230     test_result_of<PMS2CV(               S*,  int, int), int&> ();
    231     test_result_of<PMS2CV(const          S*,  int, int), int&> ();
    232     test_result_of<PMS2CV(volatile       S*,  int, int), int&> ();
    233     test_result_of<PMS2CV(const volatile S*,  int, int), int&> ();
    234     test_result_of<PMS2CV(               S*&, int, int), int&> ();
    235     test_result_of<PMS2CV(const          S*&, int, int), int&> ();
    236     test_result_of<PMS2CV(volatile       S*&, int, int), int&> ();
    237     test_result_of<PMS2CV(const volatile S*&, int, int), int&> ();
    238     test_result_of<PMS2CV(std::unique_ptr<S>, int, int), int&> ();
    239     }
    240     { // pointer to member data
    241     typedef char S::*PMD;
    242     test_result_of<PMD(S&), char &>();
    243     test_result_of<PMD(S*), char &>();
    244     test_result_of<PMD(S* const), char &>();
    245     test_result_of<PMD(const S&), const char&> ();
    246     test_result_of<PMD(const S*), const char&> ();
    247     test_result_of<PMD(volatile S&), volatile char&> ();
    248     test_result_of<PMD(volatile S*), volatile char&> ();
    249     test_result_of<PMD(const volatile S&), const volatile char&> ();
    250     test_result_of<PMD(const volatile S*), const volatile char&> ();
    251     }
    252 }
    253