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 // UNSUPPORTED: c++98, c++03 11 // 12 // <functional> 13 // 14 // result_of<Fn(ArgTypes...)> 15 16 #include <type_traits> 17 #include <memory> 18 #include <utility> 19 #include "test_macros.h" 20 21 struct wat 22 { 23 wat& operator*() { return *this; } 24 void foo(); 25 }; 26 27 struct F {}; 28 struct FD : public F {}; 29 30 template <class T, class U> 31 void test_result_of_imp() 32 { 33 static_assert((std::is_same<typename std::result_of<T>::type, U>::value), ""); 34 #if TEST_STD_VER > 11 35 static_assert((std::is_same<std::result_of_t<T>, U>::value), ""); 36 #endif 37 #if TEST_STD_VER > 14 38 static_assert(std::is_callable<T>::value, ""); 39 static_assert(std::is_callable<T, U>::value, ""); 40 #endif 41 } 42 43 int main() 44 { 45 { 46 typedef char F::*PMD; 47 test_result_of_imp<PMD(F &), char &>(); 48 test_result_of_imp<PMD(F const &), char const &>(); 49 test_result_of_imp<PMD(F volatile &), char volatile &>(); 50 test_result_of_imp<PMD(F const volatile &), char const volatile &>(); 51 52 test_result_of_imp<PMD(F &&), char &&>(); 53 test_result_of_imp<PMD(F const &&), char const &&>(); 54 test_result_of_imp<PMD(F volatile &&), char volatile &&>(); 55 test_result_of_imp<PMD(F const volatile &&), char const volatile &&>(); 56 57 test_result_of_imp<PMD(F ), char &&>(); 58 test_result_of_imp<PMD(F const ), char &&>(); 59 test_result_of_imp<PMD(F volatile ), char &&>(); 60 test_result_of_imp<PMD(F const volatile ), char &&>(); 61 62 test_result_of_imp<PMD(FD &), char &>(); 63 test_result_of_imp<PMD(FD const &), char const &>(); 64 test_result_of_imp<PMD(FD volatile &), char volatile &>(); 65 test_result_of_imp<PMD(FD const volatile &), char const volatile &>(); 66 67 test_result_of_imp<PMD(FD &&), char &&>(); 68 test_result_of_imp<PMD(FD const &&), char const &&>(); 69 test_result_of_imp<PMD(FD volatile &&), char volatile &&>(); 70 test_result_of_imp<PMD(FD const volatile &&), char const volatile &&>(); 71 72 test_result_of_imp<PMD(FD ), char &&>(); 73 test_result_of_imp<PMD(FD const ), char &&>(); 74 test_result_of_imp<PMD(FD volatile ), char &&>(); 75 test_result_of_imp<PMD(FD const volatile ), char &&>(); 76 77 test_result_of_imp<PMD(std::unique_ptr<F>), char &>(); 78 test_result_of_imp<PMD(std::unique_ptr<F const>), const char &>(); 79 test_result_of_imp<PMD(std::unique_ptr<FD>), char &>(); 80 test_result_of_imp<PMD(std::unique_ptr<FD const>), const char &>(); 81 82 test_result_of_imp<PMD(std::reference_wrapper<F>), char &>(); 83 test_result_of_imp<PMD(std::reference_wrapper<F const>), const char &>(); 84 test_result_of_imp<PMD(std::reference_wrapper<FD>), char &>(); 85 test_result_of_imp<PMD(std::reference_wrapper<FD const>), const char &>(); 86 } 87 { 88 test_result_of_imp<int (F::* (F &)) () &, int> (); 89 test_result_of_imp<int (F::* (F &)) () const &, int> (); 90 test_result_of_imp<int (F::* (F &)) () volatile &, int> (); 91 test_result_of_imp<int (F::* (F &)) () const volatile &, int> (); 92 test_result_of_imp<int (F::* (F const &)) () const &, int> (); 93 test_result_of_imp<int (F::* (F const &)) () const volatile &, int> (); 94 test_result_of_imp<int (F::* (F volatile &)) () volatile &, int> (); 95 test_result_of_imp<int (F::* (F volatile &)) () const volatile &, int> (); 96 test_result_of_imp<int (F::* (F const volatile &)) () const volatile &, int> (); 97 98 test_result_of_imp<int (F::* (F &&)) () &&, int> (); 99 test_result_of_imp<int (F::* (F &&)) () const &&, int> (); 100 test_result_of_imp<int (F::* (F &&)) () volatile &&, int> (); 101 test_result_of_imp<int (F::* (F &&)) () const volatile &&, int> (); 102 test_result_of_imp<int (F::* (F const &&)) () const &&, int> (); 103 test_result_of_imp<int (F::* (F const &&)) () const volatile &&, int> (); 104 test_result_of_imp<int (F::* (F volatile &&)) () volatile &&, int> (); 105 test_result_of_imp<int (F::* (F volatile &&)) () const volatile &&, int> (); 106 test_result_of_imp<int (F::* (F const volatile &&)) () const volatile &&, int> (); 107 108 test_result_of_imp<int (F::* (F )) () &&, int> (); 109 test_result_of_imp<int (F::* (F )) () const &&, int> (); 110 test_result_of_imp<int (F::* (F )) () volatile &&, int> (); 111 test_result_of_imp<int (F::* (F )) () const volatile &&, int> (); 112 test_result_of_imp<int (F::* (F const )) () const &&, int> (); 113 test_result_of_imp<int (F::* (F const )) () const volatile &&, int> (); 114 test_result_of_imp<int (F::* (F volatile )) () volatile &&, int> (); 115 test_result_of_imp<int (F::* (F volatile )) () const volatile &&, int> (); 116 test_result_of_imp<int (F::* (F const volatile )) () const volatile &&, int> (); 117 } 118 { 119 test_result_of_imp<int (F::* (FD &)) () &, int> (); 120 test_result_of_imp<int (F::* (FD &)) () const &, int> (); 121 test_result_of_imp<int (F::* (FD &)) () volatile &, int> (); 122 test_result_of_imp<int (F::* (FD &)) () const volatile &, int> (); 123 test_result_of_imp<int (F::* (FD const &)) () const &, int> (); 124 test_result_of_imp<int (F::* (FD const &)) () const volatile &, int> (); 125 test_result_of_imp<int (F::* (FD volatile &)) () volatile &, int> (); 126 test_result_of_imp<int (F::* (FD volatile &)) () const volatile &, int> (); 127 test_result_of_imp<int (F::* (FD const volatile &)) () const volatile &, int> (); 128 129 test_result_of_imp<int (F::* (FD &&)) () &&, int> (); 130 test_result_of_imp<int (F::* (FD &&)) () const &&, int> (); 131 test_result_of_imp<int (F::* (FD &&)) () volatile &&, int> (); 132 test_result_of_imp<int (F::* (FD &&)) () const volatile &&, int> (); 133 test_result_of_imp<int (F::* (FD const &&)) () const &&, int> (); 134 test_result_of_imp<int (F::* (FD const &&)) () const volatile &&, int> (); 135 test_result_of_imp<int (F::* (FD volatile &&)) () volatile &&, int> (); 136 test_result_of_imp<int (F::* (FD volatile &&)) () const volatile &&, int> (); 137 test_result_of_imp<int (F::* (FD const volatile &&)) () const volatile &&, int> (); 138 139 test_result_of_imp<int (F::* (FD )) () &&, int> (); 140 test_result_of_imp<int (F::* (FD )) () const &&, int> (); 141 test_result_of_imp<int (F::* (FD )) () volatile &&, int> (); 142 test_result_of_imp<int (F::* (FD )) () const volatile &&, int> (); 143 test_result_of_imp<int (F::* (FD const )) () const &&, int> (); 144 test_result_of_imp<int (F::* (FD const )) () const volatile &&, int> (); 145 test_result_of_imp<int (F::* (FD volatile )) () volatile &&, int> (); 146 test_result_of_imp<int (F::* (FD volatile )) () const volatile &&, int> (); 147 test_result_of_imp<int (F::* (FD const volatile )) () const volatile &&, int> (); 148 } 149 { 150 test_result_of_imp<int (F::* (std::reference_wrapper<F>)) (), int>(); 151 test_result_of_imp<int (F::* (std::reference_wrapper<const F>)) () const, int>(); 152 test_result_of_imp<int (F::* (std::unique_ptr<F> )) (), int>(); 153 test_result_of_imp<int (F::* (std::unique_ptr<const F> )) () const, int>(); 154 } 155 test_result_of_imp<decltype(&wat::foo)(wat), void>(); 156 } 157