| 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, CopyConstructible... Args> |
| 12 |
// unspecified mem_fn(R (T::* pm)(Args...) const volatile); |
| 13 |
|
| 14 |
#include <functional> |
| 15 |
#include <cassert> |
| 16 |
|
| 17 |
#include "test_macros.h" |
| 18 |
|
| 19 |
struct A |
| 20 |
{ |
| 21 |
char test0() const volatile {return 'a';} |
| 22 |
char test1(int) const volatile {return 'b';} |
| 23 |
char test2(int, double) const volatile {return 'c';} |
| 24 |
}; |
| 25 |
|
| 26 |
template <class F> |
| 27 |
void |
| 28 |
test0(F f) |
| 29 |
{ |
| 30 |
{ |
| 31 |
A a; |
| 32 |
assert(f(a) == 'a'); |
| 33 |
A* ap = &a; |
| 34 |
assert(f(ap) == 'a'); |
| 35 |
const volatile A* cap = &a; |
| 36 |
assert(f(cap) == 'a'); |
| 37 |
const F& cf = f; |
| 38 |
assert(cf(ap) == 'a'); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
template <class F> |
| 43 |
void |
| 44 |
test1(F f) |
| 45 |
{ |
| 46 |
{ |
| 47 |
A a; |
| 48 |
assert(f(a, 1) == 'b'); |
| 49 |
A* ap = &a; |
| 50 |
assert(f(ap, 2) == 'b'); |
| 51 |
const volatile A* cap = &a; |
| 52 |
assert(f(cap, 2) == 'b'); |
| 53 |
const F& cf = f; |
| 54 |
assert(cf(ap, 2) == 'b'); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
template <class F> |
| 59 |
void |
| 60 |
test2(F f) |
| 61 |
{ |
| 62 |
{ |
| 63 |
A a; |
| 64 |
assert(f(a, 1, 2) == 'c'); |
| 65 |
A* ap = &a; |
| 66 |
assert(f(ap, 2, 3.5) == 'c'); |
| 67 |
const volatile A* cap = &a; |
| 68 |
assert(f(cap, 2, 3.5) == 'c'); |
| 69 |
const F& cf = f; |
| 70 |
assert(cf(ap, 2, 3.5) == 'c'); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
int main(int, char**) |
| 75 |
{ |
| 76 |
test0(std::mem_fn(&A::test0)); |
| 77 |
test1(std::mem_fn(&A::test1)); |
| 78 |
test2(std::mem_fn(&A::test2)); |
| 79 |
|
| 80 |
return 0; |
| 81 |
} |