Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <functional> |
| 11 | |
| 12 | // template<Returnable R, class T> unspecified mem_fn(R T::* pm); |
| 13 | |
| 14 | #include <functional> |
| 15 | #include <cassert> |
| 16 | |
| 17 | struct A |
| 18 | { |
| 19 | double data_; |
| 20 | }; |
| 21 | |
| 22 | template <class F> |
| 23 | void |
| 24 | test(F f) |
| 25 | { |
| 26 | { |
| 27 | A a; |
| 28 | f(a) = 5; |
| 29 | assert(a.data_ == 5); |
| 30 | A* ap = &a; |
| 31 | f(ap) = 6; |
| 32 | assert(a.data_ == 6); |
| 33 | const A* cap = ap; |
| 34 | assert(f(cap) == f(ap)); |
Peter Collingbourne | a5adf48 | 2014-01-22 22:56:52 +0000 | [diff] [blame] | 35 | const F& cf = f; |
| 36 | assert(cf(ap) == f(ap)); |
Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
| 40 | int main() |
| 41 | { |
| 42 | test(std::mem_fn(&A::data_)); |
| 43 | } |