[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / utilities / function.objects / func.memfn / member_function.pass.cpp
blob88d4108e10ac0a7a2167b868633852e709dfe02f
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 // template<Returnable R, class T, CopyConstructible... Args>
12 // unspecified mem_fn(R (T::* pm)(Args...));
14 #include <functional>
15 #include <cassert>
17 #include "test_macros.h"
19 struct A
21 TEST_CONSTEXPR_CXX14 char test0() {return 'a';}
22 TEST_CONSTEXPR_CXX14 char test1(int) {return 'b';}
23 TEST_CONSTEXPR_CXX14 char test2(int, double) {return 'c';}
26 template <class F>
27 TEST_CONSTEXPR_CXX20 bool
28 test0(F f)
31 A a;
32 assert(f(a) == 'a');
33 A* ap = &a;
34 assert(f(ap) == 'a');
35 const F& cf = f;
36 assert(cf(ap) == 'a');
38 return true;
41 template <class F>
42 TEST_CONSTEXPR_CXX20 bool
43 test1(F f)
46 A a;
47 assert(f(a, 1) == 'b');
48 A* ap = &a;
49 assert(f(ap, 2) == 'b');
50 const F& cf = f;
51 assert(cf(ap, 2) == 'b');
53 return true;
56 template <class F>
57 TEST_CONSTEXPR_CXX20 bool
58 test2(F f)
61 A a;
62 assert(f(a, 1, 2) == 'c');
63 A* ap = &a;
64 assert(f(ap, 2, 3.5) == 'c');
65 const F& cf = f;
66 assert(cf(ap, 2, 3.5) == 'c');
68 return true;
71 int main(int, char**)
73 test0(std::mem_fn(&A::test0));
74 test1(std::mem_fn(&A::test1));
75 test2(std::mem_fn(&A::test2));
76 #if TEST_STD_VER >= 11
77 static_assert((noexcept(std::mem_fn(&A::test0))), ""); // LWG#2489
78 #endif
80 #if TEST_STD_VER >= 20
81 static_assert(test0(std::mem_fn(&A::test0)));
82 static_assert(test1(std::mem_fn(&A::test1)));
83 static_assert(test2(std::mem_fn(&A::test2)));
84 #endif
86 return 0;