1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // has weak result type
15 // REQUIRES: c++03 || c++11 || c++14 || c++17
17 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
20 #include <type_traits>
22 #include "test_macros.h"
24 template <class Arg
, class Result
>
25 struct my_unary_function
26 { // std::unary_function was removed in C++17
27 typedef Arg argument_type
;
28 typedef Result result_type
;
31 template <class Arg1
, class Arg2
, class Result
>
32 struct my_binary_function
33 { // std::binary_function was removed in C++17
34 typedef Arg1 first_argument_type
;
35 typedef Arg2 second_argument_type
;
36 typedef Result result_type
;
40 : public my_unary_function
<int, char>
45 : public my_binary_function
<char, int, double>
50 : public my_unary_function
<char, int>,
51 public my_binary_function
<char, int, double>
54 typedef float result_type
;
58 : public my_unary_function
<char, int>,
59 public my_binary_function
<char, int, double>
67 struct has_result_type
70 struct two
{char _
; char __
;};
71 template <class U
> static two
test(...);
72 template <class U
> static char test(typename
U::result_type
* = 0);
74 static const bool value
= sizeof(test
<T
>(0)) == 1;
79 static_assert((std::is_same
<std::reference_wrapper
<functor1
>::result_type
,
81 static_assert((std::is_same
<std::reference_wrapper
<functor2
>::result_type
,
83 static_assert((std::is_same
<std::reference_wrapper
<functor3
>::result_type
,
85 static_assert((std::is_same
<std::reference_wrapper
<void()>::result_type
,
87 static_assert((std::is_same
<std::reference_wrapper
<int*(double*)>::result_type
,
89 static_assert((std::is_same
<std::reference_wrapper
<void(*)()>::result_type
,
91 static_assert((std::is_same
<std::reference_wrapper
<int*(*)(double*)>::result_type
,
93 static_assert((std::is_same
<std::reference_wrapper
<int*(C::*)(double*)>::result_type
,
95 static_assert((std::is_same
<std::reference_wrapper
<int (C::*)(double*) const volatile>::result_type
,
97 static_assert((std::is_same
<std::reference_wrapper
<C()>::result_type
,
99 static_assert(has_result_type
<std::reference_wrapper
<functor3
> >::value
, "");
100 static_assert(!has_result_type
<std::reference_wrapper
<functor4
> >::value
, "");
101 static_assert(!has_result_type
<std::reference_wrapper
<C
> >::value
, "");