Compare commits

...

9 Commits

Author SHA1 Message Date
Michel Morin
49ab4faa2b Merge r86524 (Correct broken links to C++ standard papers); fixes #9212
[SVN r86673]
2013-11-13 03:22:55 +00:00
Beman Dawes
45295c87bc Merge 86392 from trunk. The spirit change was not applied because the file is not present in branches/release.
[SVN r86489]
2013-10-27 21:10:04 +00:00
Lorenzo Caminiti
b74489d477 Merged Boost.Parameter fixes from trunk to support accessing named paramter types tag::x::_.
[SVN r78851]
2012-06-07 18:21:25 +00:00
Tim Blechmann
475001a591 parameter: merge fix from trunk (required for boost.heap)
[SVN r76090]
2011-12-21 11:20:00 +00:00
Tim Blechmann
f9e0d1c5c3 parameter: merge enable_if fix from trunk
[SVN r76069]
2011-12-19 18:00:17 +00:00
Marshall Clow
bdcbf442bf Merge fix to release branch, fixes #4983
[SVN r68366]
2011-01-22 15:42:09 +00:00
Andrey Semashev
c9cf0ab0f5 Merged changes from trunk.
[SVN r62272]
2010-05-27 17:58:58 +00:00
Douglas Gregor
20301b3da4 Add some missing includes for the parameter library
[SVN r62231]
2010-05-26 07:47:05 +00:00
Andrey Semashev
59e172adb3 Added missing include.
[SVN r60776]
2010-03-22 20:18:30 +00:00
12 changed files with 284 additions and 196 deletions

View File

