/src/contrib/boost/spirit/home/phoenix/detail/local_reference.hpp

http://pythonocc.googlecode.com/ · C++ Header · 44 lines · 30 code · 8 blank · 6 comment · 0 complexity · 2bb36c3ce809e5c0b9b2f9d1b4d18f12 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2005-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_DETAIL_LOCAL_REFERENCE_HPP
  7. #define PHOENIX_DETAIL_LOCAL_REFERENCE_HPP
  8. #include <boost/utility/addressof.hpp>
  9. namespace boost { namespace phoenix { namespace detail
  10. {
  11. template <typename T>
  12. struct local_reference
  13. {
  14. typedef T type;
  15. explicit local_reference(T& t): t_(boost::addressof(t)) {}
  16. operator T& () const { return *t_; }
  17. local_reference& operator=(T const& x) { *t_ = x; return *this; }
  18. local_reference const& operator=(T const& x) const { *t_ = x; return *this; }
  19. T& get() const { return *t_; }
  20. T* get_pointer() const { return t_; }
  21. private:
  22. T* t_;
  23. };
  24. template <typename T>
  25. struct unwrap_local_reference
  26. {
  27. typedef T type; // T should be a reference
  28. };
  29. template <typename T>
  30. struct unwrap_local_reference<local_reference<T> >
  31. {
  32. typedef T type; // unwrap the reference; T is a value
  33. };
  34. }}}
  35. #endif