member_variable.hpp 2.6 KB

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