/src/contrib/boost/spirit/home/phoenix/core/reference.hpp

http://pythonocc.googlecode.com/ · C++ Header · 80 lines · 58 code · 14 blank · 8 comment · 1 complexity · 9e2acaea4710fe52b9e85d1ff5e386fb MD5 · raw file

  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 PHOENIX_CORE_REFERENCE_HPP
  7. #define PHOENIX_CORE_REFERENCE_HPP
  8. #include <boost/spirit/home/phoenix/core/actor.hpp>
  9. #include <boost/static_assert.hpp>
  10. #include <boost/type_traits/is_reference.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. namespace boost { namespace phoenix
  13. {
  14. template <typename T>
  15. struct reference
  16. {
  17. // $$$ TODO: a better (user friendly) static assert
  18. BOOST_STATIC_ASSERT(
  19. mpl::not_<is_reference<T> >::value != 0);
  20. typedef mpl::false_ no_nullary;
  21. template <typename Env>
  22. struct result
  23. {
  24. typedef T& type;
  25. };
  26. reference(T& arg)
  27. : ref(arg) {}
  28. template <typename Env>
  29. T& eval(Env const&) const
  30. {
  31. return ref;
  32. }
  33. T& ref;
  34. private:
  35. // silence MSVC warning C4512: assignment operator could not be generated
  36. reference& operator= (reference const&);
  37. };
  38. template <typename T>
  39. inline actor<reference<T> > const
  40. ref(T& v)
  41. {
  42. return reference<T>(v);
  43. }
  44. template <typename T>
  45. inline actor<reference<T const> > const
  46. cref(T const& v)
  47. {
  48. return reference<T const>(v);
  49. }
  50. namespace detail
  51. {
  52. struct error_attempting_to_convert_an_actor_to_a_reference {};
  53. }
  54. template <typename Base>
  55. void
  56. ref(actor<Base> const& v
  57. , detail::error_attempting_to_convert_an_actor_to_a_reference
  58. = detail::error_attempting_to_convert_an_actor_to_a_reference());
  59. template <typename Base>
  60. void
  61. cref(actor<Base> const& v
  62. , detail::error_attempting_to_convert_an_actor_to_a_reference
  63. = detail::error_attempting_to_convert_an_actor_to_a_reference());
  64. }}
  65. #endif