//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // result_of #include #include #include #include "test_macros.h" struct S { typedef short (*FreeFunc)(long); operator FreeFunc() const; double operator()(char, int&); double const& operator()(char, int&) const; double volatile& operator()(char, int&) volatile; double const volatile& operator()(char, int&) const volatile; }; struct SD : public S { }; struct NotDerived {}; template struct Voider { typedef void type; }; template struct HasType : std::false_type {}; template struct HasType::type> : std::true_type {}; #if TEST_STD_VER > 14 template struct test_invoke_result; template struct test_invoke_result { static void call() { static_assert(std::is_invocable::value, ""); static_assert(std::is_invocable_r::value, ""); ASSERT_SAME_TYPE(Ret, typename std::invoke_result::type); } }; #endif template void test_result_of() { ASSERT_SAME_TYPE(U, typename std::result_of::type); #if TEST_STD_VER > 14 test_invoke_result::call(); #endif } #if TEST_STD_VER > 14 template struct test_invoke_no_result; template struct test_invoke_no_result { static void call() { static_assert(std::is_invocable::value == false, ""); static_assert((!HasType >::value), ""); } }; #endif template void test_no_result() { #if TEST_STD_VER >= 11 static_assert((!HasType >::value), ""); #endif #if TEST_STD_VER > 14 test_invoke_no_result::call(); #endif } int main(int, char**) { typedef NotDerived ND; { // functor object test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); } { // pointer to function typedef bool (&RF0)(); typedef bool* (&RF1)(int); typedef bool& (&RF2)(int, int); typedef bool const& (&RF3)(int, int, int); typedef bool (&RF4)(int, ...); typedef bool (*PF0)(); typedef bool* (*PF1)(int); typedef bool& (*PF2)(int, int); typedef bool const& (*PF3)(int, int, int); typedef bool (*PF4)(int, ...); typedef bool (*&PRF0)(); typedef bool* (*&PRF1)(int); typedef bool& (*&PRF2)(int, int); typedef bool const& (*&PRF3)(int, int, int); typedef bool (*&PRF4)(int, ...); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of(); } { // pointer to member function typedef int (S::*PMS0)(); typedef int* (S::*PMS1)(long); typedef int& (S::*PMS2)(long, int); typedef const int& (S::*PMS3)(int, ...); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of), int> (); test_result_of&), int> (); test_result_of), int> (); test_result_of&), int> (); test_result_of), int> (); test_result_of), int> (); test_no_result(); test_no_result(); test_no_result(); test_no_result(); test_no_result(); test_no_result )>(); test_no_result)>(); test_no_result )>(); test_no_result )>(); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of, int), int*> (); test_result_of, int), int*> (); test_result_of, int), int*> (); test_result_of&, int), int*> (); test_result_of, int), int*> (); test_result_of&, int), int*> (); test_no_result(); test_no_result(); test_no_result(); test_no_result(); test_no_result(); test_no_result, int)>(); test_no_result, int)>(); test_no_result, int)>(); test_no_result, int)>(); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of, int, int), int&> (); test_result_of, int, int), int&> (); test_result_of, int, int), int&> (); test_result_of&, int, int), int&> (); test_result_of, int, int), int&> (); test_result_of&, int, int), int&> (); test_no_result(); test_no_result(); test_no_result(); test_no_result, int, int)>(); test_no_result, int, int)>(); test_no_result(); test_no_result, int, int)>(); test_no_result, int, int)>(); test_result_of(); test_result_of(); typedef int (S::*PMS0C)() const; typedef int* (S::*PMS1C)(long) const; typedef int& (S::*PMS2C)(long, int) const; typedef const int& (S::*PMS3C)(int, ...) const; test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of), int> (); test_result_of), int> (); test_result_of ), int> (); test_result_of ), int> (); test_result_of & ), int> (); test_result_of &), int> (); test_result_of ), int> (); test_result_of ), int> (); test_result_of & ), int> (); test_result_of &), int> (); test_no_result(); test_no_result(); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of, int), int*> (); test_no_result(); test_no_result(); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of, int, int), int&> (); test_no_result(); test_no_result(); test_result_of(); test_result_of(); typedef int (S::*PMS0V)() volatile; typedef int* (S::*PMS1V)(long) volatile; typedef int& (S::*PMS2V)(long, int) volatile; typedef const int& (S::*PMS3V)(int, ...) volatile; test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of), int> (); test_no_result(); test_no_result(); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of, int), int*> (); test_no_result(); test_no_result(); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of, int, int), int&> (); test_no_result(); test_no_result(); test_result_of(); test_result_of(); typedef int (S::*PMS0CV)() const volatile; typedef int* (S::*PMS1CV)(long) const volatile; typedef int& (S::*PMS2CV)(long, int) const volatile; typedef const int& (S::*PMS3CV)(int, ...) const volatile; test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of), int> (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of, int), int*> (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of, int, int), int&> (); test_result_of(); test_result_of(); } { // pointer to member data typedef char S::*PMD; test_result_of(); test_result_of(); test_result_of(); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of (); test_result_of(); test_result_of(); test_result_of(); test_result_of(); test_result_of), char &>(); test_result_of), const char&>(); #if TEST_STD_VER >= 11 test_result_of), char&>(); test_result_of), const char&>(); #endif test_no_result(); } return 0; }