]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/example/identity_transform.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2007 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
8 #include <boost/phoenix.hpp>
13 namespace proto
= boost::proto
;
14 namespace phoenix
= boost::phoenix
;
16 template <typename Rule
>
17 struct identity_transform
;
19 struct identity_actions
21 template <typename Rule
>
22 struct when
: phoenix::call
<identity_transform
<Rule
> > {};
26 struct identity_actions::when
<phoenix::rule::argument
>
28 identity_transform
<phoenix::rule::argument
>(proto::_value
, phoenix::_context
)
32 struct identity_actions::when
<phoenix::rule::terminal
>
34 identity_transform
<phoenix::rule::terminal
>(proto::_value
, phoenix::_context
)
38 struct identity_actions::when
<phoenix::rule::custom_terminal
>
40 identity_transform
<proto::_value
>(proto::_value
, phoenix::_context
)
44 struct identity_transform
<phoenix::rule::terminal
>
46 typedef std::string result_type
;
48 template <typename Terminal
, typename Context
>
49 std::string
operator()(Terminal
const & terminal
, Context
) const
52 ss
<< "val(" << terminal
<< ")";
56 template <typename Context
>
57 std::string
operator()(char const * terminal
, Context
) const
60 ss
<< "val(\"" << terminal
<< "\")";
66 struct identity_transform
<boost::reference_wrapper
<T
> >
68 typedef std::string result_type
;
70 template <typename Terminal
, typename Context
>
71 std::string
operator()(Terminal
const & terminal
, Context
) const
74 ss
<< "ref(" << terminal
<< ")";
79 template <int N
, typename Context
>
80 std::string
operator()(boost::reference_wrapper
<char const *> terminal
, Context
) const
83 ss
<< "ref(\"" << terminal
<< "\")";
87 template <int N
, typename Context
>
88 std::string
operator()(boost::reference_wrapper
<char const [N
]> terminal
, Context
) const
91 ss
<< "ref(\"" << terminal
<< "\")";
97 struct identity_transform
<phoenix::rule::argument
>
99 typedef std::string result_type
;
101 template <typename N
, typename Context
>
102 std::string
operator()(N
, Context
) const
104 std::stringstream ss
;
105 ss
<< "_" << N::value
;
111 template <typename Expr
>
112 void identity(Expr
const & expr
)
114 std::cout
<< phoenix::eval(expr
, phoenix::context(int(), identity_actions())) << "\n";
120 identity(phoenix::val(8));
121 identity(phoenix::val("8"));
122 identity(phoenix::ref("blubb"));
123 identity(phoenix::arg_names::_1
);