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 template <class T, class U> 38 void test_result_of_imp() 39 { 40 static_assert((std::is_same<typename std::result_of<T>::type, U>::value), ""); 41 #if _LIBCPP_STD_VER > 11 42 static_assert((std::is_same<std::result_of_t<T>, U>::value), ""); 43 #endif 44 } 45 46 int main() 47 { 48 test_result_of_imp<S(int), short> (); 49 test_result_of_imp<S&(unsigned char, int&), double> (); 50 test_result_of_imp<PF1(), bool> (); 51 test_result_of_imp<PMS(std::unique_ptr<S>, int), void> (); 52 test_result_of_imp<PMS(S, int), void> (); 53 test_result_of_imp<PMS(const S&, int), void> (); 54 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 55 test_result_of_imp<PMD(S), char&&> (); 56 #endif 57 test_result_of_imp<PMD(const S*), const char&> (); 58 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 59 using type1 = std::result_of<decltype(&wat::foo)(wat)>::type; 60 #endif 61 #if _LIBCPP_STD_VER > 11 62 using type2 = std::result_of_t<decltype(&wat::foo)(wat)>; 63 #endif 64 65 66 67 static_assert((std::is_same<std::result_of<S(int)>::type, short>::value), "Error!"); 68 static_assert((std::is_same<std::result_of<S&(unsigned char, int&)>::type, double>::value), "Error!"); 69 static_assert((std::is_same<std::result_of<PF1()>::type, bool>::value), "Error!"); 70 static_assert((std::is_same<std::result_of<PMS(std::unique_ptr<S>, int)>::type, void>::value), "Error!"); 71 static_assert((std::is_same<std::result_of<PMS(S, int)>::type, void>::value), "Error!"); 72 static_assert((std::is_same<std::result_of<PMS(const S&, int)>::type, void>::value), "Error!"); 73 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 74 static_assert((std::is_same<std::result_of<PMD(S)>::type, char&&>::value), "Error!"); 75 #endif 76 static_assert((std::is_same<std::result_of<PMD(const S*)>::type, const char&>::value), "Error!"); 77 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 78 using type = std::result_of<decltype(&wat::foo)(wat)>::type; 79 #endif 80 } 81