member_function_const_volatile.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===//
2//
3// ��������������������The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. 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
18struct 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
25template <class F>
26void
27test0(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    }
37}
38
39template <class F>
40void
41test1(F f)
42{
43    {
44    A a;
45    assert(f(a, 1) == 'b');
46    A* ap = &a;
47    assert(f(ap, 2) == 'b');
48    const volatile A* cap = &a;
49    assert(f(cap, 2) == 'b');
50    }
51}
52
53template <class F>
54void
55test2(F f)
56{
57    {
58    A a;
59    assert(f(a, 1, 2) == 'c');
60    A* ap = &a;
61    assert(f(ap, 2, 3.5) == 'c');
62    const volatile A* cap = &a;
63    assert(f(cap, 2, 3.5) == 'c');
64    }
65}
66
67int main()
68{
69    test0(std::mem_fn(&A::test0));
70    test1(std::mem_fn(&A::test1));
71    test2(std::mem_fn(&A::test2));
72}
73