1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 http://spirit.sourceforge.net/
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 #ifndef BOOST_SPIRIT_MODIFY_OCTOBER_25_2008_0142PM
9 #define BOOST_SPIRIT_MODIFY_OCTOBER_25_2008_0142PM
15 #include <boost/spirit/include/phoenix_limits.hpp> // needs to be included before proto
16 #include <boost/proto/proto.hpp>
17 #include <boost/mpl/if.hpp>
18 #include <boost/type_traits/is_base_of.hpp>
19 #include <boost/spirit/home/support/unused.hpp>
21 namespace boost { namespace spirit
23 template <typename Domain, typename T, typename Enable = void>
24 struct is_modifier_directive;
26 // Testing if a modifier set includes a modifier T involves
27 // checking for inheritance (i.e. Modifiers is derived from T)
28 template <typename Modifiers, typename T>
30 : is_base_of<T, Modifiers> {};
32 // Adding modifiers is done using multi-inheritance
33 template <typename Current, typename New, typename Enable = void>
34 struct compound_modifier : Current, New
39 compound_modifier(Current const& current, New const& new_)
40 : Current(current), New(new_) {}
43 // Don't add if New is already in Current
44 template <typename Current, typename New>
45 struct compound_modifier<
46 Current, New, typename enable_if<has_modifier<Current, New> >::type>
52 compound_modifier(Current const& current, New const&)
56 // Special case if Current is unused_type
57 template <typename New, typename Enable>
58 struct compound_modifier<unused_type, New, Enable> : New
63 compound_modifier(unused_type, New const& new_)
67 // Domains may specialize this modify metafunction to allow
68 // directives to add information to the Modifier template
69 // parameter that is passed to the make_component metafunction.
70 // By default, we return the modifiers untouched
71 template <typename Domain, typename Enable = void>
74 template <typename Sig>
77 template <typename This, typename Tag, typename Modifiers>
78 struct result<This(Tag, Modifiers)>
80 typedef typename remove_const<
81 typename remove_reference<Tag>::type>::type
83 typedef typename remove_const<
84 typename remove_reference<Modifiers>::type>::type
87 typedef typename mpl::if_<
88 is_modifier_directive<Domain, tag_type>
89 , compound_modifier<modifiers_type, tag_type>
94 template <typename Tag, typename Modifiers>
95 typename result<modify(Tag, Modifiers)>::type
96 operator()(Tag tag, Modifiers modifiers) const
98 return op(tag, modifiers, is_modifier_directive<Domain, Tag>());
101 template <typename Tag, typename Modifiers>
103 op(Tag /*tag*/, Modifiers modifiers, mpl::false_) const
108 template <typename Tag, typename Modifiers>
109 compound_modifier<Modifiers, Tag>
110 op(Tag tag, Modifiers modifiers, mpl::true_) const
112 return compound_modifier<Modifiers, Tag>(modifiers, tag);
117 namespace boost { namespace proto
119 template <typename Domain, typename Enable>
120 struct is_callable<spirit::modify<Domain, Enable> >