@@ -37,7 +37,7 @@ can be deduced from their types.</p>
</tbody>
</table>
<!-- @jam_prefix.append('''
project test : requirements <include>. <source>/boost//headers ;''') -->
project test : requirements <include>. <implicit-dependency>/boost//headers ;''') -->
<!-- @example.prepend('''
#include <boost/parameter.hpp>
@@ -78,14 +78,14 @@ int x = '''); -->
<tbody valign="top">
<tr class="field"><th class="field-name">Authors:</th><td class="field-body">David Abrahams, Daniel Wallin</td>
</tr>
<tr class="field"><th class="field-name">Contact:</th><td class="field-body"><a class="reference external" href="mailto:dave&#64;boost-consulting.com">dave&#64;boost-consulting.com</a>, <a class="reference external" href="mailto:dalwan01&#64;student.umu.se">dalwan01&#64;student.umu.se</a></td>
<tr class="field"><th class="field-name">Contact:</th><td class="field-body"><a class="reference external" href="mailto:dave&#64;boost-consulting.com">dave&#64;boost-consulting.com</a>, <a class="reference external" href="mailto:daniel&#64;boostpro.com">daniel&#64;boostpro.com</a></td>
</tr>
<tr class="field"><th class="field-name">Organization:</th><td class="field-body"><a class="reference external" href="http://www.boost-consulting.com">Boost Consulting</a></td>
<tr class="field"><th class="field-name">organization:</th><td class="field-body"><a class="reference external" href="http://www.boostpro.com">BoostPro Computing</a></td>
</tr>
<tr class="field"><th class="field-name">Date:</th><td class="field-body">$Date: 2005/07/18 20:34:31 $</td>
<tr class="field"><th class="field-name">date:</th><td class="field-body">$Date: 2005/07/17 19:53:01 $</td>
</tr>
<tr class="field"><th class="field-name">Copyright:</th><td class="field-body">Copyright David Abrahams, Daniel Wallin 2005.
Distributed under the Boost Software License,
<tr class="field"><th class="field-name">copyright:</th><td class="field-body">Copyright David Abrahams, Daniel Wallin
2005-2009. Distributed under the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt
or copy at <a class="reference external" href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</td>
</tr>
@@ -508,7 +508,7 @@ tuple:</p>
(required <strong>(graph, *)</strong> )
</pre>
<p class="compound-last">Since <tt class="docutils literal"><span class="pre">depth_first_search</span></tt> doesn't require any particular type
for its <tt class="docutils literal"><span class="pre">graph</span></tt> parameter, we use an asterix to indicate that
for its <tt class="docutils literal"><span class="pre">graph</span></tt> parameter, we use an asterisk to indicate that
any type is allowed. Required parameters must always precede any
optional parameters in a signature, but if there are <em>no</em>
required parameters, the <tt class="docutils literal"><span class="pre">(required</span> <span class="pre"></span> <span class="pre">)</span></tt> clause can be omitted
@@ -727,7 +727,7 @@ worse—think of the kinds of errors you get from your STL
implementation when you make a mistake).<a class="footnote-reference" href="#conceptcpp" id="id7"><sup>4</sup></a></li>
<li>The problems with exposing such permissive function template
signatures have been the subject of much discussion, especially
in the presence of <a class="reference external" href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#225">unqualified calls</a>. If all we want is to
in the presence of <a class="reference external" href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#225">unqualified calls</a>. If all we want is to
avoid unintentional argument-dependent lookup (ADL), we can
isolate <tt class="docutils literal"><span class="pre">depth_first_search</span></tt> in a namespace containing no
types<a class="footnote-reference" href="#using" id="id8"><sup>6</sup></a>, but suppose we <em>want</em> it to found via ADL?</li>
@@ -791,7 +791,7 @@ Metafunctions</a>. There's no space to give a complete description
of metafunctions or of graph library details here, but we'll show
you the complete signature with maximal checking, just to give you
a feel for how it's done. Each predicate metafunction is enclosed
in parentheses <em>and preceded by an asterix</em>, as follows:</p>
in parentheses <em>and preceded by an asterisk</em>, as follows:</p>
<pre class="literal-block">
BOOST_PARAMETER_FUNCTION(
(void), depth_first_search, graphs
@@ -1026,7 +1026,7 @@ BOOST_PARAMETER_NAME(arg2)
struct callable2
{
BOOST_PARAMETER_CONST_MEMBER_FUNCTION(
(void), operator(), tag, (required (arg1,(int))(arg2,(int))))
(void), call, tag, (required (arg1,(int))(arg2,(int))))
{
std::cout &lt;&lt; arg1 &lt;&lt; &quot;, &quot; &lt;&lt; arg2 &lt;&lt; std::endl;
}
@@ -1034,7 +1034,9 @@ struct callable2
</pre>
<!-- @example.prepend('''
#include <boost/parameter.hpp>
#include <iostream>''') -->
#include <iostream>
using namespace boost::parameter;
''') -->
<!-- @test('compile') -->
<p>These macros don't directly allow a function's interface to be
separated from its implementation, but you can always forward
@@ -1043,7 +1045,7 @@ arguments on to a separate implementation function:</p>
struct callable2
{
BOOST_PARAMETER_CONST_MEMBER_FUNCTION(
(void), operator(), tag, (required (arg1,(int))(arg2,(int))))
(void), call, tag, (required (arg1,(int))(arg2,(int))))
{
call_impl(arg1,arg2);
}
@@ -1055,8 +1057,33 @@ struct callable2
#include <boost/parameter.hpp>
BOOST_PARAMETER_NAME(arg1)
BOOST_PARAMETER_NAME(arg2)''') -->
BOOST_PARAMETER_NAME(arg2)
using namespace boost::parameter;
''') -->
<!-- @test('compile') -->
<div class="section" id="static-member-functions">
<h3>2.2.1&nbsp;&nbsp;&nbsp;Static Member Functions</h3>
<p>To expose a static member function, simply insert the keyword
<tt class="docutils literal"><span class="pre">static</span></tt>” before the function name:</p>
<pre class="literal-block">
BOOST_PARAMETER_NAME(arg1)
struct somebody
{
BOOST_PARAMETER_MEMBER_FUNCTION(
(void), <strong>static</strong> f, tag, (optional (arg1,(int),0)))
{
std::cout &lt;&lt; arg1 &lt;&lt; std::endl;
}
};
</pre>
<!-- @example.prepend('''
#include <boost/parameter.hpp>
#include <iostream>
using namespace boost::parameter;
''') -->
<!-- @test('compile') -->
</div>
</div>
<div class="section" id="parameter-enabled-constructors">
<h2><a class="toc-backref" href="#id29">2.3&nbsp;&nbsp;&nbsp;Parameter-Enabled Constructors</a></h2>
@@ -1224,10 +1251,10 @@ namespace boost { namespace python {
using boost::mpl::_;
typedef parameter::parameters&lt;
required&lt;tag::class_type, is_class&lt;_&gt; &gt;
, optional&lt;tag::base_list, mpl::is_sequence&lt;_&gt; &gt;
, optional&lt;tag::held_type&gt;
, optional&lt;tag::copyable&gt;
required&lt;tag::class_type, boost::is_class&lt;_&gt; &gt;
, parameter::optional&lt;tag::base_list, mpl::is_sequence&lt;_&gt; &gt;
, parameter::optional&lt;tag::held_type&gt;
, parameter::optional&lt;tag::copyable&gt;
&gt; class_signature;
}}
@@ -1236,6 +1263,7 @@ typedef parameter::parameters&lt;
#include <boost/parameter.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/noncopyable.hpp>
#include <boost/type_traits/is_class.hpp>
#include <memory>
using namespace boost::parameter;
@@ -1255,11 +1283,13 @@ struct bases
</div>
<div class="section" id="argument-packs-and-parameter-extraction">
<span id="binding-intro"></span><h4>2.4.1.4&nbsp;&nbsp;&nbsp;Argument Packs and Parameter Extraction</h4>
<p>Next, within the body of <tt class="docutils literal"><span class="pre">class_</span></tt> , we use the <span class="concept">ParameterSpec</span>'s nested <tt class="docutils literal"><span class="pre">::bind&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt> template to bundle the actual arguments
into an <a class="reference external" href="reference.html#argumentpack"><span class="concept">ArgumentPack</span></a> type, and then use the library's <tt class="docutils literal"><span class="pre">binding&lt;</span>
<span class="pre"></span> <span class="pre">&gt;</span></tt> metafunction to extract “logical parameters”. Note that
defaults are specified by supplying an optional third argument to
<tt class="docutils literal"><span class="pre">binding&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt>:</p>
<p>Next, within the body of <tt class="docutils literal"><span class="pre">class_</span></tt> , we use the <span class="concept">ParameterSpec</span>'s
nested <tt class="docutils literal"><span class="pre">::bind&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt> template to bundle the actual arguments into an
<a class="reference external" href="reference.html#argumentpack"><span class="concept">ArgumentPack</span></a> type, and then use the library's <tt class="docutils literal"><span class="pre">value_type&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt>
metafunction to extract “logical parameters”. <tt class="docutils literal"><span class="pre">value_type&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt> is
a lot like <tt class="docutils literal"><span class="pre">binding&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt>, but no reference is added to the actual
argument type. Note that defaults are specified by passing it an
optional third argument:</p>
<pre class="literal-block">
namespace boost { namespace python {
@@ -1277,16 +1307,16 @@ struct class_
args;
// Extract first logical parameter.
typedef typename parameter::binding&lt;
typedef typename parameter::value_type&lt;
args, tag::class_type&gt;::type class_type;
typedef typename parameter::binding&lt;
typedef typename parameter::value_type&lt;
args, tag::base_list, bases&lt;&gt; &gt;::type base_list;
typedef typename parameter::binding&lt;
typedef typename parameter::value_type&lt;
args, tag::held_type, class_type&gt;::type held_type;
typedef typename parameter::binding&lt;
typedef typename parameter::value_type&lt;
args, tag::copyable, void&gt;::type copyable;
};
@@ -1381,12 +1411,12 @@ parameters deducible:</p>
typedef parameter::parameters&lt;
required&lt;tag::class_type, is_class&lt;_&gt; &gt;
, optional&lt;
, parameter::optional&lt;
deduced&lt;tag::base_list&gt;
, is_base_and_derived&lt;detail::bases_base,_&gt;
&gt;
, optional&lt;
, parameter::optional&lt;
deduced&lt;tag::held_type&gt;
, mpl::not_&lt;
mpl::or_&lt;
@@ -1396,11 +1426,12 @@ typedef parameter::parameters&lt;
&gt;
&gt;
, optional&lt;deduced&lt;tag::copyable&gt;, is_same&lt;noncopyable,_&gt; &gt;
, parameter::optional&lt;deduced&lt;tag::copyable&gt;, is_same&lt;noncopyable,_&gt; &gt;
&gt; class_signature;
</pre>
<!-- @example.prepend('''
#include <boost/type_traits/is_class.hpp>
namespace boost { namespace python {''') -->
<!-- @example.append('''
template <
@@ -1417,16 +1448,16 @@ struct class_
args;
// Extract first logical parameter.
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::class_type>::type class_type;
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::base_list, bases<> >::type base_list;
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::held_type, class_type>::type held_type;
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::copyable, void>::type copyable;
};
@@ -1570,7 +1601,7 @@ using boost::mpl::_;''') -->
int main()
{}''') -->
<!-- @test('run', howmany='all') -->
<p>Note that because of the <a class="reference external" href="http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1385.htm">forwarding problem</a>, <tt class="docutils literal"><span class="pre">parameter::parameters::operator()</span></tt>
<p>Note that because of the <a class="reference external" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1385.htm">forwarding problem</a>, <tt class="docutils literal"><span class="pre">parameter::parameters::operator()</span></tt>
can't accept non-const rvalues.</p>
</div>
<div class="section" id="extracting-parameter-types">
@@ -1613,15 +1644,13 @@ int main()
<p>Occasionally one needs to deduce argument types without an extra
layer of function call. For example, suppose we wanted to return
twice the value of the <tt class="docutils literal"><span class="pre">index</span></tt> parameter? In that
case we can use the <tt class="docutils literal"><span class="pre">binding&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt> metafunction introduced
case we can use the <tt class="docutils literal"><span class="pre">value_type&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt> metafunction introduced
<a class="reference internal" href="#binding-intro">earlier</a>:</p>
<pre class="literal-block">
BOOST_PARAMETER_NAME(index)
template &lt;class ArgumentPack&gt;
typename remove_reference&lt;
typename parameter::binding&lt;ArgumentPack, tag::index, int&gt;::type
&gt;::type
typename parameter::value_type&lt;ArgumentPack, tag::index, int&gt;::type
twice_index(ArgumentPack const&amp; args)
{
return 2 * args[_index|42];
@@ -1635,32 +1664,16 @@ int six = twice_index(_index = 3);
#include <cassert>
namespace parameter = boost::parameter;
using boost::remove_reference;''') -->
<p>Note that the <tt class="docutils literal"><span class="pre">remove_reference&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt> dance is necessary because
<tt class="docutils literal"><span class="pre">binding&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt> will return a reference type when the argument
is bound in the argument pack. If we don't strip the reference we
end up returning a reference to the temporary created in the <tt class="docutils literal"><span class="pre">2</span> <span class="pre">*</span> <span class="pre"></span></tt>
expression. A convenient shortcut would be to use the <tt class="docutils literal"><span class="pre">value_type&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt>
metafunction:</p>
<pre class="literal-block">
template &lt;class ArgumentPack&gt;
typename <strong>parameter::value_type&lt;ArgumentPack, tag::index, int&gt;</strong>::type
twice_index(ArgumentPack const&amp; args)
{
return 2 * args[_index|42];
}
</pre>
<!-- @example.wrap('namespace with_value_type {', '''
int six = twice_index(_index = 3);
}''') -->
<!-- TODO: binding<> returns a reference. We should use value_type<> here. -->
''') -->
<!-- @example.append('''
int main()
{
assert(six == 6);
assert(with_value_type::six == 6);
}''') -->
<!-- @test('run', howmany='all') -->
<p>Note that if we had used <tt class="docutils literal"><span class="pre">binding&lt;</span> <span class="pre"></span> <span class="pre">&gt;</span></tt> rather than <tt class="docutils literal"><span class="pre">value_type&lt;</span> <span class="pre"></span>
<span class="pre">&gt;</span></tt>, we would end up returning a reference to the temporary created in
the <tt class="docutils literal"><span class="pre">2</span> <span class="pre">*</span> <span class="pre"></span></tt> expression.</p>
</div>
<div class="section" id="lazy-default-computation">
<h3>3.2.3&nbsp;&nbsp;&nbsp;Lazy Default Computation</h3>

