custom_terminal.qbk 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. [/==============================================================================
  2. Copyright (C) 2001-2010 Joel de Guzman
  3. Copyright (C) 2001-2005 Dan Marsden
  4. Copyright (C) 2001-2010 Thomas Heller
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ===============================================================================/]
  8. [section Custom Terminals]
  9. Custom Terminals are used in Phoenix to handle special values transparently.
  10. For example, as Phoenix captures everything by value, we needed to use
  11. `boost::reference_wrapper` to bring reference semantics into Phoenix.
  12. Custom terminals could be any wrapper class:
  13. template <typename T>
  14. struct is_custom_terminal;
  15. needs to be specialized in order for Phoenix to recognize this wrapper type.
  16. `default_action` calls `custom_terminal<T>`.
  17. Example:
  18. // Call out boost::reference_wrapper for special handling
  19. template<typename T>
  20. struct is_custom_terminal<boost::reference_wrapper<T> >
  21. : mpl::true_
  22. {};
  23. // Special handling for boost::reference_wrapper
  24. template<typename T>
  25. struct custom_terminal<boost::reference_wrapper<T> >
  26. {
  27. typedef T &result_type;
  28. template <typename Context>
  29. T &operator()(boost::reference_wrapper<T> r, Context &) const
  30. {
  31. return r;
  32. }
  33. };
  34. [endsect]