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