]>
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 | ||
19 | #include <functional> | |
20 | ||
21 | namespace boost_no_pointer_to_member_const{ | |
22 | ||
23 | template <class S, class T> | |
24 | class const_mem_fun_t : public std::unary_function<const T*, S> | |
25 | { | |
26 | public: | |
27 | explicit const_mem_fun_t(S (T::*p)() const) | |
28 | : | |
29 | ptr(p) | |
30 | {} | |
31 | S operator()(const T* p) const | |
32 | { | |
33 | return (p->*ptr)(); | |
34 | } | |
35 | private: | |
36 | S (T::*ptr)() const; | |
37 | }; | |
38 | ||
39 | template <class S, class T, class A> | |
40 | class const_mem_fun1_t : public std::binary_function<const T*, A, S> | |
41 | { | |
42 | public: | |
43 | explicit const_mem_fun1_t(S (T::*p)(A) const) | |
44 | : | |
45 | ptr(p) | |
46 | {} | |
47 | S operator()(const T* p, const A& x) const | |
48 | { | |
49 | return (p->*ptr)(x); | |
50 | } | |
51 | private: | |
52 | S (T::*ptr)(A) const; | |
53 | }; | |
54 | ||
55 | template<class S, class T> | |
56 | inline const_mem_fun_t<S,T> mem_fun(S (T::*f)() const) | |
57 | { | |
58 | return const_mem_fun_t<S,T>(f); | |
59 | } | |
60 | ||
61 | template<class S, class T, class A> | |
62 | inline const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const) | |
63 | { | |
64 | return const_mem_fun1_t<S,T,A>(f); | |
65 | } | |
66 | ||
67 | class tester | |
68 | { | |
69 | public: | |
70 | void foo1()const{} | |
71 | int foo2(int i)const{ return i*2; } | |
72 | }; | |
73 | ||
74 | ||
75 | int test() | |
76 | { | |
77 | boost_no_pointer_to_member_const::mem_fun(&tester::foo1); | |
78 | boost_no_pointer_to_member_const::mem_fun(&tester::foo2); | |
79 | return 0; | |
80 | } | |
81 | ||
82 | } | |
83 | ||
84 | ||
85 | ||
86 |