Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / phoenix / bind / detail / member_variable.hpp
1 /*=============================================================================
2     Copyright (c) 2001-2007 Joel de Guzman
3
4     Distributed under the Boost Software License, Version 1.0. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #ifndef BOOST_PHOENIX_CORE_DETAIL_MEMBER_VARIABLE_HPP
8 #define BOOST_PHOENIX_CORE_DETAIL_MEMBER_VARIABLE_HPP
9
10 #include <boost/proto/detail/decltype.hpp>
11 #include <boost/type_traits/remove_pointer.hpp>
12
13 #ifdef _MSC_VER
14 #pragma warning(push)
15 #pragma warning(disable: 4180) // qualifier applied to function type has no meaning; ignored
16 #endif
17
18 namespace boost { namespace phoenix { namespace detail {
19
20         template <typename RT, typename MP>
21         struct member_variable
22         {
23             template <typename Sig>
24             struct result;
25
26             template <typename This, typename Class>
27             struct result<This(Class)>
28                 : result<This(Class const &)>
29             {};
30
31             template <typename This, typename Class>
32             struct result<This(Class &)>
33             {
34                 typedef typename boost::mpl::if_c<
35                     boost::is_const<
36                         typename boost::remove_pointer<
37                             typename boost::remove_reference<Class>::type
38                         >::type
39                     >::value
40                   , const RT&
41                   , RT&
42                 >::type
43                 type;
44             };
45
46             member_variable(MP mp_)
47                 : mp(mp_) {}
48
49             template <typename Class>
50             RT& operator()(Class& obj) const
51             {
52                 BOOST_PROTO_USE_GET_POINTER();
53
54                 typedef typename proto::detail::class_member_traits<MP>::class_type class_type;
55                 return (BOOST_PROTO_GET_POINTER(class_type, obj)->*mp);
56             }
57
58             template <typename Class>
59             RT& operator()(Class* obj) const
60             {
61                 return obj->*mp;
62             }
63
64             template <typename Class>
65             RT const& operator()(Class const& obj) const
66             {
67                 BOOST_PROTO_USE_GET_POINTER();
68
69                 typedef typename proto::detail::class_member_traits<MP>::class_type class_type;
70                 return (BOOST_PROTO_GET_POINTER(class_type, obj)->*mp);
71             }
72
73             template <typename Class>
74             RT const& operator()(Class const* obj) const
75             {
76                 return obj->*mp;
77             }
78
79             MP mp;
80         };
81 }}}
82
83 #ifdef _MSC_VER
84 #pragma warning(pop)
85 #endif
86
87 #endif