]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright (c) 2000 |
2 | // Cadenza New Zealand Ltd | |
3 | // | |
4 | // (C) Copyright John Maddock 2001. | |
5 | // | |
6 | // Use, modification and distribution are subject to the | |
7 | // Boost Software License, Version 1.0. (See accompanying file | |
8 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
9 | ||
10 | // See http://www.boost.org/libs/config for the most recent version. | |
11 | ||
12 | // MACRO: BOOST_NO_POINTER_TO_MEMBER_CONST | |
13 | // TITLE: pointers to const member functions | |
14 | // DESCRIPTION: The compiler does not correctly handle | |
15 | // pointers to const member functions, preventing use | |
16 | // of these in overloaded function templates. | |
17 | // See boost/functional.hpp for example. | |
18 | ||
7c673cae FG |
19 | namespace boost_no_pointer_to_member_const{ |
20 | ||
21 | template <class S, class T> | |
b32b8144 | 22 | class const_mem_fun_t |
7c673cae FG |
23 | { |
24 | public: | |
25 | explicit const_mem_fun_t(S (T::*p)() const) | |
26 | : | |
27 | ptr(p) | |
28 | {} | |
29 | S operator()(const T* p) const | |
30 | { | |
31 | return (p->*ptr)(); | |
32 | } | |
33 | private: | |
34 | S (T::*ptr)() const; | |
35 | }; | |
36 | ||
37 | template <class S, class T, class A> | |
b32b8144 | 38 | class const_mem_fun1_t |
7c673cae FG |
39 | { |
40 | public: | |
41 | explicit const_mem_fun1_t(S (T::*p)(A) const) | |
42 | : | |
43 | ptr(p) | |
44 | {} | |
45 | S operator()(const T* p, const A& x) const | |
46 | { | |
47 | return (p->*ptr)(x); | |
48 | } | |
49 | private: | |
50 | S (T::*ptr)(A) const; | |
51 | }; | |
52 | ||
53 | template<class S, class T> | |
54 | inline const_mem_fun_t<S,T> mem_fun(S (T::*f)() const) | |
55 | { | |
56 | return const_mem_fun_t<S,T>(f); | |
57 | } | |
58 | ||
59 | template<class S, class T, class A> | |
60 | inline const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const) | |
61 | { | |
62 | return const_mem_fun1_t<S,T,A>(f); | |
63 | } | |
64 | ||
65 | class tester | |
66 | { | |
67 | public: | |
68 | void foo1()const{} | |
69 | int foo2(int i)const{ return i*2; } | |
70 | }; | |
71 | ||
72 | ||
73 | int test() | |
74 | { | |
75 | boost_no_pointer_to_member_const::mem_fun(&tester::foo1); | |
76 | boost_no_pointer_to_member_const::mem_fun(&tester::foo2); | |
77 | return 0; | |
78 | } | |
79 | ||
80 | } | |
81 | ||
82 | ||
83 | ||
84 |