Upstream version 8.36.169.0
[platform/framework/web/crosswalk.git] / src / third_party / libc++ / trunk / test / utilities / function.objects / func.memfn / member_function_const_volatile.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <functional>
11
12 // template<Returnable R, class T, CopyConstructible... Args>
13 //   unspecified mem_fn(R (T::* pm)(Args...) const volatile);
14
15 #include <functional>
16 #include <cassert>
17
18 struct A
19 {
20     char test0() const volatile {return 'a';}
21     char test1(int) const volatile {return 'b';}
22     char test2(int, double) const volatile {return 'c';}
23 };
24
25 template <class F>
26 void
27 test0(F f)
28 {
29     {
30     A a;
31     assert(f(a) == 'a');
32     A* ap = &a;
33     assert(f(ap) == 'a');
34     const volatile A* cap = &a;
35     assert(f(cap) == 'a');
36     const F& cf = f;
37     assert(cf(ap) == 'a');
38     }
39 }
40
41 template <class F>
42 void
43 test1(F f)
44 {
45     {
46     A a;
47     assert(f(a, 1) == 'b');
48     A* ap = &a;
49     assert(f(ap, 2) == 'b');
50     const volatile A* cap = &a;
51     assert(f(cap, 2) == 'b');
52     const F& cf = f;
53     assert(cf(ap, 2) == 'b');
54     }
55 }
56
57 template <class F>
58 void
59 test2(F f)
60 {
61     {
62     A a;
63     assert(f(a, 1, 2) == 'c');
64     A* ap = &a;
65     assert(f(ap, 2, 3.5) == 'c');
66     const volatile A* cap = &a;
67     assert(f(cap, 2, 3.5) == 'c');
68     const F& cf = f;
69     assert(cf(ap, 2, 3.5) == 'c');
70     }
71 }
72
73 int main()
74 {
75     test0(std::mem_fn(&A::test0));
76     test1(std::mem_fn(&A::test1));
77     test2(std::mem_fn(&A::test2));
78 }