PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/doc/advanced/porting.qbk

http://hadesmem.googlecode.com/
text | 115 lines | 98 code | 17 blank | 0 comment | 0 complexity | 0f0fc5362e78439f7803831fab891e2d MD5 | raw file
  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 Porting from Phoenix 2.0]
 11
 12While reading the current documentation you might have noticed that the
 13[link phoenix.starter_kit Starter Kit] didn't change very much. This is because
 14a lot of effort was put into being compatible with Phoenix 2.0, at least on the
 15outside.
 16
 17That being said, the only major difference is the result type deduction protocol.
 18The everyday Phoenix-User will encounter this change only when writing
 19[link phoenix.reference.modules.function Functions].
 20
 21To make your function implementations Phoenix compliant again change from
 22the old Phoenix result type deduction protocol to the new (standard compliant)
 23result type deduction protocol:
 24
 25[table
 26	[[Phoenix 2.0] [Phoenix 3.0] [Notes]]
 27	[
 28	[``
 29		struct is_odd_impl
 30		{
 31			template <typename Arg>
 32			struct result
 33			{
 34				typedef bool type;
 35			};
 36
 37			template <typename Arg>
 38			bool operator()(Arg arg) const
 39			{
 40				return arg % 2 == 1;
 41			}
 42		};
 43	
 44		boost::phoenix::function<is_odd_impl> is_odd = is_odd_impl();
 45	``]
 46	[``
 47		struct is_odd_impl
 48		{
 49			typedef bool result_type;
 50
 51			template <typename Arg>
 52			bool operator()(Arg arg) const
 53			{
 54				return arg % 2 == 1;
 55			}
 56		};
 57	
 58		boost::phoenix::function<is_odd_impl> is_odd = is_odd_impl();
 59	``]
 60	[ __note__
 61	 The result_of protocol is particularly easy when you implement a monomorphic
 62	 function (return type not dependent on the arguments). You then just need a
 63	 single nested return_type typedef.
 64	]
 65	]
 66	[
 67	[``
 68		struct add_impl
 69		{
 70			template <typename Arg1, typename Arg2>
 71			struct result
 72			{
 73				typedef Arg1 type;
 74			};
 75
 76			template <typename Arg1, typename Arg2>
 77			Arg1 operator()(Arg1 arg1, Arg2 arg2) const
 78			{
 79				return arg1 + arg2;
 80			}
 81		};
 82	
 83		boost::phoenix::function<add_impl> add = add_impl();
 84	``]
 85	[``
 86		struct add_impl
 87		{
 88			template <typename Sig>
 89			struct result;
 90
 91			template <typename This, typename Arg1, typename Arg2>
 92			struct result<This(Arg1, Arg2)>
 93				: boost::remove_reference<Arg1> {};
 94
 95			template <typename Arg1, typename Arg2>
 96			typename boost::remove_reference<Arg1>::type
 97			operator()(Arg1 arg1, Arg2 arg2) const
 98			{
 99				return arg1 + arg2;
100			}
101		};
102	
103		boost::phoenix::function<add_impl> add = add_impl();
104	``]
105	[__alert__ When dealing with polymorphic functions the template arguments can
106	be any type including cv-qualifiers and references. For that reason, the calculated
107	result type need to remove the reference whenever appropriate!]
108	]
109]
110
111[blurb __tip__ There is no general guideline for porting code which relies on the
112internals of Phoenix 2.0. If you plan on porting your Phoenix 2.0 extensions
113please refer to the next sections.]
114
115[endsect]