[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / utilities / function.objects / func.memfn / member_function_const.pass.cpp
blob057998c7e6e555e4c1a729d78a1d954ac253e8cd
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...) const);
14 #include <functional>
15 #include <cassert>
17 #include "test_macros.h"
19 struct A
21 TEST_CONSTEXPR char test0() const {return 'a';}
22 TEST_CONSTEXPR char test1(int) const {return 'b';}
23 TEST_CONSTEXPR char test2(int, double) const {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 A* cap = &a;
36 assert(f(cap) == 'a');
37 const F& cf = f;
38 assert(cf(ap) == 'a');
40 return true;
43 template <class F>
44 TEST_CONSTEXPR_CXX20 bool
45 test1(F f)
48 A a;
49 assert(f(a, 1) == 'b');
50 A* ap = &a;
51 assert(f(ap, 2) == 'b');
52 const A* cap = &a;
53 assert(f(cap, 2) == 'b');
54 const F& cf = f;
55 assert(cf(ap, 2) == 'b');
57 return true;
60 template <class F>
61 TEST_CONSTEXPR_CXX20 bool
62 test2(F f)
65 A a;
66 assert(f(a, 1, 2) == 'c');
67 A* ap = &a;
68 assert(f(ap, 2, 3.5) == 'c');
69 const A* cap = &a;
70 assert(f(cap, 2, 3.5) == 'c');
71 const F& cf = f;
72 assert(cf(ap, 2, 3.5) == 'c');
74 return true;
77 int main(int, char**)
79 test0(std::mem_fn(&A::test0));
80 test1(std::mem_fn(&A::test1));
81 test2(std::mem_fn(&A::test2));
83 #if TEST_STD_VER >= 20
84 static_assert(test0(std::mem_fn(&A::test0)));
85 static_assert(test1(std::mem_fn(&A::test1)));
86 static_assert(test2(std::mem_fn(&A::test2)));
87 #endif
89 return 0;