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 
     17 typedef bool (&PF1)();
     18 typedef short (*PF2)(long);
     19 
     20 struct S
     21 {
     22     operator PF2() const;
     23     double operator()(char, int&);
     24     void calc(long) const;
     25     char data_;
     26 };
     27 
     28 typedef void (S::*PMS)(long) const;
     29 typedef char S::*PMD;
     30 
     31 struct wat
     32 {
     33     wat& operator*() { return *this; }
     34     void foo();
     35 };
     36 
     37 struct F {};
     38 
     39 template <class T, class U>
     40 void test_result_of_imp()
     41 {
     42     static_assert((std::is_same<typename std::result_of<T>::type, U>::value), "");
     43 #if _LIBCPP_STD_VER > 11
     44     static_assert((std::is_same<std::result_of_t<T>, U>::value), "");
     45 #endif
     46 }
     47 
     48 int main()
     49 {
     50     test_result_of_imp<S(int), short> ();
     51     test_result_of_imp<S&(unsigned char, int&), double> ();
     52     test_result_of_imp<PF1(), bool> ();
     53     test_result_of_imp<PMS(std::unique_ptr<S>, int), void> ();
     54     test_result_of_imp<PMS(S, int), void> ();
     55     test_result_of_imp<PMS(const S&, int), void> ();
     56 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     57     test_result_of_imp<PMD(S), char&&> ();
     58 #endif
     59     test_result_of_imp<PMD(const S*), const char&> ();
     60 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     61     test_result_of_imp<int (F::* (F       &)) ()       &, int> ();
     62     test_result_of_imp<int (F::* (F       &)) () const &, int> ();
     63     test_result_of_imp<int (F::* (F const &)) () const &, int> ();
     64     test_result_of_imp<int (F::* (F      &&)) ()      &&, int> ();
     65     test_result_of_imp<int (F::* (F      &&)) () const&&, int> ();
     66     test_result_of_imp<int (F::* (F const&&)) () const&&, int> ();
     67 #endif
     68 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
     69     using type1 = std::result_of<decltype(&wat::foo)(wat)>::type;
     70 #endif
     71 #if _LIBCPP_STD_VER > 11
     72     using type2 = std::result_of_t<decltype(&wat::foo)(wat)>;
     73 #endif
     74 
     75 
     76 
     77     static_assert((std::is_same<std::result_of<S(int)>::type, short>::value), "Error!");
     78     static_assert((std::is_same<std::result_of<S&(unsigned char, int&)>::type, double>::value), "Error!");
     79     static_assert((std::is_same<std::result_of<PF1()>::type, bool>::value), "Error!");
     80     static_assert((std::is_same<std::result_of<PMS(std::unique_ptr<S>, int)>::type, void>::value), "Error!");
     81     static_assert((std::is_same<std::result_of<PMS(S, int)>::type, void>::value), "Error!");
     82     static_assert((std::is_same<std::result_of<PMS(const S&, int)>::type, void>::value), "Error!");
     83 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     84     static_assert((std::is_same<std::result_of<PMD(S)>::type, char&&>::value), "Error!");
     85 #endif
     86     static_assert((std::is_same<std::result_of<PMD(const S*)>::type, const char&>::value), "Error!");
     87 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     88     static_assert((std::is_same<std::result_of<int (F::* (F       &)) ()       &>::type, int>::value), "Error!");
     89     static_assert((std::is_same<std::result_of<int (F::* (F       &)) () const &>::type, int>::value), "Error!");
     90     static_assert((std::is_same<std::result_of<int (F::* (F const &)) () const &>::type, int>::value), "Error!");
     91     static_assert((std::is_same<std::result_of<int (F::* (F      &&)) ()      &&>::type, int>::value), "Error!");
     92     static_assert((std::is_same<std::result_of<int (F::* (F      &&)) () const&&>::type, int>::value), "Error!");
     93     static_assert((std::is_same<std::result_of<int (F::* (F const&&)) () const&&>::type, int>::value), "Error!");
     94 #endif
     95 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
     96     using type = std::result_of<decltype(&wat::foo)(wat)>::type;
     97 #endif
     98 }
     99