View File

@@ -1094,7 +1094,7 @@ already <tt class="docutils literal"><span class="pre">#defined</span></tt>.</p>
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Default Value:</th><td class="field-body"><tt class="docutils literal"><span class="pre">5</span></tt></td>
<tr class="field"><th class="field-name">Default Value:</th><td class="field-body"><tt class="docutils literal"><span class="pre">8</span></tt></td>
</tr>
</tbody>
</table>

View File

@@ -30,7 +30,7 @@ __ ../../../../index.htm
can be deduced from their types.
.. @jam_prefix.append('''
project test : requirements <include>. <source>/boost//headers ;''')
project test : requirements <include>. <implicit-dependency>/boost//headers ;''')
.. @example.prepend('''
#include <boost/parameter.hpp>
@@ -71,16 +71,16 @@ __ ../../../../index.htm
-------------------------------------
:Authors: David Abrahams, Daniel Wallin
:Contact: dave@boost-consulting.com, dalwan01@student.umu.se
:Organization: `Boost Consulting`_
:Date: $Date: 2005/07/18 20:34:31 $
:Contact: dave@boost-consulting.com, daniel@boostpro.com
:organization: `BoostPro Computing`_
:date: $Date: 2005/07/17 19:53:01 $
:Copyright: Copyright David Abrahams, Daniel Wallin 2005.
Distributed under the Boost Software License,
:copyright: Copyright David Abrahams, Daniel Wallin
2005-2009. Distributed under the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt
or copy at http://www.boost.org/LICENSE_1_0.txt)
.. _`Boost Consulting`: http://www.boost-consulting.com
.. _`BoostPro Computing`: http://www.boostpro.com
.. _concepts: http://www.boost.org/more/generic_programming.html#concept
@@ -783,7 +783,7 @@ signatures.
isolate ``depth_first_search`` in a namespace containing no
types [#using]_, but suppose we *want* it to found via ADL?
__ http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#225
__ http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#225
It's usually a good idea to prevent functions from being considered
for overload resolution when the passed argument types aren't
@@ -1112,7 +1112,7 @@ be used within the body of a class::
struct callable2
{
BOOST_PARAMETER_CONST_MEMBER_FUNCTION(
(void), operator(), tag, (required (arg1,(int))(arg2,(int))))
(void), call, tag, (required (arg1,(int))(arg2,(int))))
{
std::cout << arg1 << ", " << arg2 << std::endl;
}
@@ -1120,7 +1120,9 @@ be used within the body of a class::
.. @example.prepend('''
#include <boost/parameter.hpp>
#include <iostream>''')
#include <iostream>
using namespace boost::parameter;
''')
.. @test('compile')
@@ -1131,7 +1133,7 @@ arguments on to a separate implementation function::
struct callable2
{
BOOST_PARAMETER_CONST_MEMBER_FUNCTION(
(void), operator(), tag, (required (arg1,(int))(arg2,(int))))
(void), call, tag, (required (arg1,(int))(arg2,(int))))
{
call_impl(arg1,arg2);
}
@@ -1143,10 +1145,40 @@ arguments on to a separate implementation function::
#include <boost/parameter.hpp>
BOOST_PARAMETER_NAME(arg1)
BOOST_PARAMETER_NAME(arg2)''')
BOOST_PARAMETER_NAME(arg2)
using namespace boost::parameter;
''')
.. @test('compile')
Static Member Functions
=======================
To expose a static member function, simply insert the keyword
``static``” before the function name:
.. parsed-literal::
BOOST_PARAMETER_NAME(arg1)
struct somebody
{
BOOST_PARAMETER_MEMBER_FUNCTION(
(void), **static** f, tag, (optional (arg1,(int),0)))
{
std::cout << arg1 << std::endl;
}
};
.. @example.prepend('''
#include <boost/parameter.hpp>
#include <iostream>
using namespace boost::parameter;
''')
.. @test('compile')
------------------------------
Parameter-Enabled Constructors
------------------------------
@@ -1339,10 +1371,10 @@ separately)::
using boost::mpl::_;
typedef parameter::parameters<
required<tag::class_type, is_class<_> >
, optional<tag::base_list, mpl::is_sequence<_> >
, optional<tag::held_type>
, optional<tag::copyable>
required<tag::class_type, boost::is_class<_> >
, parameter::optional<tag::base_list, mpl::is_sequence<_> >
, parameter::optional<tag::held_type>
, parameter::optional<tag::copyable>
> class_signature;
}}
@@ -1351,6 +1383,7 @@ separately)::
#include <boost/parameter.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/noncopyable.hpp>
#include <boost/type_traits/is_class.hpp>
#include <memory>
using namespace boost::parameter;
@@ -1377,12 +1410,13 @@ separately)::
Argument Packs and Parameter Extraction
---------------------------------------
Next, within the body of ``class_`` , we use the |ParameterSpec|\
's nested ``::bind< … >`` template to bundle the actual arguments
into an |ArgumentPack|_ type, and then use the library's ``binding<
… >`` metafunction to extract “logical parameters”. Note that
defaults are specified by supplying an optional third argument to
``binding< … >``::
Next, within the body of ``class_`` , we use the |ParameterSpec|\ 's
nested ``::bind< … >`` template to bundle the actual arguments into an
|ArgumentPack|_ type, and then use the library's ``value_type< … >``
metafunction to extract “logical parameters”. ``value_type< … >`` is
a lot like ``binding< … >``, but no reference is added to the actual
argument type. Note that defaults are specified by passing it an
optional third argument::
namespace boost { namespace python {
@@ -1400,16 +1434,16 @@ defaults are specified by supplying an optional third argument to
args;
// Extract first logical parameter.
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::class_type>::type class_type;
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::base_list, bases<> >::type base_list;
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::held_type, class_type>::type held_type;
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::copyable, void>::type copyable;
};
@@ -1511,12 +1545,12 @@ parameters deducible::
typedef parameter::parameters<
required<tag::class_type, is_class<_> >
, optional<
, parameter::optional<
deduced<tag::base_list>
, is_base_and_derived<detail::bases_base,_>
>
, optional<
, parameter::optional<
deduced<tag::held_type>
, mpl::not_<
mpl::or_<
@@ -1526,11 +1560,12 @@ parameters deducible::
>
>
, optional<deduced<tag::copyable>, is_same<noncopyable,_> >
, parameter::optional<deduced<tag::copyable>, is_same<noncopyable,_> >
> class_signature;
.. @example.prepend('''
#include <boost/type_traits/is_class.hpp>
namespace boost { namespace python {''')
.. @example.append('''
@@ -1548,16 +1583,16 @@ parameters deducible::
args;
// Extract first logical parameter.
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::class_type>::type class_type;
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::base_list, bases<> >::type base_list;
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::held_type, class_type>::type held_type;
typedef typename parameter::binding<
typedef typename parameter::value_type<
args, tag::copyable, void>::type copyable;
};
@@ -1732,7 +1767,7 @@ its function call operator:
Note that because of the `forwarding problem`_, ``parameter::parameters::operator()``
can't accept non-const rvalues.
.. _`forwarding problem`: http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1385.htm
.. _`forwarding problem`: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1385.htm
Extracting Parameter Types
==========================
@@ -1778,15 +1813,13 @@ function template and allow *it* to do type deduction::
Occasionally one needs to deduce argument types without an extra
layer of function call. For example, suppose we wanted to return
twice the value of the ``index`` parameter? In that
case we can use the ``binding< … >`` metafunction introduced
case we can use the ``value_type< … >`` metafunction introduced
`earlier`__::
BOOST_PARAMETER_NAME(index)
template <class ArgumentPack>
typename remove_reference<
typename parameter::binding<ArgumentPack, tag::index, int>::type
>::type
typename parameter::value_type<ArgumentPack, tag::index, int>::type
twice_index(ArgumentPack const& args)
{
return 2 * args[_index|42];
@@ -1800,39 +1833,20 @@ case we can use the ``binding< … >`` metafunction introduced
#include <cassert>
namespace parameter = boost::parameter;
using boost::remove_reference;''')
Note that the ``remove_reference< … >`` dance is necessary because
``binding< … >`` will return a reference type when the argument
is bound in the argument pack. If we don't strip the reference we
end up returning a reference to the temporary created in the ``2 * …``
expression. A convenient shortcut would be to use the ``value_type< … >``
metafunction:
.. parsed-literal::
template <class ArgumentPack>
typename **parameter::value_type<ArgumentPack, tag::index, int>**::type
twice_index(ArgumentPack const& args)
{
return 2 * args[_index|42];
}
.. @example.wrap('namespace with_value_type {', '''
int six = twice_index(_index = 3);
}''')
.. TODO: binding<> returns a reference. We should use value_type<> here.
''')
.. @example.append('''
int main()
{
assert(six == 6);
assert(with_value_type::six == 6);
}''')
.. @test('run', howmany='all')
Note that if we had used ``binding< … >`` rather than ``value_type< …
>``, we would end up returning a reference to the temporary created in
the ``2 * …`` expression.
__ binding_intro_
Lazy Default Computation
@@ -1888,12 +1902,10 @@ object.
.. parsed-literal::
using boost::bind;
using boost::ref;
typename parameter::binding<
ArgumentPack, tag::s3, std::string
>::type s3 = args[_s3 **|| bind(std::plus<std::string>(), ref(s1), ref(s2))** ];
>::type s3 = args[_s3
**|| boost::bind(std::plus<std::string>(), boost::ref(s1), boost::ref(s2))** ];
.. @example.prepend('''
#include <boost/bind.hpp>

10
doc/python.rst Executable file → Normal file
View File

@@ -2,13 +2,13 @@
The Boost Parameter Library Python Binding Documentation
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
:Authors: Daniel Wallin
:Contact: dalwan01@student.umu.se
:organization: `Boost Consulting`_
:Authors: David Abrahams, Daniel Wallin
:Contact: dave@boost-consulting.com, daniel@boostpro.com
:organization: `BoostPro Computing`_
:date: $Date$
:copyright: Copyright David Abrahams, Daniel Wallin
2005. Distributed under the Boost Software License,
2005-2009. Distributed under the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt
or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -22,7 +22,7 @@
__ ../../../../index.htm
.. _`Boost Consulting`: http://www.boost-consulting.com
.. _`BoostPro Computing`: http://www.boostpro.com
.. role:: class

View File

@@ -3,12 +3,12 @@
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
:Authors: David Abrahams, Daniel Wallin
:Contact: dave@boost-consulting.com, dalwan01@student.umu.se
:organization: `Boost Consulting`_
:Contact: dave@boost-consulting.com, daniel@boostpro.com
:organization: `BoostPro Computing`_
:date: $Date: 2005/07/17 19:53:01 $
:copyright: Copyright David Abrahams, Daniel Wallin
2005. Distributed under the Boost Software License,
2005-2009. Distributed under the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt
or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -19,7 +19,7 @@
__ ../../../../index.htm
.. _`Boost Consulting`: http://www.boost-consulting.com
.. _`BoostPro Computing`: http://www.boostpro.com
//////////////////////////////////////////////////////////////////////////////
@@ -970,7 +970,7 @@ already ``#defined``.
__ ../../../../boost/parameter/config.hpp
:Default Value: ``5``
:Default Value: ``8``
Tutorial
========

39
include/boost/parameter/aux_/arg_list.hpp Executable file → Normal file
View File

@@ -11,7 +11,7 @@
#include <boost/parameter/aux_/default.hpp>
#include <boost/parameter/aux_/parameter_requirements.hpp>
#include <boost/parameter/aux_/yesno.hpp>
#include <boost/parameter/aux_/maybe.hpp>
#include <boost/parameter/aux_/is_maybe.hpp>
#include <boost/parameter/config.hpp>
#include <boost/mpl/apply.hpp>
@@ -22,11 +22,11 @@
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/facilities/intercept.hpp>
namespace boost { namespace parameter {
namespace boost { namespace parameter {
// Forward declaration for aux::arg_list, below.
template<class T> struct keyword;
@@ -46,7 +46,7 @@ struct lambda_tag;
// declarations to build member function overload sets that can
// match against keywords.
//
// MPL sequence support
struct arg_list_tag;
@@ -83,14 +83,14 @@ struct empty_arg_list
template <class KW>
static no_tag has_key(KW*);
#endif
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
|| (BOOST_WORKAROUND(__GNUC__, < 3)) \
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
// The overload set technique doesn't work with these older
// compilers, so they need some explicit handholding.
// A metafunction class that, given a keyword, returns the type
// of the base sublist whose get() function can produce the
// value for that key
@@ -159,11 +159,6 @@ no_tag operator*(empty_arg_list, KW*);
template <class KW, class T>
struct tagged_argument;
template <class T>
struct is_maybe
: is_base_and_derived<maybe_base, T>
{};
template <class T>
struct get_reference
{
@@ -211,9 +206,9 @@ struct arg_list : Next
// Create a new list by prepending arg to a copy of tail. Used
// when incrementally building this structure with the comma
// operator.
arg_list(TaggedArg arg, Next const& tail)
arg_list(TaggedArg head, Next const& tail)
: Next(tail)
, arg(arg)
, arg(head)
{}
// A metafunction class that, given a keyword and a default
@@ -241,8 +236,8 @@ struct arg_list : Next
// same keyword is used again
static yes_tag has_key(key_type*);
using Next::has_key;
# define BOOST_PARAMETER_CALL_HAS_KEY(next, key) next::has_key((key*)0)
# define BOOST_PARAMETER_CALL_HAS_KEY(next, key) next::has_key((key*)0)
# endif
BOOST_MPL_ASSERT_MSG(
@@ -257,7 +252,7 @@ struct arg_list : Next
// specific arguments by name
//
// Helpers that handle the case when TaggedArg is
// Helpers that handle the case when TaggedArg is
// empty<T>.
template <class D>
reference get_default(D const&, mpl::false_) const
@@ -337,7 +332,7 @@ struct arg_list : Next
template <class Default>
reference get(default_<key_type,Default> const& d) const
{
return get_default(d, holds_maybe());
return get_default(d, holds_maybe());
}
template <class Default>
@@ -345,7 +340,7 @@ struct arg_list : Next
{
return arg.value;
}
#else
reference operator[](keyword<key_type> const&) const
@@ -400,7 +395,7 @@ struct arg_list : Next
// Comma operator to compose argument list without using parameters<>.
// Useful for argument lists with undetermined length.
template <class KW, class T2>
arg_list<tagged_argument<KW, T2>, self>
arg_list<tagged_argument<KW, T2>, self>
operator,(tagged_argument<KW,T2> x) const
{
return arg_list<tagged_argument<KW,T2>, self>(x, *this);
@@ -414,7 +409,7 @@ struct arg_list : Next
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) // ETI workaround
template <> struct arg_list<int,int> {};
#endif
#endif
// MPL sequence support
template <class ArgumentPack>
@@ -424,7 +419,7 @@ struct arg_list_iterator
// The incremented iterator
typedef arg_list_iterator<typename ArgumentPack::tail_type> next;
// dereferencing yields the key type
typedef typename ArgumentPack::key_type type;
};

View File

@@ -40,11 +40,11 @@ struct use_default_tag {};
// X(something, *(predicate))
// X(something, (int))
template <class T>
template <class T, class Args>
struct cast;
template <>
struct cast<void*>
template <class Args>
struct cast<void*, Args>
{
static use_default_tag execute(use_default_tag)
{
@@ -73,27 +73,39 @@ struct cast<void*>
typedef void* voidstar;
template <class T>
struct cast<voidstar(T)>
: cast<void*>
template <class T, class Args>
struct cast<voidstar(T), Args>
: cast<void*, Args>
{
};
#else
template <class T>
struct cast<void*(T)>
: cast<void*>
template <class T, class Args>
struct cast<void*(T), Args>
: cast<void*, Args>
{
};
#endif
template <class T>
struct cast<void(T)>
// This is a hack used in cast<> to turn the user supplied type,
// which may or may not be a placeholder expression into one, so
// that it will be properly evaluated by mpl::apply.
template <class T, class Dummy = mpl::_1>
struct as_placeholder_expr
{
typedef T type;
};
template <class T, class Args>
struct cast<void(T), Args>
{
typedef typename mpl::apply2<
as_placeholder_expr<T>, Args, Args>::type type0;
typedef typename boost::add_reference<
typename boost::remove_const<T>::type
typename boost::remove_const<type0>::type
>::type reference;
static use_default_tag execute(use_default_tag)
@@ -106,7 +118,7 @@ struct cast<void(T)>
return use_default_tag();
}
static T execute(T value)
static type0 execute(type0 value)
{
return value;
}
@@ -118,9 +130,9 @@ struct cast<void(T)>
}
};
# define BOOST_PARAMETER_FUNCTION_CAST(value, predicate) \
boost::parameter::aux::cast<void predicate>::remove_const( \
boost::parameter::aux::cast<void predicate>::execute(value) \
# define BOOST_PARAMETER_FUNCTION_CAST(value, predicate, args) \
boost::parameter::aux::cast<void predicate, args>::remove_const( \
boost::parameter::aux::cast<void predicate, args>::execute(value) \
)
# endif

View File

@@ -0,0 +1,26 @@
// Copyright Daniel Wallin, David Abrahams 2010. Use, modification and
// distribution is subject to the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PARAMETER_IS_MAYBE_050329_HPP
#define BOOST_PARAMETER_IS_MAYBE_050329_HPP
#include <boost/type_traits/is_base_and_derived.hpp>
namespace boost {
namespace parameter {
namespace aux {
struct maybe_base {};
template <class T>
struct is_maybe
: is_base_and_derived<maybe_base, T>
{};
} // namespace aux
} // namespace parameter
} // namespace boost
#endif // BOOST_PARAMETER_IS_MAYBE_050329_HPP

60
include/boost/parameter/aux_/maybe.hpp Executable file → Normal file
View File

@@ -2,21 +2,41 @@
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PARAMETER_MAYBE_060211_HPP
# define BOOST_PARAMETER_MAYBE_060211_HPP
//
// 2009.10.21 TDS remove depenency on boost::python::detail::referent_storage
//
#ifndef BOOST_PARAMETER_MAYBE_091021_HPP
# define BOOST_PARAMETER_MAYBE_091021_HPP
# include <boost/mpl/if.hpp>
# include <boost/mpl/identity.hpp>
# include <boost/type_traits/is_reference.hpp>
# include <boost/type_traits/add_reference.hpp>
# include <boost/optional.hpp>
# include <boost/python/detail/referent_storage.hpp>
# include <boost/aligned_storage.hpp>
# include <boost/type_traits/remove_cv.hpp>
# include <boost/type_traits/add_const.hpp>
# include <boost/parameter/aux_/is_maybe.hpp>
namespace boost { namespace parameter { namespace aux {
struct maybe_base {};
template <class T> struct referent_size;
template <class T>
struct referent_size<T&>
{
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(T));
};
// A metafunction returning a POD type which can store U, where T ==
// U&. If T is not a reference type, returns a POD which can store T.
template <class T>
struct referent_storage
{
typedef typename boost::aligned_storage<
referent_size<T>::value
>::type type;
};
template <class T>
struct maybe : maybe_base
@@ -24,17 +44,17 @@ struct maybe : maybe_base
typedef typename add_reference<
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
T const
# else
# else
typename add_const<T>::type
# endif
# endif
>::type reference;
typedef typename remove_cv<
BOOST_DEDUCED_TYPENAME remove_reference<reference>::type
>::type non_cv_value;
explicit maybe(T value)
: value(value)
explicit maybe(T value_)
: value(value_)
, constructed(false)
{}
@@ -48,28 +68,28 @@ struct maybe : maybe_base
this->destroy();
}
reference construct(reference value) const
reference construct(reference value_) const
{
return value;
return value_;
}
template <class U>
reference construct2(U const& value) const
reference construct2(U const& value_) const
{
new (m_storage.bytes) non_cv_value(value);
new (m_storage.address()) non_cv_value(value_);
constructed = true;
return *(non_cv_value*)m_storage.bytes;
return *(non_cv_value*)m_storage.address();
}
template <class U>
reference construct(U const& value) const
reference construct(U const& value_) const
{
return this->construct2(value);
return this->construct2(value_);
}
void destroy()
{
((non_cv_value*)m_storage.bytes)->~non_cv_value();
((non_cv_value*)m_storage.address())->~non_cv_value();
}
typedef reference(maybe<T>::*safe_bool)() const;
@@ -87,7 +107,9 @@ struct maybe : maybe_base
private:
boost::optional<T> value;
mutable bool constructed;
mutable typename boost::python::detail::referent_storage<
mutable typename referent_storage<
reference
>::type m_storage;
};

2
include/boost/parameter/config.hpp Executable file → Normal file
View File

@@ -7,7 +7,7 @@
#define BOOST_PARAMETER_CONFIG_050403_HPP
#ifndef BOOST_PARAMETER_MAX_ARITY
# define BOOST_PARAMETER_MAX_ARITY 5
# define BOOST_PARAMETER_MAX_ARITY 8
#endif
#endif // BOOST_PARAMETER_CONFIG_050403_HPP

4
include/boost/parameter/name.hpp Executable file → Normal file
View File

@@ -27,7 +27,7 @@ namespace boost { namespace parameter { namespace aux {
// Tag type passed to MPL lambda.
struct lambda_tag;
struct name_tag_base
struct name_tag_base
{};
template <class Tag>
@@ -46,7 +46,7 @@ namespace boost { namespace mpl {
template <class T>
struct lambda<
T
, typename enable_if<
, typename boost::enable_if<
parameter::aux::is_name_tag<T>, parameter::aux::lambda_tag
>::type
>

View File

@@ -14,7 +14,9 @@
# include <boost/parameter/aux_/preprocessor/flatten.hpp>
# include <boost/preprocessor/repetition/repeat_from_to.hpp>
# include <boost/preprocessor/comparison/equal.hpp>
# include <boost/preprocessor/control/if.hpp>
# include <boost/preprocessor/control/iif.hpp>
# include <boost/preprocessor/control/expr_if.hpp>
# include <boost/preprocessor/repetition/enum_params.hpp>
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
@@ -23,9 +25,12 @@
# include <boost/preprocessor/seq/for_each_product.hpp>
# include <boost/preprocessor/seq/for_each_i.hpp>
# include <boost/preprocessor/tuple/elem.hpp>
# include <boost/preprocessor/tuple/eat.hpp>
# include <boost/preprocessor/seq/fold_left.hpp>
# include <boost/preprocessor/seq/push_back.hpp>
# include <boost/preprocessor/seq/size.hpp>
# include <boost/preprocessor/seq/enum.hpp>
# include <boost/preprocessor/seq/push_back.hpp>
# include <boost/preprocessor/detail/is_nullary.hpp>
@@ -358,7 +363,7 @@ struct funptr_predicate<void**>
# define BOOST_PARAMETER_FUNCTION_FWD_MATCH_Z(z, name, parameters, n) \
, typename boost::parameter::aux::match< \
parameters, BOOST_PP_ENUM_PARAMS(n, ParameterArgumentType) \
>::type boost_parameter_enabler_argument = parameters()
>::type = parameters()
# else
# define BOOST_PARAMETER_FUNCTION_FWD_MATCH_Z(z, name, parameters, n)
# endif
@@ -696,6 +701,7 @@ struct funptr_predicate<void**>
) \
] \
, BOOST_PARAMETER_FN_ARG_PRED(arg) \
, Args \
)
# define BOOST_PARAMETER_FUNCTION_DEFAULT_FUNCTION_BODY(name, n, split_args, tag_namespace) \
@@ -723,6 +729,7 @@ struct funptr_predicate<void**>
BOOST_PARAMETER_FUNCTION_CAST( \
boost::parameter::aux::as_lvalue(BOOST_PARAMETER_FN_ARG_DEFAULT(arg), 0L) \
, BOOST_PARAMETER_FN_ARG_PRED(arg) \
, Args \
)
# define BOOST_PARAMETER_FUNCTION_DEFAULT_EVAL_DEFAULT_BODY(name, n, split_args, tag_ns, const_) \
@@ -838,6 +845,7 @@ struct funptr_predicate<void**>
boost::parameter::keyword<tag_ns::BOOST_PARAMETER_FN_ARG_KEYWORD(arg)>::instance \
] \
, BOOST_PARAMETER_FN_ARG_PRED(arg) \
, Args \
)
// Generates the function template that recives a ArgumentPack, and then