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 //===----------------------------------------------------------------------===//
8 
9 // <functional>
10 
11 // template<Returnable R, class T> unspecified mem_fn(R T::* pm);
12 
13 #include <functional>
14 #include <cassert>
15 
16 #include "test_macros.h"
17 
18 struct A
19 {
20     double data_;
21 };
22 
23 template <class F>
24 TEST_CONSTEXPR_CXX20 bool
25 test(F f)
26 {
27     {
28     A a = {0.0};
29     f(a) = 5;
30     assert(a.data_ == 5);
31     A* ap = &a;
32     f(ap) = 6;
33     assert(a.data_ == 6);
34     const A* cap = ap;
35     assert(f(cap) == f(ap));
36     const F& cf = f;
37     assert(cf(ap) == f(ap));
38     }
39     return true;
40 }
41 
42 int main(int, char**)
43 {
44     test(std::mem_fn(&A::data_));
45 
46 #if TEST_STD_VER >= 20
47     static_assert(test(std::mem_fn(&A::data_)));
48 #endif
49 
50     return 0;
51 }
52