[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / utilities / function.objects / refwrap / weak_result.pass.cpp
blob512d4e62ba8b851be0412b7130c56df6facf0411
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <functional>
11 // reference_wrapper
13 // has weak result type
15 // REQUIRES: c++03 || c++11 || c++14 || c++17
17 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
19 #include <functional>
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;
39 class functor1
40 : public my_unary_function<int, char>
44 class functor2
45 : public my_binary_function<char, int, double>
49 class functor3
50 : public my_unary_function<char, int>,
51 public my_binary_function<char, int, double>
53 public:
54 typedef float result_type;
57 class functor4
58 : public my_unary_function<char, int>,
59 public my_binary_function<char, int, double>
61 public:
64 class C {};
66 template <class T>
67 struct has_result_type
69 private:
70 struct two {char _; char __;};
71 template <class U> static two test(...);
72 template <class U> static char test(typename U::result_type* = 0);
73 public:
74 static const bool value = sizeof(test<T>(0)) == 1;
77 int main(int, char**)
79 static_assert((std::is_same<std::reference_wrapper<functor1>::result_type,
80 char>::value), "");
81 static_assert((std::is_same<std::reference_wrapper<functor2>::result_type,
82 double>::value), "");
83 static_assert((std::is_same<std::reference_wrapper<functor3>::result_type,
84 float>::value), "");
85 static_assert((std::is_same<std::reference_wrapper<void()>::result_type,
86 void>::value), "");
87 static_assert((std::is_same<std::reference_wrapper<int*(double*)>::result_type,
88 int*>::value), "");
89 static_assert((std::is_same<std::reference_wrapper<void(*)()>::result_type,
90 void>::value), "");
91 static_assert((std::is_same<std::reference_wrapper<int*(*)(double*)>::result_type,
92 int*>::value), "");
93 static_assert((std::is_same<std::reference_wrapper<int*(C::*)(double*)>::result_type,
94 int*>::value), "");
95 static_assert((std::is_same<std::reference_wrapper<int (C::*)(double*) const volatile>::result_type,
96 int>::value), "");
97 static_assert((std::is_same<std::reference_wrapper<C()>::result_type,
98 C>::value), "");
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, "");
103 return 0;