mirror of
https://github.com/boostorg/lambda.git
synced 2026-01-21 04:52:25 +00:00
Compare commits
46 Commits
svn-branch
...
sandbox-br
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5769fc1a39 | ||
|
|
2ed8d7f4df | ||
|
|
4091f55a4b | ||
|
|
45c6ba535c | ||
|
|
57a605d7cc | ||
|
|
fcfcc42baf | ||
|
|
c516504670 | ||
|
|
c479b3b7b7 | ||
|
|
269ac93b1b | ||
|
|
15d4e6ab79 | ||
|
|
77495bb7e1 | ||
|
|
c183b699bc | ||
|
|
3d4a3e7050 | ||
|
|
c14095472e | ||
|
|
1afc4b6779 | ||
|
|
41eb864595 | ||
|
|
0f60055086 | ||
|
|
9a8e5d7784 | ||
|
|
6985fca6ee | ||
|
|
04ae944c3c | ||
|
|
0c4e251ebe | ||
|
|
0faeb3f19e | ||
|
|
150736273e | ||
|
|
d5a98758fa | ||
|
|
cd3d5fd03a | ||
|
|
48a89b7705 | ||
|
|
ec350abf06 | ||
|
|
d56abd61ce | ||
|
|
2788ede42a | ||
|
|
1c953ed38c | ||
|
|
b2dc95bb18 | ||
|
|
797b5756cf | ||
|
|
bd4da55f0f | ||
|
|
47bf3df0ae | ||
|
|
ff0929e6e3 | ||
|
|
9b925abaff | ||
|
|
bf50f2fe7f | ||
|
|
85630d55a6 | ||
|
|
2e8c4eb8f3 | ||
|
|
24e8602cf1 | ||
|
|
7f77f987c1 | ||
|
|
d854239945 | ||
|
|
4aef261258 | ||
|
|
6b67606f40 | ||
|
|
b0ce56c74f | ||
|
|
9e45d49139 |
@@ -1,5 +1,12 @@
|
||||
project boost/doc ;
|
||||
import boostbook : boostbook ;
|
||||
|
||||
boostbook lambda-doc : lambda.xml ;
|
||||
# Are these really the correct images??
|
||||
path-constant images : ../../spirit/phoenix/doc/html ;
|
||||
|
||||
boostbook lambda-doc : lambda.xml
|
||||
:
|
||||
<xsl:param>boost.root=../../../..
|
||||
<format>pdf:<xsl:param>img.src.path=$(images)/
|
||||
;
|
||||
|
||||
|
||||
4
doc/detail/lambda_doc.xml
Executable file → Normal file
4
doc/detail/lambda_doc.xml
Executable file → Normal file
@@ -163,8 +163,8 @@ The STL contains predefined function objects for some common cases (such as <lit
|
||||
As an example, one possible implementation for the standard <literal>plus</literal> template is:
|
||||
|
||||
<programlisting>
|
||||
<![CDATA[template <class T> : public binary_function<T, T, T>
|
||||
struct plus {
|
||||
<![CDATA[template <class T>
|
||||
struct plus : public binary_function<T, T, T> {
|
||||
T operator()(const T& i, const T& j) const {
|
||||
return i + j;
|
||||
}
|
||||
|
||||
12
doc/index.html
Normal file
12
doc/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=../../../doc/html/lambda.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to <a href="../../../doc/html/lambda.html">www.boost.org/doc/html/lambda.html</a> <hr>
|
||||
<p>© Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
</body>
|
||||
</html>
|
||||
162
doc/lambda.xml
162
doc/lambda.xml
@@ -44,7 +44,7 @@
|
||||
<para>
|
||||
|
||||
The Boost Lambda Library (BLL in the sequel) is a C++ template
|
||||
library, which implements form of <emphasis>lambda abstractions</emphasis> for C++.
|
||||
library, which implements a form of <emphasis>lambda abstractions</emphasis> for C++.
|
||||
The term originates from functional programming and lambda calculus, where a lambda abstraction defines an unnamed function.
|
||||
The primary motivation for the BLL is to provide flexible and
|
||||
convenient means to define unnamed function objects for STL algorithms.
|
||||
@@ -65,7 +65,7 @@ In explaining what the library is about, a line of code says more than a thousan
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_getting_started">
|
||||
<section id="lambda.getting_started">
|
||||
<title>Getting Started</title>
|
||||
|
||||
<section>
|
||||
@@ -83,41 +83,41 @@ In explaining what the library is about, a line of code says more than a thousan
|
||||
|
||||
<listitem><para>
|
||||
<filename>lambda/lambda.hpp</filename> defines lambda expressions for different C++
|
||||
operators, see <xref linkend="lambda_sect_operator_expressions"/>.
|
||||
operators, see <xref linkend="lambda.operator_expressions"/>.
|
||||
</para></listitem>
|
||||
|
||||
<listitem><para>
|
||||
<filename>lambda/bind.hpp</filename> defines <literal>bind</literal> functions for up to 9 arguments, see <xref linkend="lambda_sect_bind_expressions"/>.</para></listitem>
|
||||
<filename>lambda/bind.hpp</filename> defines <literal>bind</literal> functions for up to 9 arguments, see <xref linkend="lambda.bind_expressions"/>.</para></listitem>
|
||||
|
||||
|
||||
<listitem><para>
|
||||
<filename>lambda/if.hpp</filename> defines lambda function equivalents for if statements and the conditional operator, see <xref linkend="lambda_sect_lambda_expressions_for_control_structures"/> (includes <filename>lambda.hpp</filename>).
|
||||
<filename>lambda/if.hpp</filename> defines lambda function equivalents for if statements and the conditional operator, see <xref linkend="lambda.lambda_expressions_for_control_structures"/> (includes <filename>lambda.hpp</filename>).
|
||||
</para></listitem>
|
||||
|
||||
<listitem><para>
|
||||
<filename>lambda/loops.hpp</filename> defines lambda function equivalent for looping constructs, see <xref linkend="lambda_sect_lambda_expressions_for_control_structures"/>.
|
||||
<filename>lambda/loops.hpp</filename> defines lambda function equivalent for looping constructs, see <xref linkend="lambda.lambda_expressions_for_control_structures"/>.
|
||||
</para></listitem>
|
||||
|
||||
<listitem><para>
|
||||
<filename>lambda/switch.hpp</filename> defines lambda function equivalent for the switch statement, see <xref linkend="lambda_sect_lambda_expressions_for_control_structures"/>.
|
||||
<filename>lambda/switch.hpp</filename> defines lambda function equivalent for the switch statement, see <xref linkend="lambda.lambda_expressions_for_control_structures"/>.
|
||||
</para></listitem>
|
||||
|
||||
<listitem><para>
|
||||
<filename>lambda/construct.hpp</filename> provides tools for writing lambda expressions with constructor, destructor, new and delete invocations, see <xref linkend="lambda_sect_construction_and_destruction"/> (includes <filename>lambda.hpp</filename>).
|
||||
<filename>lambda/construct.hpp</filename> provides tools for writing lambda expressions with constructor, destructor, new and delete invocations, see <xref linkend="lambda.construction_and_destruction"/> (includes <filename>lambda.hpp</filename>).
|
||||
</para></listitem>
|
||||
|
||||
<listitem><para>
|
||||
<filename>lambda/casts.hpp</filename> provides lambda versions of different casts, as well as <literal>sizeof</literal> and <literal>typeid</literal>, see <xref linkend="lambda_sect_cast_expressions"/>.
|
||||
<filename>lambda/casts.hpp</filename> provides lambda versions of different casts, as well as <literal>sizeof</literal> and <literal>typeid</literal>, see <xref linkend="lambda.cast_expressions"/>.
|
||||
</para></listitem>
|
||||
|
||||
<listitem><para>
|
||||
<filename>lambda/exceptions.hpp</filename> gives tools for throwing and catching
|
||||
exceptions within lambda functions, <xref linkend="lambda_sect_exceptions"/> (includes
|
||||
exceptions within lambda functions, <xref linkend="lambda.exceptions"/> (includes
|
||||
<filename>lambda.hpp</filename>).
|
||||
</para></listitem>
|
||||
|
||||
<listitem><para>
|
||||
<filename>lambda/algorithm.hpp</filename> and <filename>lambda/numeric.hpp</filename> (cf. standard <filename>algortihm</filename> and <filename>numeric</filename> headers) allow nested STL algorithm invocations, see <xref linkend="lambda_sect_nested_stl_algorithms"/>.
|
||||
<filename>lambda/algorithm.hpp</filename> and <filename>lambda/numeric.hpp</filename> (cf. standard <filename>algortihm</filename> and <filename>numeric</filename> headers) allow nested STL algorithm invocations, see <xref linkend="lambda.nested_stl_algorithms"/>.
|
||||
</para></listitem>
|
||||
|
||||
</itemizedlist>
|
||||
@@ -165,8 +165,8 @@ The STL contains predefined function objects for some common cases (such as <lit
|
||||
As an example, one possible implementation for the standard <literal>plus</literal> template is:
|
||||
|
||||
<programlisting>
|
||||
<![CDATA[template <class T> : public binary_function<T, T, T>
|
||||
struct plus {
|
||||
<![CDATA[template <class T>
|
||||
struct plus : public binary_function<T, T, T> {
|
||||
T operator()(const T& i, const T& j) const {
|
||||
return i + j;
|
||||
}
|
||||
@@ -362,7 +362,7 @@ Hence, there is no syntactic keyword for C++ lambda expressions.
|
||||
|
||||
|
||||
|
||||
<section id="lambda_sect_partial_function_application">
|
||||
<section id="lambda.partial_function_application">
|
||||
<title>Partial function application</title>
|
||||
|
||||
<para>
|
||||
@@ -382,7 +382,7 @@ In partial function application, some of the arguments of a function are bound t
|
||||
|
||||
|
||||
|
||||
<section id="lambda_sect_terminology">
|
||||
<section id="lambda.terminology">
|
||||
<title>Terminology</title>
|
||||
|
||||
<para>
|
||||
@@ -398,7 +398,7 @@ In partial function application, some of the arguments of a function are bound t
|
||||
|
||||
</section>
|
||||
|
||||
<section id = "lambda_sect_using_library">
|
||||
<section id = "lambda.using_library">
|
||||
<title>Using the library</title>
|
||||
|
||||
<para>
|
||||
@@ -408,7 +408,7 @@ There are quite a lot of exceptions and special cases, but discussion of them is
|
||||
|
||||
</para>
|
||||
|
||||
<section id = "lambda_sect_introductory_examples">
|
||||
<section id = "lambda.introductory_examples">
|
||||
<title>Introductory Examples</title>
|
||||
|
||||
<para>
|
||||
@@ -480,7 +480,7 @@ The BLL provides functions <literal>constant</literal> and <literal>var</literal
|
||||
<programlisting>
|
||||
<![CDATA[for_each(vp.begin(), vp.end(), cout << constant('\n') << *_1);]]>
|
||||
</programlisting>
|
||||
These functions are described more thoroughly in <xref linkend="lambda_sect_delaying_constants_and_variables"/>
|
||||
These functions are described more thoroughly in <xref linkend="lambda.delaying_constants_and_variables"/>
|
||||
|
||||
</para>
|
||||
|
||||
@@ -491,7 +491,7 @@ These functions are described more thoroughly in <xref linkend="lambda_sect_dela
|
||||
</section>
|
||||
|
||||
|
||||
<section id="lambda_sect_parameter_and_return_types">
|
||||
<section id="lambda.parameter_and_return_types">
|
||||
<title>Parameter and return types of lambda functors</title>
|
||||
|
||||
<para>
|
||||
@@ -524,8 +524,8 @@ These functions are described more thoroughly in <xref linkend="lambda_sect_dela
|
||||
|
||||
<para>
|
||||
There are two alternative solutions to this.
|
||||
The first is to extend the BLL type deduction system to cover your own types (see <xref linkend="lambda_sect_extending_return_type_system"/>).
|
||||
The second is to use a special lambda expression (<literal>ret</literal>) which defines the return type in place (see <xref linkend = "lambda_sect_overriding_deduced_return_type"/>):
|
||||
The first is to extend the BLL type deduction system to cover your own types (see <xref linkend="lambda.extending"/>).
|
||||
The second is to use a special lambda expression (<literal>ret</literal>) which defines the return type in place (see <xref linkend = "lambda.overriding_deduced_return_type"/>):
|
||||
|
||||
<programlisting><![CDATA[A a; B b; ret<C>(_1 + _2)(a, b);]]></programlisting>
|
||||
</para>
|
||||
@@ -536,18 +536,18 @@ These functions are described more thoroughly in <xref linkend="lambda_sect_dela
|
||||
|
||||
<!--
|
||||
A rare case, where the <literal><![CDATA[ret<type>(bind(...))]]></literal> syntax does not work, but
|
||||
<literal><![CDATA[bind<type>(...)]]></literal> does, is explained in <xref linkend="lambda_sect_nullary_functors_and_ret"/>.
|
||||
<literal><![CDATA[bind<type>(...)]]></literal> does, is explained in <xref linkend="lambda.nullary_functors_and_ret"/>.
|
||||
-->
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_actual_arguments_to_lambda_functors">
|
||||
<section id="lambda.actual_arguments_to_lambda_functors">
|
||||
<title>About actual arguments to lambda functors</title>
|
||||
|
||||
<para><emphasis>This section is no longer (or currently) relevant;
|
||||
<!-- <para><emphasis>This section is no longer (or currently) relevant;
|
||||
acual arguments can be non-const rvalues.
|
||||
The section can, however, become relevant again, if in the future BLL will support
|
||||
lambda functors with higher arities than 3.</emphasis></para>
|
||||
lambda functors with higher arities than 3.</emphasis></para> -->
|
||||
|
||||
<para>A general restriction for the actual arguments is that they cannot be non-const rvalues.
|
||||
For example:
|
||||
@@ -562,7 +562,7 @@ int i = 1; int j = 2;
|
||||
Since the lambda functors are most often called inside STL-algorithms,
|
||||
the arguments originate from dereferencing iterators and the dereferencing operators seldom return rvalues.
|
||||
And for the cases where they do, there are workarounds discussed in
|
||||
<xref linkend="lambda_sect_rvalues_as_actual_arguments"/>.
|
||||
<xref linkend="lambda.rvalues_as_actual_arguments"/>.
|
||||
|
||||
|
||||
</para>
|
||||
@@ -570,7 +570,7 @@ int i = 1; int j = 2;
|
||||
</section>
|
||||
|
||||
|
||||
<section id="lambda_sect_storing_bound_arguments">
|
||||
<section id="lambda.storing_bound_arguments">
|
||||
|
||||
<title>Storing bound arguments in lambda functions</title>
|
||||
|
||||
@@ -642,7 +642,7 @@ exist for historical reasons,
|
||||
and <literal>ref</literal> can always
|
||||
be replaced with <literal>var</literal>, and <literal>cref</literal> with
|
||||
<literal>constant_ref</literal>.
|
||||
See <xref linkend="lambda_sect_delaying_constants_and_variables"/> for details.
|
||||
See <xref linkend="lambda.delaying_constants_and_variables"/> for details.
|
||||
The <literal>ref</literal> and <literal>cref</literal> functions are
|
||||
general purpose utility functions in Boost, and hence defined directly
|
||||
in the <literal moreinfo="none">boost</literal> namespace.
|
||||
@@ -702,7 +702,7 @@ This is to prevent pointer arithmetic making non-const arrays const.
|
||||
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_lambda_expressions_in_details">
|
||||
<section id="lambda.le_in_details">
|
||||
<title>Lambda expressions in details</title>
|
||||
|
||||
<para>
|
||||
@@ -712,7 +712,7 @@ We devote a separate section for each of the possible forms of a lambda expressi
|
||||
|
||||
</para>
|
||||
|
||||
<section id="lambda_sect_placeholders">
|
||||
<section id="lambda.placeholders">
|
||||
<title>Placeholders</title>
|
||||
|
||||
<para>
|
||||
@@ -758,14 +758,14 @@ _1(i, j, k) // returns i, discards j and k
|
||||
</programlisting>
|
||||
|
||||
See
|
||||
<xref linkend="lambda_sect_why_weak_arity"/> for the design rationale behind this
|
||||
<xref linkend="lambda.why_weak_arity"/> for the design rationale behind this
|
||||
functionality.
|
||||
|
||||
</para>
|
||||
|
||||
<para>
|
||||
In addition to these three placeholder types, there is also a fourth placeholder type <literal>placeholderE_type</literal>.
|
||||
The use of this placeholder is defined in <xref linkend="lambda_sect_exceptions"/> describing exception handling in lambda expressions.
|
||||
The use of this placeholder is defined in <xref linkend="lambda.exceptions"/> describing exception handling in lambda expressions.
|
||||
</para>
|
||||
|
||||
<para>When an actual argument is supplied for a placeholder, the parameter passing mode is always by reference.
|
||||
@@ -782,7 +782,7 @@ For example:
|
||||
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_operator_expressions">
|
||||
<section id="lambda.operator_expressions">
|
||||
<title>Operator expressions</title>
|
||||
|
||||
<para>
|
||||
@@ -809,7 +809,7 @@ These operators are <literal>->.</literal>, <literal>-></literal>, <literal>new<
|
||||
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_assignment_and_subscript">
|
||||
<section id="lambda.assignment_and_subscript">
|
||||
<title>Assignment and subscript operators</title>
|
||||
|
||||
<para>
|
||||
@@ -822,7 +822,7 @@ _1 = i; // ok
|
||||
i = _1; // not ok. i is not a lambda expression
|
||||
</programlisting>
|
||||
|
||||
There is a simple solution around this limitation, described in <xref linkend="lambda_sect_delaying_constants_and_variables"/>.
|
||||
There is a simple solution around this limitation, described in <xref linkend="lambda.delaying_constants_and_variables"/>.
|
||||
In short,
|
||||
the left hand argument can be explicitly turned into a lambda functor by wrapping it with a special <literal>var</literal> function:
|
||||
<programlisting>
|
||||
@@ -832,7 +832,7 @@ var(i) = _1; // ok
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_logical_operators">
|
||||
<section id="lambda.logical_operators">
|
||||
<title>Logical operators</title>
|
||||
|
||||
<para>
|
||||
@@ -844,7 +844,7 @@ bool flag = true; int i = 0;
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_comma_operator">
|
||||
<section id="lambda.comma_operator">
|
||||
<title>Comma operator</title>
|
||||
|
||||
<para>
|
||||
@@ -863,7 +863,7 @@ In the above example, each element of <literal>a</literal> is first incremented,
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_function_call_operator">
|
||||
<section id="lambda.function_call_operator">
|
||||
<title>Function call operator</title>
|
||||
|
||||
<para>
|
||||
@@ -873,7 +873,7 @@ Calls with too few arguments lead to a compile time error.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_member_pointer_operator">
|
||||
<section id="lambda.member_pointer_operator">
|
||||
<title>Member pointer operator</title>
|
||||
|
||||
<para>
|
||||
@@ -925,7 +925,7 @@ B* b = new B();
|
||||
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_bind_expressions">
|
||||
<section id="lambda.bind_expressions">
|
||||
<title>Bind expressions</title>
|
||||
|
||||
<para>
|
||||
@@ -946,7 +946,7 @@ Basically, the
|
||||
<emphasis><literal>bind-argument-list</literal></emphasis> must be a valid argument list for the target function, except that any argument can be replaced with a placeholder, or more generally, with a lambda expression.
|
||||
Note that also the target function can be a lambda expression.
|
||||
|
||||
The result of a bind expression is either a nullary, unary, binary or 3-ary function object depending on the use of placeholders in the <emphasis><literal>bind-argument-list</literal></emphasis> (see <xref linkend="lambda_sect_placeholders"/>).
|
||||
The result of a bind expression is either a nullary, unary, binary or 3-ary function object depending on the use of placeholders in the <emphasis><literal>bind-argument-list</literal></emphasis> (see <xref linkend="lambda.placeholders"/>).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -961,7 +961,7 @@ This is only necessary if the return type of the target function cannot be deduc
|
||||
The following sections describe the different types of bind expressions.
|
||||
</para>
|
||||
|
||||
<section id="lambda_sect_function_pointers_as_targets">
|
||||
<section id="lambda.function_pointers_as_targets">
|
||||
<title>Function pointers or references as targets</title>
|
||||
|
||||
<para>The target function can be a pointer or a reference to a function and it can be either bound or unbound. For example:
|
||||
@@ -1062,7 +1062,7 @@ find_if(pointers.begin(), pointers.end(), bind(&A::foo, _1, 1));]]>
|
||||
<para>
|
||||
Even though the interfaces are the same, there are important semantic differences between using a pointer or a reference as the object argument.
|
||||
The differences stem from the way <literal>bind</literal>-functions take their parameters, and how the bound parameters are stored within the lambda functor.
|
||||
The object argument has the same parameter passing and storing mechanism as any other bind argument slot (see <xref linkend="lambda_sect_storing_bound_arguments"/>); it is passed as a const reference and stored as a const copy in the lambda functor.
|
||||
The object argument has the same parameter passing and storing mechanism as any other bind argument slot (see <xref linkend="lambda.storing_bound_arguments"/>); it is passed as a const reference and stored as a const copy in the lambda functor.
|
||||
This creates some asymmetry between the lambda functor and the original member function, and between seemingly similar lambda functors. For example:
|
||||
<programlisting>
|
||||
class A {
|
||||
@@ -1114,7 +1114,7 @@ bind(&A::set_j, _1, 1)(a); // a.j == 1]]>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_members_variables_as_targets">
|
||||
<section id="lambda.members_variables_as_targets">
|
||||
<title>Member variables as targets</title>
|
||||
|
||||
<para>
|
||||
@@ -1140,7 +1140,7 @@ bind(&A::data, _1)(ca) = 1; // error]]>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_function_objects_as_targets">
|
||||
<section id="lambda.function_objects_as_targets">
|
||||
<title>Function objects as targets</title>
|
||||
|
||||
<para>
|
||||
@@ -1235,8 +1235,8 @@ of one of the arguments, and how that dependency can be expressed with the
|
||||
<![CDATA[struct A {
|
||||
|
||||
// the return type equals the third argument type:
|
||||
template<class T1, T2, T3>
|
||||
T3 operator()(const T1& t1, const T2& t2, const T3& t3);
|
||||
template<class T1, class T2, class T3>
|
||||
T3 operator()(const T1& t1, const T2& t2, const T3& t3) const;
|
||||
|
||||
template <class Args>
|
||||
class sig {
|
||||
@@ -1246,7 +1246,7 @@ of one of the arguments, and how that dependency can be expressed with the
|
||||
public:
|
||||
typedef typename
|
||||
boost::remove_cv<T3>::type type;
|
||||
}
|
||||
};
|
||||
};]]>
|
||||
</programlisting>
|
||||
|
||||
@@ -1289,12 +1289,12 @@ mechanism first introduced in the FC++ library
|
||||
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_overriding_deduced_return_type">
|
||||
<section id="lambda.overriding_deduced_return_type">
|
||||
<title>Overriding the deduced return type</title>
|
||||
|
||||
<para>
|
||||
The return type deduction system may not be able to deduce the return types of some user defined operators or bind expressions with class objects.
|
||||
<!-- (see the example in <xref linkend="lambda_sect_parameter_and_return_types"/>).-->
|
||||
<!-- (see the example in <xref linkend="lambda.parameter_and_return_types"/>).-->
|
||||
A special lambda expression type is provided for stating the return type explicitly and overriding the deduction system.
|
||||
To state that the return type of the lambda functor defined by the lambda expression <literal>e</literal> is <literal>T</literal>, you can write:
|
||||
|
||||
@@ -1342,10 +1342,10 @@ ret<D>( - ret<C>(_1 + _2))(a, b); // ok]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>If you find yourself using <literal>ret</literal> repeatedly with the same types, it is worth while extending the return type deduction (see <xref linkend="lambda_sect_extending_return_type_system"/>).
|
||||
<para>If you find yourself using <literal>ret</literal> repeatedly with the same types, it is worth while extending the return type deduction (see <xref linkend="lambda.extending"/>).
|
||||
</para>
|
||||
|
||||
<section id="lambda_sect_nullary_functors_and_ret">
|
||||
<section id="lambda.nullary_functors_and_ret">
|
||||
<title>Nullary lambda functors and ret</title>
|
||||
|
||||
<para>
|
||||
@@ -1383,7 +1383,7 @@ apart from the fact that for some nullary lambda functors the former does not wo
|
||||
</section>
|
||||
|
||||
|
||||
<section id="lambda_sect_delaying_constants_and_variables">
|
||||
<section id="lambda.delaying_constants_and_variables">
|
||||
<title>Delaying constants and variables</title>
|
||||
|
||||
<para>
|
||||
@@ -1478,11 +1478,11 @@ for_each(a.begin(),a.end(), cout << space << _1);]]>
|
||||
<title>About assignment and subscript operators</title>
|
||||
|
||||
<para>
|
||||
As described in <xref linkend="lambda_sect_assignment_and_subscript"/>, assignment and subscripting operators are always defined as member functions.
|
||||
As described in <xref linkend="lambda.assignment_and_subscript"/>, assignment and subscripting operators are always defined as member functions.
|
||||
This means, that for expressions of the form
|
||||
<literal>x = y</literal> or <literal>x[y]</literal> to be interpreted as lambda expressions, the left-hand operand <literal>x</literal> must be a lambda expression.
|
||||
Consequently, it is sometimes necessary to use <literal>var</literal> for this purpose.
|
||||
We repeat the example from <xref linkend="lambda_sect_assignment_and_subscript"/>:
|
||||
We repeat the example from <xref linkend="lambda.assignment_and_subscript"/>:
|
||||
|
||||
<programlisting>
|
||||
int i;
|
||||
@@ -1501,7 +1501,7 @@ For example, <literal>i += _1</literal> is equivalent to <literal>var(i) += _1</
|
||||
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_lambda_expressions_for_control_structures">
|
||||
<section id="lambda.lambda_expressions_for_control_structures">
|
||||
<title>Lambda expressions for control structures</title>
|
||||
|
||||
<para>
|
||||
@@ -1561,7 +1561,7 @@ for_each(a, a+5,
|
||||
</programlisting>
|
||||
|
||||
<!--
|
||||
As explained in <xref linkend="lambda_sect_delaying_constants_and_variables"/>, we can avoid the repeated use of wrapping of <literal>var</literal> if we define it beforehand:
|
||||
As explained in <xref linkend="lambda.delaying_constants_and_variables"/>, we can avoid the repeated use of wrapping of <literal>var</literal> if we define it beforehand:
|
||||
|
||||
<programlisting>
|
||||
<![CDATA[int i;
|
||||
@@ -1601,7 +1601,7 @@ of these syntaces.
|
||||
|
||||
|
||||
|
||||
<section id="lambda_sect_switch_statement">
|
||||
<section id="lambda.switch_statement">
|
||||
<title>Switch statement</title>
|
||||
</section>
|
||||
|
||||
@@ -1654,7 +1654,7 @@ Note that another lambda expression is sequenced after the <literal>switch_state
|
||||
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_exceptions">
|
||||
<section id="lambda.exceptions">
|
||||
<title>Exceptions</title>
|
||||
|
||||
<para>
|
||||
@@ -1734,7 +1734,7 @@ The last line of the second handler constructs a new exception object and
|
||||
throws that with <literal>throw exception</literal>.
|
||||
|
||||
Constructing and destructing objects within lambda expressions is
|
||||
explained in <xref linkend="lambda_sect_construction_and_destruction"/>
|
||||
explained in <xref linkend="lambda.construction_and_destruction"/>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -1768,7 +1768,7 @@ rethrowing exceptions.
|
||||
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_construction_and_destruction">
|
||||
<section id="lambda.construction_and_destruction">
|
||||
<title>Construction and destruction</title>
|
||||
|
||||
|
||||
@@ -1908,7 +1908,7 @@ For example:
|
||||
int foo(int); int bar(int);
|
||||
...
|
||||
int i;
|
||||
bind(foo, bind(bar, _1)(i);
|
||||
bind(foo, bind(bar, _1))(i);
|
||||
</programlisting>
|
||||
|
||||
The last line makes the call <literal>foo(bar(i));</literal>
|
||||
@@ -1940,7 +1940,7 @@ bind(bind(&add_or_mul, _1), _2, _3)(condition, i, j);
|
||||
|
||||
|
||||
|
||||
<section id="lambda_sect_unlambda">
|
||||
<section id="lambda.unlambda">
|
||||
<title>Unlambda</title>
|
||||
|
||||
<para>A nested bind expression may occur inadvertently,
|
||||
@@ -2063,22 +2063,22 @@ and thus finally 13.
|
||||
<para>
|
||||
Primary motivation for including <literal>protect</literal> into the library,
|
||||
was to allow nested STL algorithm invocations
|
||||
(<xref linkend="lambda_sect_nested_stl_algorithms"/>).
|
||||
(<xref linkend="lambda.nested_stl_algorithms"/>).
|
||||
</para>
|
||||
|
||||
</section>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_rvalues_as_actual_arguments">
|
||||
<section id="lambda.rvalues_as_actual_arguments">
|
||||
<title>Rvalues as actual arguments to lambda functors</title>
|
||||
|
||||
<para><emphasis>This section and all of its subsections
|
||||
<!-- <para><emphasis>This section and all of its subsections
|
||||
are no longer (or currently) relevant;
|
||||
acual arguments can be non-const rvalues and these workarounds are thus
|
||||
not needed.
|
||||
The section can, however, become relevant again, if in the future BLL will support
|
||||
lambda functors with higher arities than 3.</emphasis></para>
|
||||
lambda functors with higher arities than 3.</emphasis></para> -->
|
||||
|
||||
<para>
|
||||
Actual arguments to the lambda functors cannot be non-const rvalues.
|
||||
@@ -2088,7 +2088,7 @@ or there can be no side-effects to the actual arguments.
|
||||
There are ways around this limitation.
|
||||
|
||||
We repeat the example from section
|
||||
<xref linkend="lambda_sect_actual_arguments_to_lambda_functors"/> and list the
|
||||
<xref linkend="lambda.actual_arguments_to_lambda_functors"/> and list the
|
||||
different solutions:
|
||||
|
||||
<programlisting>
|
||||
@@ -2188,7 +2188,7 @@ and are not affected by the non-const rvalue problem.
|
||||
<section>
|
||||
<title>Casts, sizeof and typeid</title>
|
||||
|
||||
<section id="lambda_sect_cast_expressions">
|
||||
<section id="lambda.cast_expressions">
|
||||
<title>
|
||||
Cast expressions
|
||||
</title>
|
||||
@@ -2257,7 +2257,7 @@ function of that class.
|
||||
|
||||
</section>
|
||||
|
||||
<section id="lambda_sect_nested_stl_algorithms">
|
||||
<section id="lambda.nested_stl_algorithms">
|
||||
<title>Nesting STL algorithm invocations</title>
|
||||
|
||||
<para>
|
||||
@@ -2351,11 +2351,11 @@ calling templated functions ...
|
||||
|
||||
-->
|
||||
|
||||
<section id="lambda_sect_extending_return_type_system">
|
||||
<section id="lambda.extending">
|
||||
<title>Extending return type deduction system</title>
|
||||
|
||||
<para>
|
||||
<!--The <xref linkend = "lambda_sect_overriding_deduced_return_type"/> showed how to make BLL aware of the return type of a function object in bind expressions.-->
|
||||
<!--The <xref linkend = "lambda.overriding_deduced_return_type"/> showed how to make BLL aware of the return type of a function object in bind expressions.-->
|
||||
|
||||
In this section, we explain how to extend the return type deduction system
|
||||
to cover user defined operators.
|
||||
@@ -2640,6 +2640,7 @@ which require that the argument types are references.
|
||||
<row><entry><literal><![CDATA[&]]></literal></entry><entry><literal><![CDATA[other_action<address_of_action>]]></literal></entry></row>
|
||||
<row><entry><literal><![CDATA[*]]></literal></entry><entry><literal><![CDATA[other_action<contents_of_action>]]></literal></entry></row>
|
||||
<row><entry><literal><![CDATA[,]]></literal></entry><entry><literal><![CDATA[other_action<comma_action>]]></literal></entry></row>
|
||||
<row><entry><literal><![CDATA[->*]]></literal></entry><entry><literal><![CDATA[other_action<member_pointer_action>]]></literal></entry></row>
|
||||
|
||||
</tbody>
|
||||
</tgroup>
|
||||
@@ -3147,7 +3148,7 @@ To get this functionality in BLL, the bind expression inside the <literal morein
|
||||
<programlisting>
|
||||
bind(unlambda(f), _1)(x);
|
||||
</programlisting>
|
||||
as explained in <xref linkend = "lambda_sect_unlambda"/>.
|
||||
as explained in <xref linkend = "lambda.unlambda"/>.
|
||||
|
||||
</section>
|
||||
|
||||
@@ -3190,10 +3191,10 @@ to extend the library with new features.
|
||||
|
||||
|
||||
|
||||
<appendix>
|
||||
<section>
|
||||
<title>Rationale for some of the design decisions</title>
|
||||
|
||||
<section id="lambda_sect_why_weak_arity">
|
||||
<section id="lambda.why_weak_arity">
|
||||
<title>
|
||||
Lambda functor arity
|
||||
</title>
|
||||
@@ -3255,7 +3256,7 @@ was dropped.
|
||||
|
||||
</section>
|
||||
|
||||
</appendix>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
@@ -3445,16 +3446,7 @@ was dropped.
|
||||
</biblioentry>
|
||||
|
||||
|
||||
|
||||
|
||||
</bibliography>
|
||||
|
||||
|
||||
|
||||
</library>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// -- algorithm.hpp -- Boost Lambda Library -----------------------------------
|
||||
// Copyright (C) 2002 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2002 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2002 Gary Powell (gwpowell@hotmail.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// -- bind.hpp -- Boost Lambda Library --------------------------------------
|
||||
|
||||
// Copyright (C) 1999-2001 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999-2001 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Gary Powell (gwpowell@hotmail.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// - casts.hpp -- BLambda Library -------------
|
||||
//
|
||||
// Copyright (C) 2000 Gary Powell (powellg@amazon.com)
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -14,11 +14,17 @@
|
||||
#if !defined(BOOST_LAMBDA_CASTS_HPP)
|
||||
#define BOOST_LAMBDA_CASTS_HPP
|
||||
|
||||
#include "boost/lambda/detail/suppress_unused.hpp"
|
||||
#include "boost/lambda/core.hpp"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
namespace boost {
|
||||
namespace lambda {
|
||||
|
||||
template<class Act, class Args>
|
||||
struct return_type_N;
|
||||
|
||||
template<class T> class cast_action;
|
||||
|
||||
template<class T> class static_cast_action;
|
||||
@@ -64,11 +70,12 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// typedid action
|
||||
// typeid action
|
||||
class typeid_action {
|
||||
public:
|
||||
template<class RET, class Arg1>
|
||||
static RET apply(Arg1 &a1) {
|
||||
detail::suppress_unused_variable_warnings(a1);
|
||||
return typeid(a1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -251,7 +251,7 @@ private:
|
||||
closure& operator=(closure const&); // no assign
|
||||
|
||||
template <int N, typename ClosureT>
|
||||
friend struct closure_member;
|
||||
friend class closure_member;
|
||||
|
||||
template <typename ClosureT>
|
||||
friend class closure_frame;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// - construct.hpp -- Lambda Library -------------
|
||||
//
|
||||
// Copyright (C) 2000 Gary Powell (powellg@amazon.com)
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -14,6 +14,9 @@
|
||||
#if !defined(BOOST_LAMBDA_CONSTRUCT_HPP)
|
||||
#define BOOST_LAMBDA_CONSTRUCT_HPP
|
||||
|
||||
#include "boost/type_traits/remove_cv.hpp"
|
||||
#include "boost/type_traits/is_pointer.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace lambda {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// -- control_structures.hpp -- Boost Lambda Library --------------------------
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "boost/lambda/detail/operator_actions.hpp"
|
||||
#include "boost/lambda/detail/operator_return_type_traits.hpp"
|
||||
|
||||
#include "boost/lambda/detail/control_structures_impl.hpp"
|
||||
#include "boost/lambda/if.hpp"
|
||||
#include "boost/lambda/loops.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// -- core.hpp -- Boost Lambda Library -------------------------------------
|
||||
//
|
||||
// Copyright (C) 2000 Gary Powell (powellg@amazon.com)
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// -- Boost Lambda Library - actions.hpp ----------------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// -- Boost Lambda Library -------------------------------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// -- bind_functions.hpp -- Boost Lambda Library
|
||||
//
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library -- control_constructs_common.hpp -------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
|
||||
@@ -1,550 +0,0 @@
|
||||
// Boost Lambda Library -- control_structures_impl.hpp ---------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// For more information, see www.boost.org
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#if !defined(BOOST_LAMBDA_CONTROL_CONSTRUCTS_HPP)
|
||||
#define BOOST_LAMBDA_CONTROL_CONSTRUCTS_HPP
|
||||
|
||||
namespace boost {
|
||||
namespace lambda {
|
||||
|
||||
// -- void return control actions ----------------------
|
||||
|
||||
class forloop_action {};
|
||||
class forloop_no_body_action {};
|
||||
class ifthen_action {};
|
||||
class ifthenelse_action {};
|
||||
class whileloop_action {};
|
||||
class whileloop_no_body_action {};
|
||||
class dowhileloop_action {};
|
||||
class dowhileloop_no_body_action {};
|
||||
// -- nonvoid return control actions ----------------------
|
||||
|
||||
class ifthenelsereturn_action {};
|
||||
|
||||
// For loop
|
||||
template <class Arg1, class Arg2, class Arg3, class Arg4>
|
||||
inline const
|
||||
lambda_functor<
|
||||
lambda_functor_base<
|
||||
forloop_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
|
||||
lambda_functor<Arg3>, lambda_functor<Arg4> >
|
||||
>
|
||||
>
|
||||
for_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2,
|
||||
const lambda_functor<Arg3>& a3, const lambda_functor<Arg4>& a4) {
|
||||
return
|
||||
lambda_functor_base<
|
||||
forloop_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
|
||||
lambda_functor<Arg3>, lambda_functor<Arg4> >
|
||||
>
|
||||
( tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
|
||||
lambda_functor<Arg3>, lambda_functor<Arg4> >(a1, a2, a3, a4)
|
||||
);
|
||||
}
|
||||
|
||||
// No body case.
|
||||
template <class Arg1, class Arg2, class Arg3>
|
||||
inline const
|
||||
lambda_functor<
|
||||
lambda_functor_base<
|
||||
forloop_no_body_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2>, lambda_functor<Arg3> >
|
||||
>
|
||||
>
|
||||
for_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2,
|
||||
const lambda_functor<Arg3>& a3) {
|
||||
return
|
||||
lambda_functor_base<
|
||||
forloop_no_body_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
|
||||
lambda_functor<Arg3> >
|
||||
>
|
||||
( tuple<lambda_functor<Arg1>, lambda_functor<Arg2>,
|
||||
lambda_functor<Arg3> >(a1, a2, a3) );
|
||||
}
|
||||
|
||||
// While loop
|
||||
template <class Arg1, class Arg2>
|
||||
inline const
|
||||
lambda_functor<
|
||||
lambda_functor_base<
|
||||
whileloop_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
|
||||
>
|
||||
>
|
||||
while_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2) {
|
||||
return
|
||||
lambda_functor_base<
|
||||
whileloop_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
|
||||
>
|
||||
( tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >(a1, a2));
|
||||
}
|
||||
|
||||
// No body case.
|
||||
template <class Arg1>
|
||||
inline const
|
||||
lambda_functor<
|
||||
lambda_functor_base<
|
||||
whileloop_no_body_action,
|
||||
tuple<lambda_functor<Arg1> >
|
||||
>
|
||||
>
|
||||
while_loop(const lambda_functor<Arg1>& a1) {
|
||||
return
|
||||
lambda_functor_base<
|
||||
whileloop_no_body_action,
|
||||
tuple<lambda_functor<Arg1> >
|
||||
>
|
||||
( tuple<lambda_functor<Arg1> >(a1) );
|
||||
}
|
||||
|
||||
|
||||
// Do While loop
|
||||
template <class Arg1, class Arg2>
|
||||
inline const
|
||||
lambda_functor<
|
||||
lambda_functor_base<
|
||||
dowhileloop_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
|
||||
>
|
||||
>
|
||||
do_while_loop(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2) {
|
||||
return
|
||||
lambda_functor_base<
|
||||
dowhileloop_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
|
||||
>
|
||||
( tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >(a1, a2));
|
||||
}
|
||||
|
||||
// No body case.
|
||||
template <class Arg1>
|
||||
inline const
|
||||
lambda_functor<
|
||||
lambda_functor_base<
|
||||
dowhileloop_no_body_action,
|
||||
tuple<lambda_functor<Arg1> >
|
||||
>
|
||||
>
|
||||
do_while_loop(const lambda_functor<Arg1>& a1) {
|
||||
return
|
||||
lambda_functor_base<
|
||||
dowhileloop_no_body_action,
|
||||
tuple<lambda_functor<Arg1> >
|
||||
>
|
||||
( tuple<lambda_functor<Arg1> >(a1));
|
||||
}
|
||||
|
||||
|
||||
// If Then
|
||||
template <class Arg1, class Arg2>
|
||||
inline const
|
||||
lambda_functor<
|
||||
lambda_functor_base<
|
||||
ifthen_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
|
||||
>
|
||||
>
|
||||
if_then(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2) {
|
||||
return
|
||||
lambda_functor_base<
|
||||
ifthen_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >
|
||||
>
|
||||
( tuple<lambda_functor<Arg1>, lambda_functor<Arg2> >(a1, a2) );
|
||||
}
|
||||
|
||||
// If then else
|
||||
|
||||
template <class Arg1, class Arg2, class Arg3>
|
||||
inline const
|
||||
lambda_functor<
|
||||
lambda_functor_base<
|
||||
ifthenelse_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2>, lambda_functor<Arg3> >
|
||||
>
|
||||
>
|
||||
if_then_else(const lambda_functor<Arg1>& a1, const lambda_functor<Arg2>& a2,
|
||||
const lambda_functor<Arg3>& a3) {
|
||||
return
|
||||
lambda_functor_base<
|
||||
ifthenelse_action,
|
||||
tuple<lambda_functor<Arg1>, lambda_functor<Arg2>, lambda_functor<Arg3> >
|
||||
>
|
||||
(tuple<lambda_functor<Arg1>, lambda_functor<Arg2>, lambda_functor<Arg3> >
|
||||
(a1, a2, a3) );
|
||||
}
|
||||
|
||||
// Our version of operator?:()
|
||||
|
||||
template <class Arg1, class Arg2, class Arg3>
|
||||
inline const
|
||||
lambda_functor<
|
||||
lambda_functor_base<
|
||||
other_action<ifthenelsereturn_action>,
|
||||
tuple<lambda_functor<Arg1>,
|
||||
typename const_copy_argument<Arg2>::type,
|
||||
typename const_copy_argument<Arg3>::type>
|
||||
>
|
||||
>
|
||||
if_then_else_return(const lambda_functor<Arg1>& a1,
|
||||
const Arg2 & a2,
|
||||
const Arg3 & a3) {
|
||||
return
|
||||
lambda_functor_base<
|
||||
other_action<ifthenelsereturn_action>,
|
||||
tuple<lambda_functor<Arg1>,
|
||||
typename const_copy_argument<Arg2>::type,
|
||||
typename const_copy_argument<Arg3>::type>
|
||||
> ( tuple<lambda_functor<Arg1>,
|
||||
typename const_copy_argument<Arg2>::type,
|
||||
typename const_copy_argument<Arg3>::type> (a1, a2, a3) );
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
// return type specialization for conditional expression begins -----------
|
||||
// start reading below and move upwards
|
||||
|
||||
// PHASE 6:1
|
||||
// check if A is conbertible to B and B to A
|
||||
template<int Phase, bool AtoB, bool BtoA, bool SameType, class A, class B>
|
||||
struct return_type_2_ifthenelsereturn;
|
||||
|
||||
// if A can be converted to B and vice versa -> ambiguous
|
||||
template<int Phase, class A, class B>
|
||||
struct return_type_2_ifthenelsereturn<Phase, true, true, false, A, B> {
|
||||
typedef
|
||||
detail::return_type_deduction_failure<return_type_2_ifthenelsereturn> type;
|
||||
// ambiguous type in conditional expression
|
||||
};
|
||||
// if A can be converted to B and vice versa and are of same type
|
||||
template<int Phase, class A, class B>
|
||||
struct return_type_2_ifthenelsereturn<Phase, true, true, true, A, B> {
|
||||
typedef A type;
|
||||
};
|
||||
|
||||
|
||||
// A can be converted to B
|
||||
template<int Phase, class A, class B>
|
||||
struct return_type_2_ifthenelsereturn<Phase, true, false, false, A, B> {
|
||||
typedef B type;
|
||||
};
|
||||
|
||||
// B can be converted to A
|
||||
template<int Phase, class A, class B>
|
||||
struct return_type_2_ifthenelsereturn<Phase, false, true, false, A, B> {
|
||||
typedef A type;
|
||||
};
|
||||
|
||||
// neither can be converted. Then we drop the potential references, and
|
||||
// try again
|
||||
template<class A, class B>
|
||||
struct return_type_2_ifthenelsereturn<1, false, false, false, A, B> {
|
||||
// it is safe to add const, since the result will be an rvalue and thus
|
||||
// const anyway. The const are needed eg. if the types
|
||||
// are 'const int*' and 'void *'. The remaining type should be 'const void*'
|
||||
typedef const typename boost::remove_reference<A>::type plainA;
|
||||
typedef const typename boost::remove_reference<B>::type plainB;
|
||||
// TODO: Add support for volatile ?
|
||||
|
||||
typedef typename
|
||||
return_type_2_ifthenelsereturn<
|
||||
2,
|
||||
boost::is_convertible<plainA,plainB>::value,
|
||||
boost::is_convertible<plainB,plainA>::value,
|
||||
boost::is_same<plainA,plainB>::value,
|
||||
plainA,
|
||||
plainB>::type type;
|
||||
};
|
||||
|
||||
// PHASE 6:2
|
||||
template<class A, class B>
|
||||
struct return_type_2_ifthenelsereturn<2, false, false, false, A, B> {
|
||||
typedef
|
||||
detail::return_type_deduction_failure<return_type_2_ifthenelsereturn> type;
|
||||
// types_do_not_match_in_conditional_expression
|
||||
};
|
||||
|
||||
|
||||
|
||||
// PHASE 5: now we know that types are not arithmetic.
|
||||
template<class A, class B>
|
||||
struct non_numeric_types {
|
||||
typedef typename
|
||||
return_type_2_ifthenelsereturn<
|
||||
1, // phase 1
|
||||
is_convertible<A,B>::value,
|
||||
is_convertible<B,A>::value,
|
||||
is_same<A,B>::value,
|
||||
A,
|
||||
B>::type type;
|
||||
};
|
||||
|
||||
// PHASE 4 :
|
||||
// the base case covers arithmetic types with differing promote codes
|
||||
// use the type deduction of arithmetic_actions
|
||||
template<int CodeA, int CodeB, class A, class B>
|
||||
struct arithmetic_or_not {
|
||||
typedef typename
|
||||
return_type_2<arithmetic_action<plus_action>, A, B>::type type;
|
||||
// plus_action is just a random pick, has to be a concrete instance
|
||||
};
|
||||
|
||||
// this case covers the case of artihmetic types with the same promote codes.
|
||||
// non numeric deduction is used since e.g. integral promotion is not
|
||||
// performed with operator ?:
|
||||
template<int CodeA, class A, class B>
|
||||
struct arithmetic_or_not<CodeA, CodeA, A, B> {
|
||||
typedef typename non_numeric_types<A, B>::type type;
|
||||
};
|
||||
|
||||
// if either A or B has promote code -1 it is not an arithmetic type
|
||||
template<class A, class B>
|
||||
struct arithmetic_or_not <-1, -1, A, B> {
|
||||
typedef typename non_numeric_types<A, B>::type type;
|
||||
};
|
||||
template<int CodeB, class A, class B>
|
||||
struct arithmetic_or_not <-1, CodeB, A, B> {
|
||||
typedef typename non_numeric_types<A, B>::type type;
|
||||
};
|
||||
template<int CodeA, class A, class B>
|
||||
struct arithmetic_or_not <CodeA, -1, A, B> {
|
||||
typedef typename non_numeric_types<A, B>::type type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// PHASE 3 : Are the types same?
|
||||
// No, check if they are arithmetic or not
|
||||
template <class A, class B>
|
||||
struct same_or_not {
|
||||
typedef typename detail::remove_reference_and_cv<A>::type plainA;
|
||||
typedef typename detail::remove_reference_and_cv<B>::type plainB;
|
||||
|
||||
typedef typename
|
||||
arithmetic_or_not<
|
||||
detail::promote_code<plainA>::value,
|
||||
detail::promote_code<plainB>::value,
|
||||
A,
|
||||
B>::type type;
|
||||
};
|
||||
// Yes, clear.
|
||||
template <class A> struct same_or_not<A, A> {
|
||||
typedef A type;
|
||||
};
|
||||
|
||||
} // detail
|
||||
|
||||
// PHASE 2 : Perform first the potential array_to_pointer conversion
|
||||
template<class A, class B>
|
||||
struct return_type_2<other_action<ifthenelsereturn_action>, A, B> {
|
||||
|
||||
typedef typename detail::array_to_pointer<A>::type A1;
|
||||
typedef typename detail::array_to_pointer<B>::type B1;
|
||||
|
||||
typedef typename
|
||||
boost::add_const<typename detail::same_or_not<A1, B1>::type>::type type;
|
||||
};
|
||||
|
||||
// PHASE 1 : Deduction is based on the second and third operand
|
||||
|
||||
|
||||
// return type specialization for conditional expression ends -----------
|
||||
|
||||
|
||||
|
||||
|
||||
// Control loop lambda_functor_base specializations.
|
||||
|
||||
// Specialization for for_loop.
|
||||
template<class Args>
|
||||
class
|
||||
lambda_functor_base<forloop_action, Args> {
|
||||
public:
|
||||
Args args;
|
||||
template <class T> struct sig { typedef void type; };
|
||||
public:
|
||||
explicit lambda_functor_base(const Args& a) : args(a) {}
|
||||
|
||||
template<class RET, CALL_TEMPLATE_ARGS>
|
||||
RET call(CALL_FORMAL_ARGS) const {
|
||||
for(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS);
|
||||
detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
|
||||
detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS))
|
||||
|
||||
detail::select(boost::tuples::get<3>(args), CALL_ACTUAL_ARGS);
|
||||
}
|
||||
};
|
||||
|
||||
// No body case
|
||||
template<class Args>
|
||||
class
|
||||
lambda_functor_base<forloop_no_body_action, Args> {
|
||||
public:
|
||||
Args args;
|
||||
template <class T> struct sig { typedef void type; };
|
||||
public:
|
||||
explicit lambda_functor_base(const Args& a) : args(a) {}
|
||||
|
||||
template<class RET, CALL_TEMPLATE_ARGS>
|
||||
RET call(CALL_FORMAL_ARGS) const {
|
||||
for(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS);
|
||||
detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
|
||||
detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS)) {}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Specialization for while_loop.
|
||||
template<class Args>
|
||||
class
|
||||
lambda_functor_base<whileloop_action, Args> {
|
||||
public:
|
||||
Args args;
|
||||
template <class T> struct sig { typedef void type; };
|
||||
public:
|
||||
explicit lambda_functor_base(const Args& a) : args(a) {}
|
||||
|
||||
template<class RET, CALL_TEMPLATE_ARGS>
|
||||
RET call(CALL_FORMAL_ARGS) const {
|
||||
while(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS))
|
||||
|
||||
detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
|
||||
}
|
||||
};
|
||||
|
||||
// No body case
|
||||
template<class Args>
|
||||
class
|
||||
lambda_functor_base<whileloop_no_body_action, Args> {
|
||||
public:
|
||||
Args args;
|
||||
template <class T> struct sig { typedef void type; };
|
||||
public:
|
||||
explicit lambda_functor_base(const Args& a) : args(a) {}
|
||||
|
||||
template<class RET, CALL_TEMPLATE_ARGS>
|
||||
RET call(CALL_FORMAL_ARGS) const {
|
||||
while(detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)) {}
|
||||
}
|
||||
};
|
||||
|
||||
// Specialization for do_while_loop.
|
||||
// Note that the first argument is the condition.
|
||||
template<class Args>
|
||||
class
|
||||
lambda_functor_base<dowhileloop_action, Args> {
|
||||
public:
|
||||
Args args;
|
||||
template <class T> struct sig { typedef void type; };
|
||||
public:
|
||||
explicit lambda_functor_base(const Args& a) : args(a) {}
|
||||
|
||||
template<class RET, CALL_TEMPLATE_ARGS>
|
||||
RET call(CALL_FORMAL_ARGS) const {
|
||||
do {
|
||||
detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
|
||||
} while (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) );
|
||||
}
|
||||
};
|
||||
|
||||
// No body case
|
||||
template<class Args>
|
||||
class
|
||||
lambda_functor_base<dowhileloop_no_body_action, Args> {
|
||||
public:
|
||||
Args args;
|
||||
template <class T> struct sig { typedef void type; };
|
||||
public:
|
||||
explicit lambda_functor_base(const Args& a) : args(a) {}
|
||||
|
||||
template<class RET, CALL_TEMPLATE_ARGS>
|
||||
RET call(CALL_FORMAL_ARGS) const {
|
||||
do {} while (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Specialization for if_then.
|
||||
template<class Args>
|
||||
class
|
||||
lambda_functor_base<ifthen_action, Args> {
|
||||
public:
|
||||
Args args;
|
||||
template <class T> struct sig { typedef void type; };
|
||||
public:
|
||||
explicit lambda_functor_base(const Args& a) : args(a) {}
|
||||
|
||||
template<class RET, CALL_TEMPLATE_ARGS>
|
||||
RET call(CALL_FORMAL_ARGS) const {
|
||||
if (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)) detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
|
||||
}
|
||||
};
|
||||
|
||||
// Specialization for if_then_else.
|
||||
template<class Args>
|
||||
class
|
||||
lambda_functor_base<ifthenelse_action, Args> {
|
||||
public:
|
||||
Args args;
|
||||
template <class T> struct sig { typedef void type; };
|
||||
public:
|
||||
explicit lambda_functor_base(const Args& a) : args(a) {}
|
||||
|
||||
template<class RET, CALL_TEMPLATE_ARGS>
|
||||
RET call(CALL_FORMAL_ARGS) const {
|
||||
if (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS))
|
||||
detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
|
||||
else
|
||||
detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS);
|
||||
}
|
||||
};
|
||||
|
||||
// Specialization of lambda_functor_base for if_then_else_return.
|
||||
template<class Args>
|
||||
class
|
||||
lambda_functor_base<other_action<ifthenelsereturn_action>, Args> {
|
||||
public:
|
||||
Args args;
|
||||
|
||||
template <class SigArgs> struct sig {
|
||||
private:
|
||||
typedef typename detail::nth_return_type_sig<1, Args, SigArgs>::type ret1;
|
||||
typedef typename detail::nth_return_type_sig<2, Args, SigArgs>::type ret2;
|
||||
public:
|
||||
typedef typename return_type_2<
|
||||
other_action<ifthenelsereturn_action>, ret1, ret2
|
||||
>::type type;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit lambda_functor_base(const Args& a) : args(a) {}
|
||||
|
||||
template<class RET, CALL_TEMPLATE_ARGS>
|
||||
RET call(CALL_FORMAL_ARGS) const {
|
||||
return (detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)) ?
|
||||
detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS)
|
||||
:
|
||||
detail::select(boost::tuples::get<2>(args), CALL_ACTUAL_ARGS);
|
||||
}
|
||||
};
|
||||
|
||||
} // lambda
|
||||
} // boost
|
||||
|
||||
#endif // BOOST_LAMBDA_CONTROL_CONSTRUCTS_HPP
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library - function_adaptors.hpp ----------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -12,25 +12,170 @@
|
||||
#ifndef BOOST_LAMBDA_FUNCTION_ADAPTORS_HPP
|
||||
#define BOOST_LAMBDA_FUNCTION_ADAPTORS_HPP
|
||||
|
||||
#include "boost/mpl/has_xxx.hpp"
|
||||
#include "boost/tuple/tuple.hpp"
|
||||
#include "boost/type_traits/same_traits.hpp"
|
||||
#include "boost/type_traits/remove_reference.hpp"
|
||||
#include "boost/type_traits/remove_cv.hpp"
|
||||
#include "boost/type_traits/add_const.hpp"
|
||||
#include "boost/type_traits/add_volatile.hpp"
|
||||
#include "boost/utility/result_of.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace lambda {
|
||||
|
||||
namespace detail {
|
||||
|
||||
BOOST_MPL_HAS_XXX_TEMPLATE_DEF(sig)
|
||||
|
||||
template<class Tuple>
|
||||
struct remove_references_from_elements {
|
||||
typedef typename boost::tuples::cons<
|
||||
typename boost::remove_reference<typename Tuple::head_type>::type,
|
||||
typename remove_references_from_elements<typename Tuple::tail_type>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct remove_references_from_elements<boost::tuples::null_type> {
|
||||
typedef boost::tuples::null_type type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <class Func> struct function_adaptor {
|
||||
|
||||
typedef typename detail::remove_reference_and_cv<Func>::type plainF;
|
||||
|
||||
#if !defined(BOOST_NO_RESULT_OF)
|
||||
// Support functors that use the boost::result_of return type convention.
|
||||
template<class Tuple, int Length, bool HasSig>
|
||||
struct result_converter;
|
||||
template<class Tuple, int Length>
|
||||
struct result_converter<Tuple, Length, true>
|
||||
: plainF::template sig<
|
||||
typename detail::remove_references_from_elements<Tuple>::type
|
||||
>
|
||||
{};
|
||||
template<class Tuple>
|
||||
struct result_converter<Tuple, 0, false>
|
||||
: result_of<plainF()>
|
||||
{};
|
||||
template<class Tuple>
|
||||
struct result_converter<Tuple, 1, false>
|
||||
: result_of<plainF(
|
||||
typename tuples::element<1, Tuple>::type)
|
||||
>
|
||||
{};
|
||||
template<class Tuple>
|
||||
struct result_converter<Tuple, 2, false>
|
||||
: result_of<plainF(
|
||||
typename tuples::element<1, Tuple>::type,
|
||||
typename tuples::element<2, Tuple>::type)
|
||||
>
|
||||
{};
|
||||
template<class Tuple>
|
||||
struct result_converter<Tuple, 3, false>
|
||||
: result_of<plainF(
|
||||
typename tuples::element<1, Tuple>::type,
|
||||
typename tuples::element<2, Tuple>::type,
|
||||
typename tuples::element<3, Tuple>::type)
|
||||
>
|
||||
{};
|
||||
template<class Tuple>
|
||||
struct result_converter<Tuple, 4, false>
|
||||
: result_of<plainF(
|
||||
typename tuples::element<1, Tuple>::type,
|
||||
typename tuples::element<2, Tuple>::type,
|
||||
typename tuples::element<3, Tuple>::type,
|
||||
typename tuples::element<4, Tuple>::type)
|
||||
>
|
||||
{};
|
||||
template<class Tuple>
|
||||
struct result_converter<Tuple, 5, false>
|
||||
: result_of<plainF(
|
||||
typename tuples::element<1, Tuple>::type,
|
||||
typename tuples::element<2, Tuple>::type,
|
||||
typename tuples::element<3, Tuple>::type,
|
||||
typename tuples::element<4, Tuple>::type,
|
||||
typename tuples::element<5, Tuple>::type)
|
||||
>
|
||||
{};
|
||||
template<class Tuple>
|
||||
struct result_converter<Tuple, 6, false>
|
||||
: result_of<plainF(
|
||||
typename tuples::element<1, Tuple>::type,
|
||||
typename tuples::element<2, Tuple>::type,
|
||||
typename tuples::element<3, Tuple>::type,
|
||||
typename tuples::element<4, Tuple>::type,
|
||||
typename tuples::element<5, Tuple>::type,
|
||||
typename tuples::element<6, Tuple>::type)
|
||||
>
|
||||
{};
|
||||
template<class Tuple>
|
||||
struct result_converter<Tuple, 7, false>
|
||||
: result_of<plainF(
|
||||
typename tuples::element<1, Tuple>::type,
|
||||
typename tuples::element<2, Tuple>::type,
|
||||
typename tuples::element<3, Tuple>::type,
|
||||
typename tuples::element<4, Tuple>::type,
|
||||
typename tuples::element<5, Tuple>::type,
|
||||
typename tuples::element<6, Tuple>::type,
|
||||
typename tuples::element<7, Tuple>::type)
|
||||
>
|
||||
{};
|
||||
template<class Tuple>
|
||||
struct result_converter<Tuple, 8, false>
|
||||
: result_of<plainF(
|
||||
typename tuples::element<1, Tuple>::type,
|
||||
typename tuples::element<2, Tuple>::type,
|
||||
typename tuples::element<3, Tuple>::type,
|
||||
typename tuples::element<4, Tuple>::type,
|
||||
typename tuples::element<5, Tuple>::type,
|
||||
typename tuples::element<6, Tuple>::type,
|
||||
typename tuples::element<7, Tuple>::type,
|
||||
typename tuples::element<8, Tuple>::type)
|
||||
>
|
||||
{};
|
||||
template<class Tuple>
|
||||
struct result_converter<Tuple, 9, false>
|
||||
: result_of<plainF(
|
||||
typename tuples::element<1, Tuple>::type,
|
||||
typename tuples::element<2, Tuple>::type,
|
||||
typename tuples::element<3, Tuple>::type,
|
||||
typename tuples::element<4, Tuple>::type,
|
||||
typename tuples::element<5, Tuple>::type,
|
||||
typename tuples::element<6, Tuple>::type,
|
||||
typename tuples::element<7, Tuple>::type,
|
||||
typename tuples::element<8, Tuple>::type,
|
||||
typename tuples::element<9, Tuple>::type)
|
||||
>
|
||||
{};
|
||||
|
||||
// we do not know the return type off-hand, we must ask it from Func
|
||||
template <class Args> class sig {
|
||||
typedef typename Args::head_type F;
|
||||
// To sig we pass a cons list, where the head is the function object type
|
||||
// itself (potentially cv-qualified)
|
||||
// and the tail contains the types of the actual arguments to be passed
|
||||
// to the function object. The arguments can be cv qualified
|
||||
// as well.
|
||||
template <class Args>
|
||||
struct sig
|
||||
: result_converter<
|
||||
Args
|
||||
, tuples::length<typename Args::tail_type>::value
|
||||
, detail::has_sig<plainF>::value
|
||||
>
|
||||
{};
|
||||
#else // BOOST_NO_RESULT_OF
|
||||
|
||||
template <class Args> class sig {
|
||||
typedef typename detail::remove_reference_and_cv<Func>::type plainF;
|
||||
public:
|
||||
// To sig we pass a cons list, where the head is the function object type
|
||||
// itself (potentially cv-qualified)
|
||||
// and the tail contains the types of the actual arguments to be passed
|
||||
// to the function object. The arguments can be cv qualified
|
||||
// as well.
|
||||
typedef typename plainF::template sig<Args>::type type;
|
||||
typedef typename plainF::template sig<
|
||||
typename detail::remove_references_from_elements<Args>::type
|
||||
>::type type;
|
||||
};
|
||||
#endif
|
||||
|
||||
template<class RET, class A1>
|
||||
static RET apply(A1& a1) {
|
||||
@@ -95,22 +240,26 @@ struct function_adaptor<T Object::*> {
|
||||
// the data member is accessed is const, and finally adding a reference
|
||||
template<class Args> class sig {
|
||||
typedef typename boost::tuples::element<1, Args>::type argument_type;
|
||||
typedef typename boost::remove_reference<
|
||||
argument_type
|
||||
>::type unref_type;
|
||||
|
||||
typedef typename detail::IF<boost::is_const<argument_type>::value,
|
||||
typedef typename detail::IF<boost::is_const<unref_type>::value,
|
||||
typename boost::add_const<T>::type,
|
||||
T
|
||||
>::RET properly_consted_return_type;
|
||||
|
||||
typedef typename detail::IF<
|
||||
boost::is_volatile<properly_consted_return_type>::value,
|
||||
typedef typename detail::IF<boost::is_volatile<unref_type>::value,
|
||||
typename boost::add_volatile<properly_consted_return_type>::type,
|
||||
properly_consted_return_type
|
||||
>::RET properly_cvd_return_type;
|
||||
|
||||
|
||||
public:
|
||||
typedef typename
|
||||
boost::add_reference<properly_cvd_return_type>::type type;
|
||||
typedef typename detail::IF<boost::is_reference<argument_type>::value,
|
||||
typename boost::add_reference<properly_cvd_return_type>::type,
|
||||
typename boost::remove_cv<T>::type
|
||||
>::RET type;
|
||||
};
|
||||
|
||||
template <class RET>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library - is_instance_of.hpp ---------------------
|
||||
|
||||
// Copyright (C) 2001 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2001 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library - lambda_config.hpp ------------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library lambda_functor_base.hpp -----------------------------
|
||||
//
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -13,9 +13,19 @@
|
||||
#ifndef BOOST_LAMBDA_LAMBDA_FUNCTOR_BASE_HPP
|
||||
#define BOOST_LAMBDA_LAMBDA_FUNCTOR_BASE_HPP
|
||||
|
||||
#include "boost/type_traits/add_reference.hpp"
|
||||
#include "boost/type_traits/add_const.hpp"
|
||||
#include "boost/type_traits/remove_const.hpp"
|
||||
#include "boost/lambda/detail/lambda_fwd.hpp"
|
||||
#include "boost/lambda/detail/lambda_traits.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace lambda {
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4512) //assignment operator could not be generated
|
||||
#endif
|
||||
|
||||
// for return type deductions we wrap bound argument to this class,
|
||||
// which fulfils the base class contract for lambda_functors
|
||||
@@ -27,7 +37,7 @@ public:
|
||||
|
||||
typedef T element_t;
|
||||
|
||||
// take all parameters as const rererences. Note that non-const references
|
||||
// take all parameters as const references. Note that non-const references
|
||||
// stay as they are.
|
||||
typedef typename boost::add_reference<
|
||||
typename boost::add_const<T>::type
|
||||
@@ -36,12 +46,16 @@ public:
|
||||
explicit identity(par_t t) : elem(t) {}
|
||||
|
||||
template <typename SigArgs>
|
||||
struct sig { typedef element_t type; };
|
||||
struct sig { typedef typename boost::remove_const<element_t>::type type; };
|
||||
|
||||
template<class RET, CALL_TEMPLATE_ARGS>
|
||||
RET call(CALL_FORMAL_ARGS) const { CALL_USE_ARGS; return elem; }
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
inline lambda_functor<identity<T&> > var(T& t) { return identity<T&>(t); }
|
||||
|
||||
@@ -262,6 +276,8 @@ class lambda_functor_base<explicit_return_type_action<RET>, Args>
|
||||
public:
|
||||
Args args;
|
||||
|
||||
typedef RET result_type;
|
||||
|
||||
explicit lambda_functor_base(const Args& a) : args(a) {}
|
||||
|
||||
template <class SigArgs> struct sig { typedef RET type; };
|
||||
@@ -317,7 +333,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// These specializatoins provide a shorter notation to define actions.
|
||||
// These specializations provide a shorter notation to define actions.
|
||||
// These lambda_functor_base instances take care of the recursive evaluation
|
||||
// of the arguments and pass the evaluated arguments to the apply function
|
||||
// of an action class. To make action X work with these classes, one must
|
||||
@@ -337,7 +353,7 @@ class lambda_functor_base<action<0, Act>, Args>
|
||||
{
|
||||
public:
|
||||
// Args args; not needed
|
||||
explicit lambda_functor_base(const Args& a) {}
|
||||
explicit lambda_functor_base(const Args& /*a*/) {}
|
||||
|
||||
template<class SigArgs> struct sig {
|
||||
typedef typename return_type_N<Act, null_type>::type type;
|
||||
@@ -367,7 +383,7 @@ public: \
|
||||
\
|
||||
template<class SigArgs> struct sig { \
|
||||
typedef typename \
|
||||
detail::deduce_non_ref_argument_types<Args, SigArgs>::type rets_t; \
|
||||
detail::deduce_argument_types<Args, SigArgs>::type rets_t; \
|
||||
public: \
|
||||
typedef typename \
|
||||
return_type_N_prot<Act, rets_t>::type type; \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library - lambda_functors.hpp -------------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -13,6 +13,30 @@
|
||||
#ifndef BOOST_LAMBDA_LAMBDA_FUNCTORS_HPP
|
||||
#define BOOST_LAMBDA_LAMBDA_FUNCTORS_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
|
||||
|
||||
#include <boost/mpl/or.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_array.hpp>
|
||||
|
||||
#define BOOST_LAMBDA_DISABLE_IF_ARRAY1(A1, R1)\
|
||||
typename lazy_disable_if<is_array<A1>, typename R1 >::type
|
||||
#define BOOST_LAMBDA_DISABLE_IF_ARRAY2(A1, A2, R1, R2) \
|
||||
typename lazy_disable_if<mpl::or_<is_array<A1>, is_array<A2> >, typename R1, R2 >::type
|
||||
#define BOOST_LAMBDA_DISABLE_IF_ARRAY3(A1, A2, A3, R1, R2, R3) \
|
||||
typename lazy_disable_if<mpl::or_<is_array<A1>, is_array<A2>, is_array<A3> >, typename R1, R2, R3 >::type
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_LAMBDA_DISABLE_IF_ARRAY1(A1, R1) typename R1::type
|
||||
#define BOOST_LAMBDA_DISABLE_IF_ARRAY2(A1, A2, R1, R2) typename R1, R2::type
|
||||
#define BOOST_LAMBDA_DISABLE_IF_ARRAY3(A1, A2, A3, R1, R2, R3) typename R1, R2, R3::type
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace lambda {
|
||||
|
||||
@@ -105,7 +129,10 @@ typedef const lambda_functor<placeholder<THIRD> > placeholder3_type;
|
||||
// other lambda_functors.
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4512) //assignment operator could not be generated
|
||||
#endif
|
||||
|
||||
// -- lambda_functor NONE ------------------------------------------------
|
||||
template <class T>
|
||||
@@ -134,6 +161,25 @@ public:
|
||||
inherited::template sig<null_type>::type
|
||||
nullary_return_type;
|
||||
|
||||
// Support for boost::result_of.
|
||||
template <class Sig> struct result;
|
||||
template <class F>
|
||||
struct result<F()> {
|
||||
typedef nullary_return_type type;
|
||||
};
|
||||
template <class F, class A>
|
||||
struct result<F(A)> {
|
||||
typedef typename sig<tuple<F, A> >::type type;
|
||||
};
|
||||
template <class F, class A, class B>
|
||||
struct result<F(A, B)> {
|
||||
typedef typename sig<tuple<F, A, B> >::type type;
|
||||
};
|
||||
template <class F, class A, class B, class C>
|
||||
struct result<F(A, B, C)> {
|
||||
typedef typename sig<tuple<F, A, B, C> >::type type;
|
||||
};
|
||||
|
||||
nullary_return_type operator()() const {
|
||||
return inherited::template
|
||||
call<nullary_return_type>
|
||||
@@ -148,6 +194,14 @@ public:
|
||||
>(a, cnull_type(), cnull_type(), cnull_type());
|
||||
}
|
||||
|
||||
template<class A>
|
||||
BOOST_LAMBDA_DISABLE_IF_ARRAY1(A, inherited::template sig<tuple<A const&> >)
|
||||
operator()(A const& a) const {
|
||||
return inherited::template call<
|
||||
typename inherited::template sig<tuple<A const&> >::type
|
||||
>(a, cnull_type(), cnull_type(), cnull_type());
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
typename inherited::template sig<tuple<A&, B&> >::type
|
||||
operator()(A& a, B& b) const {
|
||||
@@ -156,6 +210,30 @@ public:
|
||||
>(a, b, cnull_type(), cnull_type());
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
BOOST_LAMBDA_DISABLE_IF_ARRAY2(A, B, inherited::template sig<tuple<A const&, B&> >)
|
||||
operator()(A const& a, B& b) const {
|
||||
return inherited::template call<
|
||||
typename inherited::template sig<tuple<A const&, B&> >::type
|
||||
>(a, b, cnull_type(), cnull_type());
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
BOOST_LAMBDA_DISABLE_IF_ARRAY2(A, B, inherited::template sig<tuple<A&, B const&> >)
|
||||
operator()(A& a, B const& b) const {
|
||||
return inherited::template call<
|
||||
typename inherited::template sig<tuple<A&, B const&> >::type
|
||||
>(a, b, cnull_type(), cnull_type());
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
BOOST_LAMBDA_DISABLE_IF_ARRAY2(A, B, inherited::template sig<tuple<A const&, B const&> >)
|
||||
operator()(A const& a, B const& b) const {
|
||||
return inherited::template call<
|
||||
typename inherited::template sig<tuple<A const&, B const&> >::type
|
||||
>(a, b, cnull_type(), cnull_type());
|
||||
}
|
||||
|
||||
template<class A, class B, class C>
|
||||
typename inherited::template sig<tuple<A&, B&, C&> >::type
|
||||
operator()(A& a, B& b, C& c) const
|
||||
@@ -165,6 +243,15 @@ public:
|
||||
>(a, b, c, cnull_type());
|
||||
}
|
||||
|
||||
template<class A, class B, class C>
|
||||
BOOST_LAMBDA_DISABLE_IF_ARRAY3(A, B, C, inherited::template sig<tuple<A const&, B const&, C const&> >)
|
||||
operator()(A const& a, B const& b, C const& c) const
|
||||
{
|
||||
return inherited::template call<
|
||||
typename inherited::template sig<tuple<A const&, B const&, C const&> >::type
|
||||
>(a, b, c, cnull_type());
|
||||
}
|
||||
|
||||
// for internal calls with env
|
||||
template<CALL_TEMPLATE_ARGS>
|
||||
typename inherited::template sig<tuple<CALL_REFERENCE_TYPES> >::type
|
||||
@@ -203,10 +290,35 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace lambda
|
||||
} // namespace boost
|
||||
|
||||
// is_placeholder
|
||||
|
||||
#include <boost/is_placeholder.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template<> struct is_placeholder< lambda::lambda_functor< lambda::placeholder<lambda::FIRST> > >
|
||||
{
|
||||
enum _vt { value = 1 };
|
||||
};
|
||||
|
||||
template<> struct is_placeholder< lambda::lambda_functor< lambda::placeholder<lambda::SECOND> > >
|
||||
{
|
||||
enum _vt { value = 2 };
|
||||
};
|
||||
|
||||
template<> struct is_placeholder< lambda::lambda_functor< lambda::placeholder<lambda::THIRD> > >
|
||||
{
|
||||
enum _vt { value = 3 };
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// lambda_fwd.hpp - Boost Lambda Library -------------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -65,7 +65,7 @@ void do_nothing(A1&, A2&, A3&, A4&) {}
|
||||
} // lambda
|
||||
} // boost
|
||||
|
||||
// prevent the warnings from unused argumetns
|
||||
// prevent the warnings from unused arguments
|
||||
#define CALL_USE_ARGS \
|
||||
::boost::lambda::detail::do_nothing(a, b, c, env)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// - lambda_traits.hpp --- Boost Lambda Library ----------------------------
|
||||
//
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "boost/type_traits/cv_traits.hpp"
|
||||
#include "boost/type_traits/function_traits.hpp"
|
||||
#include "boost/type_traits/object_traits.hpp"
|
||||
#include "boost/tuple/tuple.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace lambda {
|
||||
@@ -430,6 +431,56 @@ struct bind_traits<const volatile T[n]> {
|
||||
typedef const volatile T (&type)[n];
|
||||
};
|
||||
|
||||
template<class R>
|
||||
struct bind_traits<R()> {
|
||||
typedef R(&type)();
|
||||
};
|
||||
|
||||
template<class R, class Arg1>
|
||||
struct bind_traits<R(Arg1)> {
|
||||
typedef R(&type)(Arg1);
|
||||
};
|
||||
|
||||
template<class R, class Arg1, class Arg2>
|
||||
struct bind_traits<R(Arg1, Arg2)> {
|
||||
typedef R(&type)(Arg1, Arg2);
|
||||
};
|
||||
|
||||
template<class R, class Arg1, class Arg2, class Arg3>
|
||||
struct bind_traits<R(Arg1, Arg2, Arg3)> {
|
||||
typedef R(&type)(Arg1, Arg2, Arg3);
|
||||
};
|
||||
|
||||
template<class R, class Arg1, class Arg2, class Arg3, class Arg4>
|
||||
struct bind_traits<R(Arg1, Arg2, Arg3, Arg4)> {
|
||||
typedef R(&type)(Arg1, Arg2, Arg3, Arg4);
|
||||
};
|
||||
|
||||
template<class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
|
||||
struct bind_traits<R(Arg1, Arg2, Arg3, Arg4, Arg5)> {
|
||||
typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5);
|
||||
};
|
||||
|
||||
template<class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
|
||||
struct bind_traits<R(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)> {
|
||||
typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
|
||||
};
|
||||
|
||||
template<class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
|
||||
struct bind_traits<R(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)> {
|
||||
typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7);
|
||||
};
|
||||
|
||||
template<class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8>
|
||||
struct bind_traits<R(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)> {
|
||||
typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8);
|
||||
};
|
||||
|
||||
template<class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8, class Arg9>
|
||||
struct bind_traits<R(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)> {
|
||||
typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9);
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct bind_traits<reference_wrapper<T> >{
|
||||
typedef T& type;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library -- member_ptr.hpp ---------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000 Gary Powell (gary.powell@sierra.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// -- operator_actions.hpp - Boost Lambda Library ----------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library - operator_lambda_func_base.hpp -----------------
|
||||
//
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// operator_return_type_traits.hpp -- Boost Lambda Library ------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "boost/type_traits/same_traits.hpp"
|
||||
|
||||
#include "boost/indirect_reference.hpp"
|
||||
#include "boost/detail/container_fwd.hpp"
|
||||
|
||||
#include <cstddef> // needed for the ptrdiff_t
|
||||
#include <iosfwd> // for istream and ostream
|
||||
@@ -58,10 +59,6 @@ template <> struct promote_code<long double> { static const int value = 700; };
|
||||
} // namespace lambda
|
||||
} // namespace boost
|
||||
|
||||
namespace std {
|
||||
template<class T> class complex;
|
||||
}
|
||||
|
||||
namespace boost {
|
||||
namespace lambda {
|
||||
namespace detail {
|
||||
@@ -228,34 +225,15 @@ template <> struct contentsof_type<null_type> {
|
||||
|
||||
|
||||
template <class A> struct contentsof_type<const A> {
|
||||
typedef typename contentsof_type<A>::type type1;
|
||||
// return a reference to the underlying const type
|
||||
// the IF is because the A::reference in the primary template could
|
||||
// be some class type rather than a real reference, hence
|
||||
// we do not want to make it a reference here either
|
||||
typedef typename detail::IF<
|
||||
is_reference<type1>::value,
|
||||
const typename boost::remove_reference<type1>::type &,
|
||||
const type1
|
||||
>::RET type;
|
||||
typedef typename contentsof_type<A>::type type;
|
||||
};
|
||||
|
||||
template <class A> struct contentsof_type<volatile A> {
|
||||
typedef typename contentsof_type<A>::type type1;
|
||||
typedef typename detail::IF<
|
||||
is_reference<type1>::value,
|
||||
volatile typename boost::remove_reference<type1>::type &,
|
||||
volatile type1
|
||||
>::RET type;
|
||||
typedef typename contentsof_type<A>::type type;
|
||||
};
|
||||
|
||||
template <class A> struct contentsof_type<const volatile A> {
|
||||
typedef typename contentsof_type<A>::type type1;
|
||||
typedef typename detail::IF<
|
||||
is_reference<type1>::value,
|
||||
const volatile typename boost::remove_reference<type1>::type &,
|
||||
const volatile type1
|
||||
>::RET type;
|
||||
typedef typename contentsof_type<A>::type type;
|
||||
};
|
||||
|
||||
// standard iterator traits should take care of the pointer types
|
||||
@@ -853,44 +831,6 @@ struct return_type_2<other_action<subscript_action>, A, B> {
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace lambda
|
||||
} // namespace boost
|
||||
|
||||
|
||||
namespace std {
|
||||
template <class Char, class Traits, class Allocator> class basic_string;
|
||||
}
|
||||
|
||||
// The GCC 2.95.x uses a non-conformant deque
|
||||
#if BOOST_WORKAROUND(__GNUC__, == 2) && __GNUC_MINOR__ <= 96
|
||||
#include <deque>
|
||||
#else
|
||||
|
||||
namespace std {
|
||||
template <class T, class Allocator> class deque;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND(__GNUC__, == 3) && __GNUC_MINOR__ >=4
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#else
|
||||
|
||||
namespace std {
|
||||
template <class T, class Allocator> class vector;
|
||||
template <class Key, class T, class Cmp, class Allocator> class map;
|
||||
template <class Key, class T, class Cmp, class Allocator> class multimap;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace lambda {
|
||||
|
||||
template<class Key, class T, class Cmp, class Allocator, class B>
|
||||
struct plain_return_type_2<other_action<subscript_action>, std::map<Key, T, Cmp, Allocator>, B> {
|
||||
typedef T& type;
|
||||
@@ -933,6 +873,41 @@ struct plain_return_type_2<other_action<subscript_action>, const std::basic_stri
|
||||
typedef typename std::basic_string<Char, Traits, Allocator>::const_reference type;
|
||||
};
|
||||
|
||||
template<class Char, class Traits, class Allocator>
|
||||
struct plain_return_type_2<arithmetic_action<plus_action>,
|
||||
std::basic_string<Char, Traits, Allocator>,
|
||||
std::basic_string<Char, Traits, Allocator> > {
|
||||
typedef std::basic_string<Char, Traits, Allocator> type;
|
||||
};
|
||||
|
||||
template<class Char, class Traits, class Allocator>
|
||||
struct plain_return_type_2<arithmetic_action<plus_action>,
|
||||
const Char*,
|
||||
std::basic_string<Char, Traits, Allocator> > {
|
||||
typedef std::basic_string<Char, Traits, Allocator> type;
|
||||
};
|
||||
|
||||
template<class Char, class Traits, class Allocator>
|
||||
struct plain_return_type_2<arithmetic_action<plus_action>,
|
||||
std::basic_string<Char, Traits, Allocator>,
|
||||
const Char*> {
|
||||
typedef std::basic_string<Char, Traits, Allocator> type;
|
||||
};
|
||||
|
||||
template<class Char, class Traits, class Allocator, std::size_t N>
|
||||
struct plain_return_type_2<arithmetic_action<plus_action>,
|
||||
Char[N],
|
||||
std::basic_string<Char, Traits, Allocator> > {
|
||||
typedef std::basic_string<Char, Traits, Allocator> type;
|
||||
};
|
||||
|
||||
template<class Char, class Traits, class Allocator, std::size_t N>
|
||||
struct plain_return_type_2<arithmetic_action<plus_action>,
|
||||
std::basic_string<Char, Traits, Allocator>,
|
||||
Char[N]> {
|
||||
typedef std::basic_string<Char, Traits, Allocator> type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace lambda
|
||||
} // namespace boost
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library - operators.hpp --------------------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -37,16 +37,16 @@ inline const \
|
||||
lambda_functor< \
|
||||
lambda_functor_base< \
|
||||
ACTION, \
|
||||
tuple<lambda_functor<Arg>, typename CONVERSION <CONSTB>::type> \
|
||||
tuple<lambda_functor<Arg>, typename const_copy_argument <CONSTB>::type> \
|
||||
> \
|
||||
> \
|
||||
OPER_NAME (const lambda_functor<Arg>& a, CONSTB& b) { \
|
||||
return \
|
||||
lambda_functor_base< \
|
||||
ACTION, \
|
||||
tuple<lambda_functor<Arg>, typename CONVERSION <CONSTB>::type> \
|
||||
tuple<lambda_functor<Arg>, typename const_copy_argument <CONSTB>::type>\
|
||||
> \
|
||||
(tuple<lambda_functor<Arg>, typename CONVERSION <CONSTB>::type>(a, b)); \
|
||||
(tuple<lambda_functor<Arg>, typename const_copy_argument <CONSTB>::type>(a, b)); \
|
||||
}
|
||||
|
||||
|
||||
@@ -258,17 +258,17 @@ operator>>(const lambda_functor<Arg>& a, Ret(&b)(ManipArg))
|
||||
#error "Multiple defines of BOOST_LAMBDA_PTR_ARITHMETIC_E1"
|
||||
#endif
|
||||
|
||||
#define BOOST_LAMBDA_PTR_ARITHMETIC_E1(OPER_NAME, ACTION, CONSTB) \
|
||||
#define BOOST_LAMBDA_PTR_ARITHMETIC_E1(OPER_NAME, ACTION, CONSTB) \
|
||||
template<class Arg, int N, class B> \
|
||||
inline const \
|
||||
lambda_functor< \
|
||||
lambda_functor_base<ACTION, tuple<lambda_functor<Arg>, CONSTB(&)[N]> > \
|
||||
lambda_functor_base<ACTION, tuple<lambda_functor<Arg>, CONSTB(&)[N]> > \
|
||||
> \
|
||||
OPER_NAME (const lambda_functor<Arg>& a, CONSTB(&b)[N]) \
|
||||
OPER_NAME (const lambda_functor<Arg>& a, CONSTB(&b)[N]) \
|
||||
{ \
|
||||
return lambda_functor< \
|
||||
lambda_functor_base<ACTION, tuple<lambda_functor<Arg>, CONSTB(&)[N]> > \
|
||||
>(tuple<lambda_functor<Arg>, CONSTB(&)[N]>(a, b)); \
|
||||
return \
|
||||
lambda_functor_base<ACTION, tuple<lambda_functor<Arg>, CONSTB(&)[N]> > \
|
||||
(tuple<lambda_functor<Arg>, CONSTB(&)[N]>(a, b)); \
|
||||
}
|
||||
|
||||
|
||||
@@ -276,15 +276,15 @@ OPER_NAME (const lambda_functor<Arg>& a, CONSTB(&b)[N]) \
|
||||
#error "Multiple defines of BOOST_LAMBDA_PTR_ARITHMETIC_E2"
|
||||
#endif
|
||||
|
||||
#define BOOST_LAMBDA_PTR_ARITHMETIC_E2(OPER_NAME, ACTION, CONSTA) \
|
||||
template<int N, class A, class Arg> \
|
||||
inline const \
|
||||
lambda_functor< \
|
||||
#define BOOST_LAMBDA_PTR_ARITHMETIC_E2(OPER_NAME, ACTION, CONSTA) \
|
||||
template<int N, class A, class Arg> \
|
||||
inline const \
|
||||
lambda_functor< \
|
||||
lambda_functor_base<ACTION, tuple<CONSTA(&)[N], lambda_functor<Arg> > > \
|
||||
> \
|
||||
> \
|
||||
OPER_NAME (CONSTA(&a)[N], const lambda_functor<Arg>& b) \
|
||||
{ \
|
||||
return \
|
||||
{ \
|
||||
return \
|
||||
lambda_functor_base<ACTION, tuple<CONSTA(&)[N], lambda_functor<Arg> > > \
|
||||
(tuple<CONSTA(&)[N], lambda_functor<Arg> >(a, b)); \
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library ret.hpp -----------------------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// return_type_traits.hpp -- Boost Lambda Library ---------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -216,8 +216,6 @@ typedef typename
|
||||
|
||||
|
||||
// currently there are no protectable actions with > 2 args
|
||||
// Note, that if there will be, lambda_functor_base will have to be
|
||||
// changed to not get rid of references in Args elements
|
||||
|
||||
template<class Act, class Args> struct return_type_N_prot {
|
||||
typedef typename return_type_N<Act, Args>::type type;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// -- select_functions.hpp -- Boost Lambda Library --------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
27
include/boost/lambda/detail/suppress_unused.hpp
Normal file
27
include/boost/lambda/detail/suppress_unused.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
// Boost Lambda Library suppress_unused.hpp -----------------------------
|
||||
//
|
||||
// Copyright (C) 2009 Steven Watanabe
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// For more information, see www.boost.org
|
||||
|
||||
// ------------------------------------------------------------
|
||||
|
||||
#ifndef BOOST_LAMBDA_SUPRESS_UNUSED_HPP
|
||||
#define BOOST_LAMBDA_SUPRESS_UNUSED_HPP
|
||||
|
||||
namespace boost {
|
||||
namespace lambda {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
inline void suppress_unused_variable_warnings(const T&) {}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
// -- Boost Lambda Library -- exceptions.hpp ----------------
|
||||
//
|
||||
// Copyright (C) 2000 Gary Powell (gwpowell@hotmail.com)
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -14,6 +14,7 @@
|
||||
#if !defined(BOOST_LAMBDA_EXCEPTIONS_HPP)
|
||||
#define BOOST_LAMBDA_EXCEPTIONS_HPP
|
||||
|
||||
#include "boost/lambda/core.hpp"
|
||||
#include "boost/lambda/detail/control_constructs_common.hpp"
|
||||
|
||||
namespace boost {
|
||||
@@ -48,7 +49,7 @@ struct try_catch_action {};
|
||||
struct throw_new_action {};
|
||||
struct rethrow_action {};
|
||||
|
||||
template<class ThrowType> class throw_action;
|
||||
template<class ThrowType> struct throw_action;
|
||||
|
||||
template<>
|
||||
struct throw_action<rethrow_action> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library -- if.hpp ------------------------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000 Gary Powell (powellg@amazon.com)
|
||||
// Copyright (C) 2001-2002 Joel de Guzman
|
||||
//
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// -- lambda.hpp -- Boost Lambda Library -----------------------------------
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Boost Lambda Library -- loops.hpp ----------------------------------------
|
||||
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000 Gary Powell (powellg@amazon.com)
|
||||
// Copyright (c) 2001-2002 Joel de Guzman
|
||||
//
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// -- numeric.hpp -- Boost Lambda Library -----------------------------------
|
||||
// Copyright (C) 2002 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2002 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2002 Gary Powell (gwpowell@hotmail.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Boost Lambda Library -- switch.hpp -----------------------------------
|
||||
//
|
||||
// Copyright (C) 2000 Gary Powell (powellg@amazon.com)
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -465,12 +465,18 @@ BOOST_LAMBDA_SWITCH( BOOST_PP_INC(N) )
|
||||
#define BOOST_LAMBDA_SWITCH_STATEMENT_HELPER(z, N, A) \
|
||||
BOOST_LAMBDA_SWITCH_STATEMENT(BOOST_PP_INC(N))
|
||||
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4065)
|
||||
#endif
|
||||
|
||||
// up to 9 cases supported (counting default:)
|
||||
BOOST_PP_REPEAT_2ND(9,BOOST_LAMBDA_SWITCH_HELPER,FOO)
|
||||
BOOST_PP_REPEAT_2ND(9,BOOST_LAMBDA_SWITCH_STATEMENT_HELPER,FOO)
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace lambda
|
||||
} // namespace boost
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
<meta http-equiv="refresh" content="0; URL=../../doc/html/lambda.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to <a href="../../doc/html/lambda.html">www.boost.org/doc/html/lambda.html</a>
|
||||
Automatic redirection failed, please go to <a href="../../doc/html/lambda.html">www.boost.org/doc/html/lambda.html</a> <hr>
|
||||
<p>© Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
</body>
|
||||
</html>
|
||||
72
test/Jamfile
72
test/Jamfile
@@ -8,52 +8,28 @@
|
||||
|
||||
# For more information, see http://www.boost.org/
|
||||
|
||||
import testing ;
|
||||
|
||||
subproject libs/lambda/test ;
|
||||
|
||||
# bring in rules for testing
|
||||
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
|
||||
include testing.jam ;
|
||||
|
||||
# Make tests run by default.
|
||||
DEPENDS all : test ;
|
||||
|
||||
{
|
||||
# look in BOOST_ROOT for sources first, just in this Jamfile
|
||||
local SEARCH_SOURCE = $(BOOST_ROOT) $(SEARCH_SOURCE) ;
|
||||
|
||||
test-suite lambda
|
||||
:
|
||||
[ run libs/lambda/test/algorithm_test.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/bind_tests_simple.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/bind_tests_advanced.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/bind_tests_simple_f_refs.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/bll_and_function.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/cast_test.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/constructor_tests.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/control_structures.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/exception_test.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/extending_rt_traits.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/is_instance_of_test.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/member_pointer_test.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/operator_tests_simple.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/phoenix_control_structures.cpp : : : : ]
|
||||
|
||||
[ run libs/lambda/test/switch_construct.cpp : : : : ]
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
project
|
||||
: requirements <toolset>msvc:<asynch-exceptions>on
|
||||
;
|
||||
|
||||
test-suite lambda
|
||||
: [ run algorithm_test.cpp ]
|
||||
[ run bind_tests_simple.cpp ]
|
||||
[ run bind_tests_advanced.cpp ]
|
||||
[ run bind_tests_simple_f_refs.cpp ]
|
||||
[ run bll_and_function.cpp ]
|
||||
[ run cast_test.cpp : : : : lambda_cast_test ]
|
||||
[ run constructor_tests.cpp ]
|
||||
[ run control_structures.cpp ]
|
||||
[ run exception_test.cpp ]
|
||||
[ run extending_rt_traits.cpp ]
|
||||
[ run is_instance_of_test.cpp ]
|
||||
[ run member_pointer_test.cpp ]
|
||||
[ run operator_tests_simple.cpp ]
|
||||
[ run phoenix_control_structures.cpp ]
|
||||
[ run switch_construct.cpp ]
|
||||
[ run result_of_tests.cpp ]
|
||||
[ run ret_test.cpp ]
|
||||
;
|
||||
|
||||
4
test/Makefile
Executable file → Normal file
4
test/Makefile
Executable file → Normal file
@@ -1,7 +1,7 @@
|
||||
BOOST = ../../..
|
||||
|
||||
CXX = gcc
|
||||
EXTRAFLAGS = -pedantic -Wno-long-long -ftemplate-depth-50
|
||||
CXX = g++
|
||||
EXTRAFLAGS = -pedantic -Wno-long-long -Wno-long-double -ftemplate-depth-50
|
||||
LIBS = -lstdc++
|
||||
|
||||
#CXX = KCC
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// bll_and_function.cpp - The Boost Lambda Library -----------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -41,7 +41,7 @@ void test_foreach() {
|
||||
bind(ll::for_each(), _1, _1 + 20,
|
||||
protect((sum += _1))));
|
||||
|
||||
BOOST_TEST(sum == (199 + 1)/ 2 * 199);
|
||||
BOOST_CHECK(sum == (199 + 1)/ 2 * 199);
|
||||
}
|
||||
|
||||
// More tests needed (for all algorithms)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// bind_tests_advanced.cpp -- The Boost Lambda Library ------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
// Copyright (C) 2010 Steven Watanabe
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -19,6 +20,9 @@
|
||||
|
||||
|
||||
#include "boost/any.hpp"
|
||||
#include "boost/type_traits/is_reference.hpp"
|
||||
#include "boost/mpl/assert.hpp"
|
||||
#include "boost/mpl/if.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -27,7 +31,8 @@
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
using namespace boost::lambda;
|
||||
using namespace boost::lambda;
|
||||
namespace bl = boost::lambda;
|
||||
|
||||
int sum_0() { return 0; }
|
||||
int sum_1(int a) { return a; }
|
||||
@@ -60,16 +65,16 @@ void test_nested_binds()
|
||||
bool condition;
|
||||
|
||||
condition = true;
|
||||
BOOST_TEST(bind(bind(&sum_or_product, _1), 1, 2)(condition)==3);
|
||||
BOOST_TEST(bind(bind(&sum_or_product, _1), _2, _3)(condition, j, k)==5);
|
||||
BOOST_CHECK(bind(bind(&sum_or_product, _1), 1, 2)(condition)==3);
|
||||
BOOST_CHECK(bind(bind(&sum_or_product, _1), _2, _3)(condition, j, k)==5);
|
||||
|
||||
condition = false;
|
||||
BOOST_TEST(bind(bind(&sum_or_product, _1), 1, 2)(condition)==2);
|
||||
BOOST_TEST(bind(bind(&sum_or_product, _1), _2, _3)(condition, j, k)==6);
|
||||
BOOST_CHECK(bind(bind(&sum_or_product, _1), 1, 2)(condition)==2);
|
||||
BOOST_CHECK(bind(bind(&sum_or_product, _1), _2, _3)(condition, j, k)==6);
|
||||
|
||||
|
||||
which_one wo;
|
||||
BOOST_TEST(bind(bind(bind(wo), _1), _2, _3)(condition, j, k)==6);
|
||||
BOOST_CHECK(bind(bind(bind(wo), _1), _2, _3)(condition, j, k)==6);
|
||||
|
||||
|
||||
return;
|
||||
@@ -91,7 +96,7 @@ int call_with_100(const F& f) {
|
||||
// This would result in;
|
||||
// bind(_1 + 1, _1)(make_const(100)) , which would be a compile time error
|
||||
|
||||
return bind(unlambda(f), _1)(make_const(100));
|
||||
return bl::bind(unlambda(f), _1)(make_const(100));
|
||||
|
||||
// for other functors than lambda functors, unlambda has no effect
|
||||
// (except for making them const)
|
||||
@@ -109,18 +114,18 @@ void test_unlambda() {
|
||||
|
||||
int i = 1;
|
||||
|
||||
BOOST_TEST(unlambda(_1 + _2)(i, i) == 2);
|
||||
BOOST_TEST(unlambda(++var(i))() == 2);
|
||||
BOOST_TEST(call_with_100(_1 + 1) == 101);
|
||||
BOOST_CHECK(unlambda(_1 + _2)(i, i) == 2);
|
||||
BOOST_CHECK(unlambda(++var(i))() == 2);
|
||||
BOOST_CHECK(call_with_100(_1 + 1) == 101);
|
||||
|
||||
|
||||
BOOST_TEST(call_with_101(_1 + 1) == 102);
|
||||
BOOST_CHECK(call_with_101(_1 + 1) == 102);
|
||||
|
||||
BOOST_TEST(call_with_100(bind(std_functor(std::bind1st(std::plus<int>(), 1)), _1)) == 101);
|
||||
BOOST_CHECK(call_with_100(bl::bind(std_functor(std::bind1st(std::plus<int>(), 1)), _1)) == 101);
|
||||
|
||||
// std_functor insturcts LL that the functor defines a result_type typedef
|
||||
// rather than a sig template.
|
||||
bind(std_functor(std::plus<int>()), _1, _2)(i, i);
|
||||
bl::bind(std_functor(std::plus<int>()), _1, _2)(i, i);
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +205,7 @@ void test_protect()
|
||||
bind(ll::for_each(), _1, _1 + 5,
|
||||
protect(sum += _1))
|
||||
);
|
||||
BOOST_TEST(sum == (1+15)*15/2);
|
||||
BOOST_CHECK(sum == (1+15)*15/2);
|
||||
|
||||
sum = 0;
|
||||
|
||||
@@ -208,17 +213,17 @@ void test_protect()
|
||||
bind(ll::for_each(), _1, _1 + 5,
|
||||
sum += 1 + protect(_1)) // add element count
|
||||
);
|
||||
BOOST_TEST(sum == (1+15)*15/2 + 15);
|
||||
BOOST_CHECK(sum == (1+15)*15/2 + 15);
|
||||
|
||||
(1 + protect(_1))(sum);
|
||||
|
||||
int k = 0;
|
||||
((k += constant(1)) += protect(constant(2)))();
|
||||
BOOST_TEST(k==1);
|
||||
BOOST_CHECK(k==1);
|
||||
|
||||
k = 0;
|
||||
((k += constant(1)) += protect(constant(2)))()();
|
||||
BOOST_TEST(k==3);
|
||||
BOOST_CHECK(k==3);
|
||||
|
||||
// note, the following doesn't work:
|
||||
|
||||
@@ -276,10 +281,10 @@ void test_lambda_functors_as_arguments_to_lambda_functors() {
|
||||
// sum_0() + 7, but rather
|
||||
// bind(sum_0) + 7, which results in another lambda functor
|
||||
// (lambda functor + int) and can be called again
|
||||
BOOST_TEST((_1 + _2)(bind(&sum_0), make_const(7))() == 7);
|
||||
BOOST_CHECK((_1 + _2)(bind(&sum_0), make_const(7))() == 7);
|
||||
|
||||
int i = 3, j = 12;
|
||||
BOOST_TEST((_1 - _2)(_2, _1)(i, j) == j - i);
|
||||
BOOST_CHECK((_1 - _2)(_2, _1)(i, j) == j - i);
|
||||
|
||||
// also, note that lambda functor are no special case for bind if received
|
||||
// as a parameter. In oder to be bindable, the functor must
|
||||
@@ -292,12 +297,12 @@ void test_lambda_functors_as_arguments_to_lambda_functors() {
|
||||
int a = 5, b = 6;
|
||||
|
||||
// Let type deduction find out the return type
|
||||
BOOST_TEST(bind(_1, _2, _3)(unlambda(_1 + _2), a, b) == 11);
|
||||
BOOST_CHECK(bind(_1, _2, _3)(unlambda(_1 + _2), a, b) == 11);
|
||||
|
||||
//specify it yourself:
|
||||
BOOST_TEST(bind(_1, _2, _3)(ret<int>(_1 + _2), a, b) == 11);
|
||||
BOOST_TEST(ret<int>(bind(_1, _2, _3))(_1 + _2, a, b) == 11);
|
||||
BOOST_TEST(bind<int>(_1, _2, _3)(_1 + _2, a, b) == 11);
|
||||
BOOST_CHECK(bind(_1, _2, _3)(ret<int>(_1 + _2), a, b) == 11);
|
||||
BOOST_CHECK(ret<int>(bind(_1, _2, _3))(_1 + _2, a, b) == 11);
|
||||
BOOST_CHECK(bind<int>(_1, _2, _3)(_1 + _2, a, b) == 11);
|
||||
|
||||
bind(_1,1.0)(_1+_1);
|
||||
return;
|
||||
@@ -310,10 +315,10 @@ void test_const_parameters() {
|
||||
// (_1 + _2)(1, 2); // this would fail,
|
||||
|
||||
// Either make arguments const:
|
||||
BOOST_TEST((_1 + _2)(make_const(1), make_const(2)) == 3);
|
||||
BOOST_CHECK((_1 + _2)(make_const(1), make_const(2)) == 3);
|
||||
|
||||
// Or use const_parameters:
|
||||
BOOST_TEST(const_parameters(_1 + _2)(1, 2) == 3);
|
||||
BOOST_CHECK(const_parameters(_1 + _2)(1, 2) == 3);
|
||||
|
||||
|
||||
|
||||
@@ -323,7 +328,7 @@ void test_rvalue_arguments()
|
||||
{
|
||||
// Not quite working yet.
|
||||
// Problems with visual 7.1
|
||||
// BOOST_TEST((_1 + _2)(1, 2) == 3);
|
||||
// BOOST_CHECK((_1 + _2)(1, 2) == 3);
|
||||
}
|
||||
|
||||
void test_break_const()
|
||||
@@ -348,7 +353,56 @@ void test_break_const()
|
||||
// OLD COMMENT: (_1 += _2)(i, 2) // fails, 2 is a non-const rvalue
|
||||
// OLD COMMENT: const_parameters(_1 += _2)(i, 2) // fails, side-effect to i
|
||||
break_const(_1 += _2)(i, 2); // ok
|
||||
BOOST_TEST(i == 3);
|
||||
BOOST_CHECK(i == 3);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct func {
|
||||
template<class Args>
|
||||
struct sig {
|
||||
typedef typename boost::tuples::element<1, Args>::type arg1;
|
||||
// If the argument type is not the same as the expected type,
|
||||
// return void, which will cause an error. Note that we
|
||||
// can't just assert that the types are the same, because
|
||||
// both const and non-const versions can be instantiated
|
||||
// even though only one is ultimately used.
|
||||
typedef typename boost::mpl::if_<boost::is_same<arg1, T>,
|
||||
typename boost::remove_const<arg1>::type,
|
||||
void
|
||||
>::type type;
|
||||
};
|
||||
template<class U>
|
||||
U operator()(const U& arg) const {
|
||||
return arg;
|
||||
}
|
||||
};
|
||||
|
||||
void test_sig()
|
||||
{
|
||||
int i = 1;
|
||||
BOOST_CHECK(bind(func<int>(), 1)() == 1);
|
||||
BOOST_CHECK(bind(func<const int>(), _1)(static_cast<const int&>(i)) == 1);
|
||||
BOOST_CHECK(bind(func<int>(), _1)(i) == 1);
|
||||
}
|
||||
|
||||
class base {
|
||||
public:
|
||||
virtual int foo() = 0;
|
||||
};
|
||||
|
||||
class derived : public base {
|
||||
public:
|
||||
virtual int foo() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
void test_abstract()
|
||||
{
|
||||
derived d;
|
||||
base& b = d;
|
||||
BOOST_CHECK(bind(&base::foo, var(b))() == 1);
|
||||
BOOST_CHECK(bind(&base::foo, *_1)(&b) == 1);
|
||||
}
|
||||
|
||||
int test_main(int, char *[]) {
|
||||
@@ -360,17 +414,7 @@ int test_main(int, char *[]) {
|
||||
test_const_parameters();
|
||||
test_rvalue_arguments();
|
||||
test_break_const();
|
||||
test_sig();
|
||||
test_abstract();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// bind_tests_simple.cpp -- The Boost Lambda Library ------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::lambda;
|
||||
using namespace boost::lambda;
|
||||
|
||||
|
||||
int sum_of_args_0() { return 0; }
|
||||
@@ -65,79 +63,96 @@ void test_member_functions()
|
||||
|
||||
|
||||
|
||||
BOOST_TEST(bind(&A::add, ref(a), _1)(i) == 11);
|
||||
BOOST_TEST(bind(&A::add, &a, _1)(i) == 11);
|
||||
BOOST_TEST(bind(&A::add, _1, 1)(a) == 11);
|
||||
BOOST_TEST(bind(&A::add, _1, 1)(make_const(&a)) == 11);
|
||||
BOOST_CHECK(bind(&A::add, ref(a), _1)(i) == 11);
|
||||
BOOST_CHECK(bind(&A::add, &a, _1)(i) == 11);
|
||||
BOOST_CHECK(bind(&A::add, _1, 1)(a) == 11);
|
||||
BOOST_CHECK(bind(&A::add, _1, 1)(make_const(&a)) == 11);
|
||||
|
||||
BOOST_TEST(bind(&A::add2, _1, 1, 1)(a) == 12);
|
||||
BOOST_TEST(bind(&A::add3, _1, 1, 1, 1)(a) == 13);
|
||||
BOOST_TEST(bind(&A::add4, _1, 1, 1, 1, 1)(a) == 14);
|
||||
BOOST_TEST(bind(&A::add5, _1, 1, 1, 1, 1, 1)(a) == 15);
|
||||
BOOST_TEST(bind(&A::add6, _1, 1, 1, 1, 1, 1, 1)(a) == 16);
|
||||
BOOST_TEST(bind(&A::add7, _1, 1, 1, 1, 1, 1, 1, 1)(a) == 17);
|
||||
BOOST_TEST(bind(&A::add8, _1, 1, 1, 1, 1, 1, 1, 1, 1)(a) == 18);
|
||||
BOOST_CHECK(bind(&A::add2, _1, 1, 1)(a) == 12);
|
||||
BOOST_CHECK(bind(&A::add3, _1, 1, 1, 1)(a) == 13);
|
||||
BOOST_CHECK(bind(&A::add4, _1, 1, 1, 1, 1)(a) == 14);
|
||||
BOOST_CHECK(bind(&A::add5, _1, 1, 1, 1, 1, 1)(a) == 15);
|
||||
BOOST_CHECK(bind(&A::add6, _1, 1, 1, 1, 1, 1, 1)(a) == 16);
|
||||
BOOST_CHECK(bind(&A::add7, _1, 1, 1, 1, 1, 1, 1, 1)(a) == 17);
|
||||
BOOST_CHECK(bind(&A::add8, _1, 1, 1, 1, 1, 1, 1, 1, 1)(a) == 18);
|
||||
|
||||
// This should fail, as lambda functors store arguments as const
|
||||
// bind(&A::add, a, _1);
|
||||
}
|
||||
|
||||
struct B {
|
||||
B(int n) : i(n) {};
|
||||
int i;
|
||||
};
|
||||
|
||||
void test_data_members()
|
||||
{
|
||||
using boost::ref;
|
||||
B b(10);
|
||||
BOOST_CHECK(bind(&B::i, ref(b))() == 10);
|
||||
BOOST_CHECK(bind(&B::i, b)() == 10);
|
||||
BOOST_CHECK(bind(&B::i, _1)(b) == 10);
|
||||
BOOST_CHECK(bind(&B::i, _1)(B(11)) == 11);
|
||||
bind(&B::i, ref(b))() = 1;
|
||||
BOOST_CHECK(b.i == 1);
|
||||
}
|
||||
|
||||
int test_main(int, char *[]) {
|
||||
|
||||
int i = 1; int j = 2; int k = 3;
|
||||
int result;
|
||||
|
||||
// bind all parameters
|
||||
BOOST_TEST(bind(&sum_of_args_0)()==0);
|
||||
BOOST_TEST(bind(&sum_of_args_1, 1)()==1);
|
||||
BOOST_TEST(bind(&sum_of_args_2, 1, 2)()==3);
|
||||
BOOST_TEST(bind(&sum_of_args_3, 1, 2, 3)()==6);
|
||||
BOOST_TEST(bind(&sum_of_args_4, 1, 2, 3, 4)()==10);
|
||||
BOOST_TEST(bind(&sum_of_args_5, 1, 2, 3, 4, 5)()==15);
|
||||
BOOST_TEST(bind(&sum_of_args_6, 1, 2, 3, 4, 5, 6)()==21);
|
||||
BOOST_TEST(bind(&sum_of_args_7, 1, 2, 3, 4, 5, 6, 7)()==28);
|
||||
BOOST_TEST(bind(&sum_of_args_8, 1, 2, 3, 4, 5, 6, 7, 8)()==36);
|
||||
BOOST_TEST(bind(&sum_of_args_9, 1, 2, 3, 4, 5, 6, 7, 8, 9)()==45);
|
||||
BOOST_CHECK(bind(&sum_of_args_0)()==0);
|
||||
BOOST_CHECK(bind(&sum_of_args_1, 1)()==1);
|
||||
BOOST_CHECK(bind(&sum_of_args_2, 1, 2)()==3);
|
||||
BOOST_CHECK(bind(&sum_of_args_3, 1, 2, 3)()==6);
|
||||
BOOST_CHECK(bind(&sum_of_args_4, 1, 2, 3, 4)()==10);
|
||||
BOOST_CHECK(bind(&sum_of_args_5, 1, 2, 3, 4, 5)()==15);
|
||||
BOOST_CHECK(bind(&sum_of_args_6, 1, 2, 3, 4, 5, 6)()==21);
|
||||
BOOST_CHECK(bind(&sum_of_args_7, 1, 2, 3, 4, 5, 6, 7)()==28);
|
||||
BOOST_CHECK(bind(&sum_of_args_8, 1, 2, 3, 4, 5, 6, 7, 8)()==36);
|
||||
BOOST_CHECK(bind(&sum_of_args_9, 1, 2, 3, 4, 5, 6, 7, 8, 9)()==45);
|
||||
|
||||
// first parameter open
|
||||
BOOST_TEST(bind(&sum_of_args_0)()==0);
|
||||
BOOST_TEST(bind(&sum_of_args_1, _1)(i)==1);
|
||||
BOOST_TEST(bind(&sum_of_args_2, _1, 2)(i)==3);
|
||||
BOOST_TEST(bind(&sum_of_args_3, _1, 2, 3)(i)==6);
|
||||
BOOST_TEST(bind(&sum_of_args_4, _1, 2, 3, 4)(i)==10);
|
||||
BOOST_TEST(bind(&sum_of_args_5, _1, 2, 3, 4, 5)(i)==15);
|
||||
BOOST_TEST(bind(&sum_of_args_6, _1, 2, 3, 4, 5, 6)(i)==21);
|
||||
BOOST_TEST(bind(&sum_of_args_7, _1, 2, 3, 4, 5, 6, 7)(i)==28);
|
||||
BOOST_TEST(bind(&sum_of_args_8, _1, 2, 3, 4, 5, 6, 7, 8)(i)==36);
|
||||
BOOST_TEST(bind(&sum_of_args_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i)==45);
|
||||
BOOST_CHECK(bind(&sum_of_args_0)()==0);
|
||||
BOOST_CHECK(bind(&sum_of_args_1, _1)(i)==1);
|
||||
BOOST_CHECK(bind(&sum_of_args_2, _1, 2)(i)==3);
|
||||
BOOST_CHECK(bind(&sum_of_args_3, _1, 2, 3)(i)==6);
|
||||
BOOST_CHECK(bind(&sum_of_args_4, _1, 2, 3, 4)(i)==10);
|
||||
BOOST_CHECK(bind(&sum_of_args_5, _1, 2, 3, 4, 5)(i)==15);
|
||||
BOOST_CHECK(bind(&sum_of_args_6, _1, 2, 3, 4, 5, 6)(i)==21);
|
||||
BOOST_CHECK(bind(&sum_of_args_7, _1, 2, 3, 4, 5, 6, 7)(i)==28);
|
||||
BOOST_CHECK(bind(&sum_of_args_8, _1, 2, 3, 4, 5, 6, 7, 8)(i)==36);
|
||||
BOOST_CHECK(bind(&sum_of_args_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i)==45);
|
||||
|
||||
// two open arguments
|
||||
BOOST_TEST(bind(&sum_of_args_0)()==0);
|
||||
BOOST_TEST(bind(&sum_of_args_1, _1)(i)==1);
|
||||
BOOST_TEST(bind(&sum_of_args_2, _1, _2)(i, j)==3);
|
||||
BOOST_TEST(bind(&sum_of_args_3, _1, _2, 3)(i, j)==6);
|
||||
BOOST_TEST(bind(&sum_of_args_4, _1, _2, 3, 4)(i, j)==10);
|
||||
BOOST_TEST(bind(&sum_of_args_5, _1, _2, 3, 4, 5)(i, j)==15);
|
||||
BOOST_TEST(bind(&sum_of_args_6, _1, _2, 3, 4, 5, 6)(i, j)==21);
|
||||
BOOST_TEST(bind(&sum_of_args_7, _1, _2, 3, 4, 5, 6, 7)(i, j)==28);
|
||||
BOOST_TEST(bind(&sum_of_args_8, _1, _2, 3, 4, 5, 6, 7, 8)(i, j)==36);
|
||||
BOOST_TEST(bind(&sum_of_args_9, _1, _2, 3, 4, 5, 6, 7, 8, 9)(i, j)==45);
|
||||
BOOST_CHECK(bind(&sum_of_args_0)()==0);
|
||||
BOOST_CHECK(bind(&sum_of_args_1, _1)(i)==1);
|
||||
BOOST_CHECK(bind(&sum_of_args_2, _1, _2)(i, j)==3);
|
||||
BOOST_CHECK(bind(&sum_of_args_3, _1, _2, 3)(i, j)==6);
|
||||
BOOST_CHECK(bind(&sum_of_args_4, _1, _2, 3, 4)(i, j)==10);
|
||||
BOOST_CHECK(bind(&sum_of_args_5, _1, _2, 3, 4, 5)(i, j)==15);
|
||||
BOOST_CHECK(bind(&sum_of_args_6, _1, _2, 3, 4, 5, 6)(i, j)==21);
|
||||
BOOST_CHECK(bind(&sum_of_args_7, _1, _2, 3, 4, 5, 6, 7)(i, j)==28);
|
||||
BOOST_CHECK(bind(&sum_of_args_8, _1, _2, 3, 4, 5, 6, 7, 8)(i, j)==36);
|
||||
BOOST_CHECK(bind(&sum_of_args_9, _1, _2, 3, 4, 5, 6, 7, 8, 9)(i, j)==45);
|
||||
|
||||
// three open arguments
|
||||
BOOST_TEST(bind(&sum_of_args_0)()==0);
|
||||
BOOST_TEST(bind(&sum_of_args_1, _1)(i)==1);
|
||||
BOOST_TEST(bind(&sum_of_args_2, _1, _2)(i, j)==3);
|
||||
BOOST_TEST(bind(&sum_of_args_3, _1, _2, _3)(i, j, k)==6);
|
||||
BOOST_TEST(bind(&sum_of_args_4, _1, _2, _3, 4)(i, j, k)==10);
|
||||
BOOST_TEST(bind(&sum_of_args_5, _1, _2, _3, 4, 5)(i, j, k)==15);
|
||||
BOOST_TEST(bind(&sum_of_args_6, _1, _2, _3, 4, 5, 6)(i, j, k)==21);
|
||||
BOOST_TEST(bind(&sum_of_args_7, _1, _2, _3, 4, 5, 6, 7)(i, j, k)==28);
|
||||
BOOST_TEST(bind(&sum_of_args_8, _1, _2, _3, 4, 5, 6, 7, 8)(i, j, k)==36);
|
||||
BOOST_TEST(bind(&sum_of_args_9, _1, _2, _3, 4, 5, 6, 7, 8, 9)(i, j, k)==45);
|
||||
BOOST_CHECK(bind(&sum_of_args_0)()==0);
|
||||
BOOST_CHECK(bind(&sum_of_args_1, _1)(i)==1);
|
||||
BOOST_CHECK(bind(&sum_of_args_2, _1, _2)(i, j)==3);
|
||||
BOOST_CHECK(bind(&sum_of_args_3, _1, _2, _3)(i, j, k)==6);
|
||||
BOOST_CHECK(bind(&sum_of_args_4, _1, _2, _3, 4)(i, j, k)==10);
|
||||
BOOST_CHECK(bind(&sum_of_args_5, _1, _2, _3, 4, 5)(i, j, k)==15);
|
||||
BOOST_CHECK(bind(&sum_of_args_6, _1, _2, _3, 4, 5, 6)(i, j, k)==21);
|
||||
BOOST_CHECK(bind(&sum_of_args_7, _1, _2, _3, 4, 5, 6, 7)(i, j, k)==28);
|
||||
BOOST_CHECK(bind(&sum_of_args_8, _1, _2, _3, 4, 5, 6, 7, 8)(i, j, k)==36);
|
||||
BOOST_CHECK(bind(&sum_of_args_9, _1, _2, _3, 4, 5, 6, 7, 8, 9)(i, j, k)==45);
|
||||
|
||||
// function compositions with bind
|
||||
BOOST_TEST(bind(&sum_of_args_3, bind(&sum_of_args_2, _1, 2), 2, 3)(i)==8);
|
||||
BOOST_TEST(
|
||||
BOOST_CHECK(bind(&sum_of_args_3, bind(&sum_of_args_2, _1, 2), 2, 3)(i)==8);
|
||||
BOOST_CHECK(
|
||||
bind(&sum_of_args_9,
|
||||
bind(&sum_of_args_0), // 0
|
||||
bind(&sum_of_args_1, _1), // 1
|
||||
@@ -163,7 +178,7 @@ int test_main(int, char *[]) {
|
||||
_3,
|
||||
4)
|
||||
)(i, j, k);
|
||||
BOOST_TEST(result == 12);
|
||||
BOOST_CHECK(result == 12);
|
||||
|
||||
test_member_functions();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// bind_tests_simple.cpp -- The Boost Lambda Library ------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::lambda;
|
||||
using namespace boost::lambda;
|
||||
|
||||
|
||||
int sum_of_args_0() { return 0; }
|
||||
@@ -50,10 +48,10 @@ void test_member_functions()
|
||||
A a(10);
|
||||
int i = 1;
|
||||
|
||||
BOOST_TEST(bind(&A::add, ref(a), _1)(i) == 11);
|
||||
BOOST_TEST(bind(&A::add, &a, _1)(i) == 11);
|
||||
BOOST_TEST(bind(&A::add, _1, 1)(a) == 11);
|
||||
BOOST_TEST(bind(&A::add, _1, 1)(make_const(&a)) == 11);
|
||||
BOOST_CHECK(bind(&A::add, ref(a), _1)(i) == 11);
|
||||
BOOST_CHECK(bind(&A::add, &a, _1)(i) == 11);
|
||||
BOOST_CHECK(bind(&A::add, _1, 1)(a) == 11);
|
||||
BOOST_CHECK(bind(&A::add, _1, 1)(make_const(&a)) == 11);
|
||||
|
||||
// This should fail, as lambda functors store arguments as const
|
||||
// bind(&A::add, a, _1);
|
||||
@@ -66,56 +64,56 @@ int test_main(int, char *[]) {
|
||||
|
||||
|
||||
// bind all parameters
|
||||
BOOST_TEST(bind(sum_of_args_0)()==0);
|
||||
BOOST_TEST(bind(sum_of_args_1, 1)()==1);
|
||||
BOOST_TEST(bind(sum_of_args_2, 1, 2)()==3);
|
||||
BOOST_TEST(bind(sum_of_args_3, 1, 2, 3)()==6);
|
||||
BOOST_TEST(bind(sum_of_args_4, 1, 2, 3, 4)()==10);
|
||||
BOOST_TEST(bind(sum_of_args_5, 1, 2, 3, 4, 5)()==15);
|
||||
BOOST_TEST(bind(sum_of_args_6, 1, 2, 3, 4, 5, 6)()==21);
|
||||
BOOST_TEST(bind(sum_of_args_7, 1, 2, 3, 4, 5, 6, 7)()==28);
|
||||
BOOST_TEST(bind(sum_of_args_8, 1, 2, 3, 4, 5, 6, 7, 8)()==36);
|
||||
BOOST_TEST(bind(sum_of_args_9, 1, 2, 3, 4, 5, 6, 7, 8, 9)()==45);
|
||||
BOOST_CHECK(bind(sum_of_args_0)()==0);
|
||||
BOOST_CHECK(bind(sum_of_args_1, 1)()==1);
|
||||
BOOST_CHECK(bind(sum_of_args_2, 1, 2)()==3);
|
||||
BOOST_CHECK(bind(sum_of_args_3, 1, 2, 3)()==6);
|
||||
BOOST_CHECK(bind(sum_of_args_4, 1, 2, 3, 4)()==10);
|
||||
BOOST_CHECK(bind(sum_of_args_5, 1, 2, 3, 4, 5)()==15);
|
||||
BOOST_CHECK(bind(sum_of_args_6, 1, 2, 3, 4, 5, 6)()==21);
|
||||
BOOST_CHECK(bind(sum_of_args_7, 1, 2, 3, 4, 5, 6, 7)()==28);
|
||||
BOOST_CHECK(bind(sum_of_args_8, 1, 2, 3, 4, 5, 6, 7, 8)()==36);
|
||||
BOOST_CHECK(bind(sum_of_args_9, 1, 2, 3, 4, 5, 6, 7, 8, 9)()==45);
|
||||
|
||||
// first parameter open
|
||||
BOOST_TEST(bind(sum_of_args_0)()==0);
|
||||
BOOST_TEST(bind(sum_of_args_1, _1)(i)==1);
|
||||
BOOST_TEST(bind(sum_of_args_2, _1, 2)(i)==3);
|
||||
BOOST_TEST(bind(sum_of_args_3, _1, 2, 3)(i)==6);
|
||||
BOOST_TEST(bind(sum_of_args_4, _1, 2, 3, 4)(i)==10);
|
||||
BOOST_TEST(bind(sum_of_args_5, _1, 2, 3, 4, 5)(i)==15);
|
||||
BOOST_TEST(bind(sum_of_args_6, _1, 2, 3, 4, 5, 6)(i)==21);
|
||||
BOOST_TEST(bind(sum_of_args_7, _1, 2, 3, 4, 5, 6, 7)(i)==28);
|
||||
BOOST_TEST(bind(sum_of_args_8, _1, 2, 3, 4, 5, 6, 7, 8)(i)==36);
|
||||
BOOST_TEST(bind(sum_of_args_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i)==45);
|
||||
BOOST_CHECK(bind(sum_of_args_0)()==0);
|
||||
BOOST_CHECK(bind(sum_of_args_1, _1)(i)==1);
|
||||
BOOST_CHECK(bind(sum_of_args_2, _1, 2)(i)==3);
|
||||
BOOST_CHECK(bind(sum_of_args_3, _1, 2, 3)(i)==6);
|
||||
BOOST_CHECK(bind(sum_of_args_4, _1, 2, 3, 4)(i)==10);
|
||||
BOOST_CHECK(bind(sum_of_args_5, _1, 2, 3, 4, 5)(i)==15);
|
||||
BOOST_CHECK(bind(sum_of_args_6, _1, 2, 3, 4, 5, 6)(i)==21);
|
||||
BOOST_CHECK(bind(sum_of_args_7, _1, 2, 3, 4, 5, 6, 7)(i)==28);
|
||||
BOOST_CHECK(bind(sum_of_args_8, _1, 2, 3, 4, 5, 6, 7, 8)(i)==36);
|
||||
BOOST_CHECK(bind(sum_of_args_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i)==45);
|
||||
|
||||
// two open arguments
|
||||
BOOST_TEST(bind(sum_of_args_0)()==0);
|
||||
BOOST_TEST(bind(sum_of_args_1, _1)(i)==1);
|
||||
BOOST_TEST(bind(sum_of_args_2, _1, _2)(i, j)==3);
|
||||
BOOST_TEST(bind(sum_of_args_3, _1, _2, 3)(i, j)==6);
|
||||
BOOST_TEST(bind(sum_of_args_4, _1, _2, 3, 4)(i, j)==10);
|
||||
BOOST_TEST(bind(sum_of_args_5, _1, _2, 3, 4, 5)(i, j)==15);
|
||||
BOOST_TEST(bind(sum_of_args_6, _1, _2, 3, 4, 5, 6)(i, j)==21);
|
||||
BOOST_TEST(bind(sum_of_args_7, _1, _2, 3, 4, 5, 6, 7)(i, j)==28);
|
||||
BOOST_TEST(bind(sum_of_args_8, _1, _2, 3, 4, 5, 6, 7, 8)(i, j)==36);
|
||||
BOOST_TEST(bind(sum_of_args_9, _1, _2, 3, 4, 5, 6, 7, 8, 9)(i, j)==45);
|
||||
BOOST_CHECK(bind(sum_of_args_0)()==0);
|
||||
BOOST_CHECK(bind(sum_of_args_1, _1)(i)==1);
|
||||
BOOST_CHECK(bind(sum_of_args_2, _1, _2)(i, j)==3);
|
||||
BOOST_CHECK(bind(sum_of_args_3, _1, _2, 3)(i, j)==6);
|
||||
BOOST_CHECK(bind(sum_of_args_4, _1, _2, 3, 4)(i, j)==10);
|
||||
BOOST_CHECK(bind(sum_of_args_5, _1, _2, 3, 4, 5)(i, j)==15);
|
||||
BOOST_CHECK(bind(sum_of_args_6, _1, _2, 3, 4, 5, 6)(i, j)==21);
|
||||
BOOST_CHECK(bind(sum_of_args_7, _1, _2, 3, 4, 5, 6, 7)(i, j)==28);
|
||||
BOOST_CHECK(bind(sum_of_args_8, _1, _2, 3, 4, 5, 6, 7, 8)(i, j)==36);
|
||||
BOOST_CHECK(bind(sum_of_args_9, _1, _2, 3, 4, 5, 6, 7, 8, 9)(i, j)==45);
|
||||
|
||||
// three open arguments
|
||||
BOOST_TEST(bind(sum_of_args_0)()==0);
|
||||
BOOST_TEST(bind(sum_of_args_1, _1)(i)==1);
|
||||
BOOST_TEST(bind(sum_of_args_2, _1, _2)(i, j)==3);
|
||||
BOOST_TEST(bind(sum_of_args_3, _1, _2, _3)(i, j, k)==6);
|
||||
BOOST_TEST(bind(sum_of_args_4, _1, _2, _3, 4)(i, j, k)==10);
|
||||
BOOST_TEST(bind(sum_of_args_5, _1, _2, _3, 4, 5)(i, j, k)==15);
|
||||
BOOST_TEST(bind(sum_of_args_6, _1, _2, _3, 4, 5, 6)(i, j, k)==21);
|
||||
BOOST_TEST(bind(sum_of_args_7, _1, _2, _3, 4, 5, 6, 7)(i, j, k)==28);
|
||||
BOOST_TEST(bind(sum_of_args_8, _1, _2, _3, 4, 5, 6, 7, 8)(i, j, k)==36);
|
||||
BOOST_TEST(bind(sum_of_args_9, _1, _2, _3, 4, 5, 6, 7, 8, 9)(i, j, k)==45);
|
||||
BOOST_CHECK(bind(sum_of_args_0)()==0);
|
||||
BOOST_CHECK(bind(sum_of_args_1, _1)(i)==1);
|
||||
BOOST_CHECK(bind(sum_of_args_2, _1, _2)(i, j)==3);
|
||||
BOOST_CHECK(bind(sum_of_args_3, _1, _2, _3)(i, j, k)==6);
|
||||
BOOST_CHECK(bind(sum_of_args_4, _1, _2, _3, 4)(i, j, k)==10);
|
||||
BOOST_CHECK(bind(sum_of_args_5, _1, _2, _3, 4, 5)(i, j, k)==15);
|
||||
BOOST_CHECK(bind(sum_of_args_6, _1, _2, _3, 4, 5, 6)(i, j, k)==21);
|
||||
BOOST_CHECK(bind(sum_of_args_7, _1, _2, _3, 4, 5, 6, 7)(i, j, k)==28);
|
||||
BOOST_CHECK(bind(sum_of_args_8, _1, _2, _3, 4, 5, 6, 7, 8)(i, j, k)==36);
|
||||
BOOST_CHECK(bind(sum_of_args_9, _1, _2, _3, 4, 5, 6, 7, 8, 9)(i, j, k)==45);
|
||||
|
||||
// function compositions with bind
|
||||
BOOST_TEST(bind(sum_of_args_3, bind(sum_of_args_2, _1, 2), 2, 3)(i)==8);
|
||||
BOOST_TEST(
|
||||
BOOST_CHECK(bind(sum_of_args_3, bind(sum_of_args_2, _1, 2), 2, 3)(i)==8);
|
||||
BOOST_CHECK(
|
||||
bind(sum_of_args_9,
|
||||
bind(sum_of_args_0), // 0
|
||||
bind(sum_of_args_1, _1), // 1
|
||||
@@ -141,7 +139,7 @@ int test_main(int, char *[]) {
|
||||
_3,
|
||||
4)
|
||||
)(i, j, k);
|
||||
BOOST_TEST(result == 12);
|
||||
BOOST_CHECK(result == 12);
|
||||
|
||||
test_member_functions();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// bll_and_function.cpp - The Boost Lambda Library -----------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -32,12 +32,12 @@ void test_function() {
|
||||
boost::function<int (int, int)> f;
|
||||
f = _1 + _2;
|
||||
|
||||
BOOST_TEST(f(1, 2)== 3);
|
||||
BOOST_CHECK(f(1, 2)== 3);
|
||||
|
||||
int i=1; int j=2;
|
||||
boost::function<int& (int&, int)> g = _1 += _2;
|
||||
g(i, j);
|
||||
BOOST_TEST(i==3);
|
||||
BOOST_CHECK(i==3);
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ void test_function() {
|
||||
*sum = 0;
|
||||
boost::function<int& (int)> counter = *sum += _1;
|
||||
counter(5); // ok, sum* = 5;
|
||||
BOOST_TEST(*sum == 5);
|
||||
BOOST_CHECK(*sum == 5);
|
||||
delete sum;
|
||||
|
||||
// The next statement would lead to a dangling reference
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// cast_tests.cpp -- The Boost Lambda Library ------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -29,7 +29,7 @@ class base {
|
||||
public:
|
||||
virtual std::string class_name() const { return "const base"; }
|
||||
virtual std::string class_name() { return "base"; }
|
||||
|
||||
virtual ~base() {}
|
||||
};
|
||||
|
||||
class derived : public base {
|
||||
@@ -53,46 +53,46 @@ void do_test() {
|
||||
(var(b) = ll_static_cast<base *>(p_derived))();
|
||||
(var(d) = ll_static_cast<derived *>(b))();
|
||||
|
||||
BOOST_TEST(b->class_name() == "derived");
|
||||
BOOST_TEST(d->class_name() == "derived");
|
||||
BOOST_CHECK(b->class_name() == "derived");
|
||||
BOOST_CHECK(d->class_name() == "derived");
|
||||
|
||||
(var(b) = ll_dynamic_cast<derived *>(b))();
|
||||
BOOST_TEST(b != 0);
|
||||
BOOST_TEST(b->class_name() == "derived");
|
||||
BOOST_CHECK(b != 0);
|
||||
BOOST_CHECK(b->class_name() == "derived");
|
||||
|
||||
(var(d) = ll_dynamic_cast<derived *>(p_base))();
|
||||
BOOST_TEST(d == 0);
|
||||
BOOST_CHECK(d == 0);
|
||||
|
||||
|
||||
|
||||
const derived* p_const_derived = p_derived;
|
||||
|
||||
BOOST_TEST(p_const_derived->class_name() == "const derived");
|
||||
BOOST_CHECK(p_const_derived->class_name() == "const derived");
|
||||
(var(d) = ll_const_cast<derived *>(p_const_derived))();
|
||||
BOOST_TEST(d->class_name() == "derived");
|
||||
BOOST_CHECK(d->class_name() == "derived");
|
||||
|
||||
int i = 10;
|
||||
char* cp = reinterpret_cast<char*>(&i);
|
||||
|
||||
int* ip;
|
||||
(var(ip) = ll_reinterpret_cast<int *>(cp))();
|
||||
BOOST_TEST(*ip == 10);
|
||||
BOOST_CHECK(*ip == 10);
|
||||
|
||||
|
||||
// typeid
|
||||
|
||||
BOOST_TEST(string(ll_typeid(d)().name()) == string(typeid(d).name()));
|
||||
BOOST_CHECK(string(ll_typeid(d)().name()) == string(typeid(d).name()));
|
||||
|
||||
|
||||
// sizeof
|
||||
|
||||
BOOST_TEST(ll_sizeof(_1)(p_derived) == sizeof(p_derived));
|
||||
BOOST_TEST(ll_sizeof(_1)(*p_derived) == sizeof(*p_derived));
|
||||
BOOST_TEST(ll_sizeof(_1)(p_base) == sizeof(p_base));
|
||||
BOOST_TEST(ll_sizeof(_1)(*p_base) == sizeof(*p_base));
|
||||
BOOST_CHECK(ll_sizeof(_1)(p_derived) == sizeof(p_derived));
|
||||
BOOST_CHECK(ll_sizeof(_1)(*p_derived) == sizeof(*p_derived));
|
||||
BOOST_CHECK(ll_sizeof(_1)(p_base) == sizeof(p_base));
|
||||
BOOST_CHECK(ll_sizeof(_1)(*p_base) == sizeof(*p_base));
|
||||
|
||||
int an_array[100];
|
||||
BOOST_TEST(ll_sizeof(_1)(an_array) == 100 * sizeof(int));
|
||||
BOOST_CHECK(ll_sizeof(_1)(an_array) == 100 * sizeof(int));
|
||||
|
||||
delete p_derived;
|
||||
delete p_base;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// constructor_tests.cpp -- The Boost Lambda Library ------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -24,8 +24,12 @@
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(disable:4512)
|
||||
#endif
|
||||
|
||||
using namespace boost::lambda;
|
||||
using namespace std;
|
||||
namespace bl = boost::lambda;
|
||||
|
||||
template<class T>
|
||||
bool check_tuple(int n, const T& t)
|
||||
@@ -34,7 +38,7 @@ bool check_tuple(int n, const T& t)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool check_tuple(int n, const null_type& ) { return true; }
|
||||
bool check_tuple(int /*n*/, const null_type& ) { return true; }
|
||||
|
||||
|
||||
void constructor_all_lengths()
|
||||
@@ -45,63 +49,63 @@ void constructor_all_lengths()
|
||||
bind(constructor<tuple<int> >(),
|
||||
1)()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
bind(constructor<tuple<int, int> >(),
|
||||
1, 2)()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
bind(constructor<tuple<int, int, int> >(),
|
||||
1, 2, 3)()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
bind(constructor<tuple<int, int, int, int> >(),
|
||||
1, 2, 3, 4)()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
bind(constructor<tuple<int, int, int, int, int> >(),
|
||||
1, 2, 3, 4, 5)()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
bind(constructor<tuple<int, int, int, int, int, int> >(),
|
||||
1, 2, 3, 4, 5, 6)()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
bind(constructor<tuple<int, int, int, int, int, int, int> >(),
|
||||
1, 2, 3, 4, 5, 6, 7)()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
bind(constructor<tuple<int, int, int, int, int, int, int, int> >(),
|
||||
1, 2, 3, 4, 5, 6, 7, 8)()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
bind(constructor<tuple<int, int, int, int, int, int, int, int, int> >(),
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9)()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
}
|
||||
|
||||
@@ -113,63 +117,63 @@ void new_ptr_all_lengths()
|
||||
*(bind(new_ptr<tuple<int> >(),
|
||||
1))()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
*(bind(new_ptr<tuple<int, int> >(),
|
||||
1, 2))()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
*(bind(new_ptr<tuple<int, int, int> >(),
|
||||
1, 2, 3))()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
*(bind(new_ptr<tuple<int, int, int, int> >(),
|
||||
1, 2, 3, 4))()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
*(bind(new_ptr<tuple<int, int, int, int, int> >(),
|
||||
1, 2, 3, 4, 5))()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
*(bind(new_ptr<tuple<int, int, int, int, int, int> >(),
|
||||
1, 2, 3, 4, 5, 6))()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
*(bind(new_ptr<tuple<int, int, int, int, int, int, int> >(),
|
||||
1, 2, 3, 4, 5, 6, 7))()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
*(bind(new_ptr<tuple<int, int, int, int, int, int, int, int> >(),
|
||||
1, 2, 3, 4, 5, 6, 7, 8))()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
ok = check_tuple(
|
||||
1,
|
||||
*(bind(new_ptr<tuple<int, int, int, int, int, int, int, int, int> >(),
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9))()
|
||||
);
|
||||
BOOST_TEST(ok);
|
||||
BOOST_CHECK(ok);
|
||||
|
||||
}
|
||||
|
||||
@@ -183,17 +187,17 @@ public:
|
||||
void test_destructor ()
|
||||
{
|
||||
char space[sizeof(is_destructor_called)];
|
||||
bool flag;
|
||||
bool flag = false;
|
||||
|
||||
is_destructor_called* idc = new(space) is_destructor_called(flag);
|
||||
BOOST_TEST(flag == false);
|
||||
BOOST_CHECK(flag == false);
|
||||
bind(destructor(), _1)(idc);
|
||||
BOOST_TEST(flag == true);
|
||||
BOOST_CHECK(flag == true);
|
||||
|
||||
idc = new(space) is_destructor_called(flag);
|
||||
BOOST_TEST(flag == false);
|
||||
BOOST_CHECK(flag == false);
|
||||
bind(destructor(), _1)(*idc);
|
||||
BOOST_TEST(flag == true);
|
||||
BOOST_CHECK(flag == true);
|
||||
}
|
||||
|
||||
|
||||
@@ -208,18 +212,18 @@ int count_deletes::count = 0;
|
||||
void test_news_and_deletes ()
|
||||
{
|
||||
int* i[10];
|
||||
for_each(i, i+10, _1 = bind(new_ptr<int>(), 2));
|
||||
std::for_each(i, i+10, _1 = bind(new_ptr<int>(), 2));
|
||||
int count_errors = 0;
|
||||
|
||||
for_each(i, i+10, (*_1 == 2) || ++var(count_errors));
|
||||
BOOST_TEST(count_errors == 0);
|
||||
std::for_each(i, i+10, (*_1 == 2) || ++var(count_errors));
|
||||
BOOST_CHECK(count_errors == 0);
|
||||
|
||||
|
||||
count_deletes* ct[10];
|
||||
for_each(ct, ct+10, _1 = bind(new_ptr<count_deletes>()));
|
||||
std::for_each(ct, ct+10, _1 = bind(new_ptr<count_deletes>()));
|
||||
count_deletes::count = 0;
|
||||
for_each(ct, ct+10, bind(delete_ptr(), _1));
|
||||
BOOST_TEST(count_deletes::count == 10);
|
||||
std::for_each(ct, ct+10, bind(delete_ptr(), _1));
|
||||
BOOST_CHECK(count_deletes::count == 10);
|
||||
|
||||
}
|
||||
|
||||
@@ -230,22 +234,22 @@ void test_array_new_and_delete()
|
||||
count_deletes::count = 0;
|
||||
|
||||
bind(delete_array(), _1)(c);
|
||||
BOOST_TEST(count_deletes::count == 5);
|
||||
BOOST_CHECK(count_deletes::count == 5);
|
||||
}
|
||||
|
||||
|
||||
void delayed_construction()
|
||||
{
|
||||
vector<int> x(3);
|
||||
vector<int> y(3);
|
||||
std::vector<int> x(3);
|
||||
std::vector<int> y(3);
|
||||
|
||||
fill(x.begin(), x.end(), 0);
|
||||
fill(y.begin(), y.end(), 1);
|
||||
std::fill(x.begin(), x.end(), 0);
|
||||
std::fill(y.begin(), y.end(), 1);
|
||||
|
||||
vector<pair<int, int> > v;
|
||||
std::vector<std::pair<int, int> > v;
|
||||
|
||||
transform(x.begin(), x.end(), y.begin(), back_inserter(v),
|
||||
bind(constructor<pair<int, int> >(), _1, _2) );
|
||||
std::transform(x.begin(), x.end(), y.begin(), std::back_inserter(v),
|
||||
bl::bind(constructor<std::pair<int, int> >(), _1, _2) );
|
||||
}
|
||||
|
||||
int test_main(int, char *[]) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// -- control_structures.cpp -- The Boost Lambda Library ------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -50,41 +50,41 @@ void simple_loops() {
|
||||
int i;
|
||||
int arithmetic_series = 0;
|
||||
for_loop(_1 = 0, _1 < 10, _1++, arithmetic_series += _1)(i);
|
||||
BOOST_TEST(arithmetic_series == 45);
|
||||
BOOST_CHECK(arithmetic_series == 45);
|
||||
|
||||
// no body case
|
||||
for_loop(boost::lambda::var(i) = 0, boost::lambda::var(i) < 100, ++boost::lambda::var(i))();
|
||||
BOOST_TEST(i == 100);
|
||||
BOOST_CHECK(i == 100);
|
||||
|
||||
// while loops -------------------------------------------------------
|
||||
int a = 0, b = 0, c = 0;
|
||||
|
||||
while_loop((_1 + _2) >= (_1 * _2), (++_1, ++_2, ++_3))(a, b, c);
|
||||
BOOST_TEST(c == 3);
|
||||
BOOST_CHECK(c == 3);
|
||||
|
||||
int count;
|
||||
count = 0; i = 0;
|
||||
while_loop(_1++ < 10, ++boost::lambda::var(count))(i);
|
||||
BOOST_TEST(count == 10);
|
||||
BOOST_CHECK(count == 10);
|
||||
|
||||
// note that the first parameter of do_while_loop is the condition
|
||||
count = 0; i = 0;
|
||||
do_while_loop(_1++ < 10, ++boost::lambda::var(count))(i);
|
||||
BOOST_TEST(count == 11);
|
||||
BOOST_CHECK(count == 11);
|
||||
|
||||
a = 0;
|
||||
do_while_loop(constant(false), _1++)(a);
|
||||
BOOST_TEST(a == 1);
|
||||
BOOST_CHECK(a == 1);
|
||||
|
||||
// no body cases
|
||||
a = 40; b = 30;
|
||||
while_loop(--_1 > _2)(a, b);
|
||||
BOOST_TEST(a == b);
|
||||
BOOST_CHECK(a == b);
|
||||
|
||||
// (the no body case for do_while_loop is pretty redundant)
|
||||
a = 40; b = 30;
|
||||
do_while_loop(--_1 > _2)(a, b);
|
||||
BOOST_TEST(a == b);
|
||||
BOOST_CHECK(a == b);
|
||||
|
||||
|
||||
}
|
||||
@@ -93,25 +93,25 @@ void simple_ifs () {
|
||||
|
||||
int value = 42;
|
||||
if_then(_1 < 0, _1 = 0)(value);
|
||||
BOOST_TEST(value == 42);
|
||||
BOOST_CHECK(value == 42);
|
||||
|
||||
value = -42;
|
||||
if_then(_1 < 0, _1 = -_1)(value);
|
||||
BOOST_TEST(value == 42);
|
||||
BOOST_CHECK(value == 42);
|
||||
|
||||
int min;
|
||||
if_then_else(_1 < _2, boost::lambda::var(min) = _1, boost::lambda::var(min) = _2)
|
||||
(make_const(1), make_const(2));
|
||||
BOOST_TEST(min == 1);
|
||||
BOOST_CHECK(min == 1);
|
||||
|
||||
if_then_else(_1 < _2, boost::lambda::var(min) = _1, boost::lambda::var(min) = _2)
|
||||
(make_const(5), make_const(3));
|
||||
BOOST_TEST(min == 3);
|
||||
BOOST_CHECK(min == 3);
|
||||
|
||||
int x, y;
|
||||
x = -1; y = 1;
|
||||
BOOST_TEST(if_then_else_return(_1 < _2, _2, _1)(x, y) == (std::max)(x ,y));
|
||||
BOOST_TEST(if_then_else_return(_1 < _2, _2, _1)(y, x) == (std::max)(x ,y));
|
||||
BOOST_CHECK(if_then_else_return(_1 < _2, _2, _1)(x, y) == (std::max)(x ,y));
|
||||
BOOST_CHECK(if_then_else_return(_1 < _2, _2, _1)(y, x) == (std::max)(x ,y));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// -- exception_test.cpp -- The Boost Lambda Library ------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -29,7 +29,7 @@ using namespace boost::lambda;
|
||||
using namespace std;
|
||||
|
||||
// to prevent unused variables warnings
|
||||
template <class T> void dummy(const T& t) {}
|
||||
template <class T> void dummy(const T&) {}
|
||||
|
||||
void erroneous_exception_related_lambda_expressions() {
|
||||
|
||||
@@ -98,7 +98,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 1);
|
||||
BOOST_CHECK(ecount == 1);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=2; i++)
|
||||
@@ -113,7 +113,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 2);
|
||||
BOOST_CHECK(ecount == 2);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=3; i++)
|
||||
@@ -131,7 +131,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 3);
|
||||
BOOST_CHECK(ecount == 3);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=4; i++)
|
||||
@@ -152,7 +152,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 4);
|
||||
BOOST_CHECK(ecount == 4);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=5; i++)
|
||||
@@ -176,7 +176,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 5);
|
||||
BOOST_CHECK(ecount == 5);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=6; i++)
|
||||
@@ -203,7 +203,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 6);
|
||||
BOOST_CHECK(ecount == 6);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=7; i++)
|
||||
@@ -233,7 +233,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 7);
|
||||
BOOST_CHECK(ecount == 7);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=8; i++)
|
||||
@@ -266,7 +266,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 8);
|
||||
BOOST_CHECK(ecount == 8);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=9; i++)
|
||||
@@ -302,7 +302,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 9);
|
||||
BOOST_CHECK(ecount == 9);
|
||||
|
||||
|
||||
// with catch(...) blocks
|
||||
@@ -317,7 +317,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 1);
|
||||
BOOST_CHECK(ecount == 1);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=2; i++)
|
||||
@@ -332,7 +332,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 2);
|
||||
BOOST_CHECK(ecount == 2);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=3; i++)
|
||||
@@ -350,7 +350,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 3);
|
||||
BOOST_CHECK(ecount == 3);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=4; i++)
|
||||
@@ -371,7 +371,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 4);
|
||||
BOOST_CHECK(ecount == 4);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=5; i++)
|
||||
@@ -395,7 +395,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 5);
|
||||
BOOST_CHECK(ecount == 5);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=6; i++)
|
||||
@@ -422,7 +422,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 6);
|
||||
BOOST_CHECK(ecount == 6);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=7; i++)
|
||||
@@ -452,7 +452,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 7);
|
||||
BOOST_CHECK(ecount == 7);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=8; i++)
|
||||
@@ -485,7 +485,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 8);
|
||||
BOOST_CHECK(ecount == 8);
|
||||
|
||||
ecount = 0;
|
||||
for(int i=1; i<=9; i++)
|
||||
@@ -521,7 +521,7 @@ void test_different_number_of_catch_blocks() {
|
||||
)
|
||||
)(i);
|
||||
}
|
||||
BOOST_TEST(ecount == 9);
|
||||
BOOST_CHECK(ecount == 9);
|
||||
}
|
||||
|
||||
void test_empty_catch_blocks() {
|
||||
@@ -551,7 +551,7 @@ void return_type_matching() {
|
||||
|
||||
int i = 1;
|
||||
|
||||
BOOST_TEST(
|
||||
BOOST_CHECK(
|
||||
|
||||
try_catch(
|
||||
_1 + 1,
|
||||
@@ -575,14 +575,14 @@ void return_type_matching() {
|
||||
make_void(_1 += 1),
|
||||
catch_exception<char>(_e) // since try is void, catch can return anything
|
||||
)(i);
|
||||
BOOST_TEST(i == 2);
|
||||
BOOST_CHECK(i == 2);
|
||||
|
||||
try_catch(
|
||||
(_1 += 1, throw_exception('a')),
|
||||
catch_exception<char>(_e) // since try throws, it is void,
|
||||
// so catch can return anything
|
||||
)(i);
|
||||
BOOST_TEST(i == 3);
|
||||
BOOST_CHECK(i == 3);
|
||||
|
||||
char a = 'a';
|
||||
try_catch(
|
||||
@@ -592,7 +592,7 @@ void return_type_matching() {
|
||||
),
|
||||
catch_exception<char>( _1 = _e )
|
||||
)(a);
|
||||
BOOST_TEST(a == 'b');
|
||||
BOOST_CHECK(a == 'b');
|
||||
}
|
||||
|
||||
int test_main(int, char *[]) {
|
||||
@@ -603,13 +603,13 @@ int test_main(int, char *[]) {
|
||||
return_type_matching();
|
||||
test_empty_catch_blocks();
|
||||
}
|
||||
catch (int x)
|
||||
catch (int)
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
BOOST_CHECK(false);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
BOOST_CHECK(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// extending_return_type_traits.cpp -- The Boost Lambda Library --------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "boost/lambda/bind.hpp"
|
||||
#include "boost/lambda/lambda.hpp"
|
||||
#include "boost/lambda/detail/suppress_unused.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -23,6 +24,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using boost::lambda::detail::suppress_unused_variable_warnings;
|
||||
|
||||
class A {};
|
||||
class B {};
|
||||
|
||||
@@ -81,7 +84,7 @@ struct plain_return_type_1<other_action<contentsof_action>, A> {
|
||||
} // lambda
|
||||
} // boost
|
||||
|
||||
void ok(B b) {}
|
||||
void ok(B /*b*/) {}
|
||||
|
||||
void test_unary_operators()
|
||||
{
|
||||
@@ -96,7 +99,7 @@ void test_unary_operators()
|
||||
ok((&_1)(a));
|
||||
ok((*_1)(a));
|
||||
|
||||
BOOST_TEST((*_1)(make_const(&i)) == 1);
|
||||
BOOST_CHECK((*_1)(make_const(&i)) == 1);
|
||||
}
|
||||
|
||||
class X {};
|
||||
@@ -127,7 +130,7 @@ class my_vector {};
|
||||
|
||||
template<class A, class B>
|
||||
my_vector<typename return_type_2<arithmetic_action<plus_action>, A&, B&>::type>
|
||||
operator+(const my_vector<A>& a, const my_vector<B>& b)
|
||||
operator+(const my_vector<A>& /*a*/, const my_vector<B>& /*b*/)
|
||||
{
|
||||
typedef typename
|
||||
return_type_2<arithmetic_action<plus_action>, A&, B&>::type res_type;
|
||||
@@ -175,8 +178,8 @@ Z operator^=( X&, const Y&) { return Z(); }
|
||||
// assignment
|
||||
class Assign {
|
||||
public:
|
||||
void operator=(const Assign& a) {}
|
||||
X operator[](const int& i) { return X(); }
|
||||
void operator=(const Assign& /*a*/) {}
|
||||
X operator[](const int& /*i*/) { return X(); }
|
||||
};
|
||||
|
||||
|
||||
@@ -329,9 +332,16 @@ void test_binary_operators() {
|
||||
XX dummy3 = (_1 * _2)(vxx, vyy);
|
||||
VV dummy4 = (_1 * _2)(cvxx, cvyy);
|
||||
|
||||
suppress_unused_variable_warnings(dummy1);
|
||||
suppress_unused_variable_warnings(dummy2);
|
||||
suppress_unused_variable_warnings(dummy3);
|
||||
suppress_unused_variable_warnings(dummy4);
|
||||
|
||||
my_vector<int> v1; my_vector<double> v2;
|
||||
my_vector<double> d = (_1 + _2)(v1, v2);
|
||||
|
||||
suppress_unused_variable_warnings(d);
|
||||
|
||||
// bitwise
|
||||
|
||||
(_1 << _2)(x, y);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// is_instance_of_test.cpp -- The Boost Lambda Library ------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -53,25 +53,25 @@ using boost::lambda::is_instance_of_3;
|
||||
using boost::lambda::is_instance_of_4;
|
||||
|
||||
|
||||
BOOST_TEST((is_instance_of_1<B1, A1>::value == true));
|
||||
BOOST_TEST((is_instance_of_1<A1<float>, A1>::value == true));
|
||||
BOOST_TEST((is_instance_of_1<int, A1>::value == false));
|
||||
BOOST_TEST((is_instance_of_1<C1, A1>::value == false));
|
||||
BOOST_CHECK((is_instance_of_1<B1, A1>::value == true));
|
||||
BOOST_CHECK((is_instance_of_1<A1<float>, A1>::value == true));
|
||||
BOOST_CHECK((is_instance_of_1<int, A1>::value == false));
|
||||
BOOST_CHECK((is_instance_of_1<C1, A1>::value == false));
|
||||
|
||||
BOOST_TEST((is_instance_of_2<B2, A2>::value == true));
|
||||
BOOST_TEST((is_instance_of_2<A2<int, float>, A2>::value == true));
|
||||
BOOST_TEST((is_instance_of_2<int, A2>::value == false));
|
||||
BOOST_TEST((is_instance_of_2<C2, A2>::value == false));
|
||||
BOOST_CHECK((is_instance_of_2<B2, A2>::value == true));
|
||||
BOOST_CHECK((is_instance_of_2<A2<int, float>, A2>::value == true));
|
||||
BOOST_CHECK((is_instance_of_2<int, A2>::value == false));
|
||||
BOOST_CHECK((is_instance_of_2<C2, A2>::value == false));
|
||||
|
||||
BOOST_TEST((is_instance_of_3<B3, A3>::value == true));
|
||||
BOOST_TEST((is_instance_of_3<A3<int, float, char>, A3>::value == true));
|
||||
BOOST_TEST((is_instance_of_3<int, A3>::value == false));
|
||||
BOOST_TEST((is_instance_of_3<C3, A3>::value == false));
|
||||
BOOST_CHECK((is_instance_of_3<B3, A3>::value == true));
|
||||
BOOST_CHECK((is_instance_of_3<A3<int, float, char>, A3>::value == true));
|
||||
BOOST_CHECK((is_instance_of_3<int, A3>::value == false));
|
||||
BOOST_CHECK((is_instance_of_3<C3, A3>::value == false));
|
||||
|
||||
BOOST_TEST((is_instance_of_4<B4, A4>::value == true));
|
||||
BOOST_TEST((is_instance_of_4<A4<int, float, char, double>, A4>::value == true));
|
||||
BOOST_TEST((is_instance_of_4<int, A4>::value == false));
|
||||
BOOST_TEST((is_instance_of_4<C4, A4>::value == false));
|
||||
BOOST_CHECK((is_instance_of_4<B4, A4>::value == true));
|
||||
BOOST_CHECK((is_instance_of_4<A4<int, float, char, double>, A4>::value == true));
|
||||
BOOST_CHECK((is_instance_of_4<int, A4>::value == false));
|
||||
BOOST_CHECK((is_instance_of_4<C4, A4>::value == false));
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
30
test/istreambuf_test.cpp
Normal file
30
test/istreambuf_test.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// istreambuf_test - test lambda function objects with istreambuf_iterator
|
||||
//
|
||||
// Copyright (c) 2007 Peter Dimov
|
||||
//
|
||||
// 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
|
||||
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::lambda;
|
||||
|
||||
std::stringstream is( "ax2" );
|
||||
|
||||
std::istreambuf_iterator<char> b2( is );
|
||||
std::istreambuf_iterator<char> e2;
|
||||
|
||||
std::istreambuf_iterator<char> i = std::find_if( b2, e2, _1 == 'x' );
|
||||
|
||||
BOOST_TEST( *i == 'x' );
|
||||
BOOST_TEST( std::distance( i, e2 ) == 2 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// member_pointer_test.cpp -- The Boost Lambda Library ------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -50,65 +50,65 @@ void pointer_to_data_member_tests() {
|
||||
// int i = 0;
|
||||
my_struct *y = &x;
|
||||
|
||||
BOOST_TEST((_1 ->* &my_struct::mem)(y) == 3);
|
||||
BOOST_CHECK((_1 ->* &my_struct::mem)(y) == 3);
|
||||
|
||||
(_1 ->* &my_struct::mem)(y) = 4;
|
||||
BOOST_TEST(x.mem == 4);
|
||||
BOOST_CHECK(x.mem == 4);
|
||||
|
||||
((_1 ->* &my_struct::mem) = 5)(y);
|
||||
BOOST_TEST(x.mem == 5);
|
||||
BOOST_CHECK(x.mem == 5);
|
||||
|
||||
// &my_struct::mem is a temporary, must be constified
|
||||
((y ->* _1) = 6)(make_const(&my_struct::mem));
|
||||
BOOST_TEST(x.mem == 6);
|
||||
BOOST_CHECK(x.mem == 6);
|
||||
|
||||
((_1 ->* _2) = 7)(y, make_const(&my_struct::mem));
|
||||
BOOST_TEST(x.mem == 7);
|
||||
BOOST_CHECK(x.mem == 7);
|
||||
|
||||
}
|
||||
|
||||
void pointer_to_member_function_tests() {
|
||||
|
||||
my_struct *y = new my_struct(1);
|
||||
BOOST_TEST( (_1 ->* &my_struct::foo)(y)() == (y->mem));
|
||||
BOOST_TEST( (_1 ->* &my_struct::fooc)(y)() == (y->mem));
|
||||
BOOST_TEST( (y ->* _1)(make_const(&my_struct::foo))() == (y->mem));
|
||||
BOOST_TEST( (y ->* _1)(make_const(&my_struct::fooc))() == (y->mem));
|
||||
BOOST_TEST( (_1 ->* _2)(y, make_const(&my_struct::foo))() == (y->mem));
|
||||
BOOST_TEST( (_1 ->* _2)(y, make_const(&my_struct::fooc))() == (y->mem));
|
||||
BOOST_CHECK( (_1 ->* &my_struct::foo)(y)() == (y->mem));
|
||||
BOOST_CHECK( (_1 ->* &my_struct::fooc)(y)() == (y->mem));
|
||||
BOOST_CHECK( (y ->* _1)(make_const(&my_struct::foo))() == (y->mem));
|
||||
BOOST_CHECK( (y ->* _1)(make_const(&my_struct::fooc))() == (y->mem));
|
||||
BOOST_CHECK( (_1 ->* _2)(y, make_const(&my_struct::foo))() == (y->mem));
|
||||
BOOST_CHECK( (_1 ->* _2)(y, make_const(&my_struct::fooc))() == (y->mem));
|
||||
|
||||
BOOST_TEST( (_1 ->* &my_struct::foo1)(y)(1) == (y->mem+1));
|
||||
BOOST_TEST( (_1 ->* &my_struct::foo1c)(y)(1) == (y->mem+1));
|
||||
BOOST_TEST( (y ->* _1)(make_const(&my_struct::foo1))(1) == (y->mem+1));
|
||||
BOOST_TEST( (y ->* _1)(make_const(&my_struct::foo1c))(1) == (y->mem+1));
|
||||
BOOST_TEST( (_1 ->* _2)(y, make_const(&my_struct::foo1))(1) == (y->mem+1));
|
||||
BOOST_TEST( (_1 ->* _2)(y, make_const(&my_struct::foo1c))(1) == (y->mem+1));
|
||||
BOOST_CHECK( (_1 ->* &my_struct::foo1)(y)(1) == (y->mem+1));
|
||||
BOOST_CHECK( (_1 ->* &my_struct::foo1c)(y)(1) == (y->mem+1));
|
||||
BOOST_CHECK( (y ->* _1)(make_const(&my_struct::foo1))(1) == (y->mem+1));
|
||||
BOOST_CHECK( (y ->* _1)(make_const(&my_struct::foo1c))(1) == (y->mem+1));
|
||||
BOOST_CHECK( (_1 ->* _2)(y, make_const(&my_struct::foo1))(1) == (y->mem+1));
|
||||
BOOST_CHECK( (_1 ->* _2)(y, make_const(&my_struct::foo1c))(1) == (y->mem+1));
|
||||
|
||||
BOOST_TEST( (_1 ->* &my_struct::foo2)(y)(1,2) == (y->mem+1+2));
|
||||
BOOST_TEST( (_1 ->* &my_struct::foo2c)(y)(1,2) == (y->mem+1+2));
|
||||
BOOST_TEST( (y ->* _1)(make_const(&my_struct::foo2))(1,2) == (y->mem+1+2));
|
||||
BOOST_TEST( (y ->* _1)(make_const(&my_struct::foo2c))(1,2) == (y->mem+1+2));
|
||||
BOOST_TEST( (_1 ->* _2)(y, make_const(&my_struct::foo2))(1,2) == (y->mem+1+2));
|
||||
BOOST_TEST( (_1 ->* _2)(y, make_const(&my_struct::foo2c))(1,2) == (y->mem+1+2));
|
||||
BOOST_CHECK( (_1 ->* &my_struct::foo2)(y)(1,2) == (y->mem+1+2));
|
||||
BOOST_CHECK( (_1 ->* &my_struct::foo2c)(y)(1,2) == (y->mem+1+2));
|
||||
BOOST_CHECK( (y ->* _1)(make_const(&my_struct::foo2))(1,2) == (y->mem+1+2));
|
||||
BOOST_CHECK( (y ->* _1)(make_const(&my_struct::foo2c))(1,2) == (y->mem+1+2));
|
||||
BOOST_CHECK( (_1 ->* _2)(y, make_const(&my_struct::foo2))(1,2) == (y->mem+1+2));
|
||||
BOOST_CHECK( (_1 ->* _2)(y, make_const(&my_struct::foo2c))(1,2) == (y->mem+1+2));
|
||||
|
||||
BOOST_TEST( (_1 ->* &my_struct::foo3)(y)(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_TEST( (_1 ->* &my_struct::foo3c)(y)(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_TEST( (y ->* _1)(make_const(&my_struct::foo3))(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_TEST( (y ->* _1)(make_const(&my_struct::foo3c))(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_TEST( (_1 ->* _2)(y, make_const(&my_struct::foo3))(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_TEST( (_1 ->* _2)(y, make_const(&my_struct::foo3c))(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_CHECK( (_1 ->* &my_struct::foo3)(y)(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_CHECK( (_1 ->* &my_struct::foo3c)(y)(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_CHECK( (y ->* _1)(make_const(&my_struct::foo3))(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_CHECK( (y ->* _1)(make_const(&my_struct::foo3c))(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_CHECK( (_1 ->* _2)(y, make_const(&my_struct::foo3))(1,2,3) == (y->mem+1+2+3));
|
||||
BOOST_CHECK( (_1 ->* _2)(y, make_const(&my_struct::foo3c))(1,2,3) == (y->mem+1+2+3));
|
||||
|
||||
BOOST_TEST( (_1 ->* &my_struct::foo4)(y)(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_TEST( (_1 ->* &my_struct::foo4c)(y)(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_TEST( (y ->* _1)(make_const(&my_struct::foo4))(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_TEST( (y ->* _1)(make_const(&my_struct::foo4c))(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_TEST( (_1 ->* _2)(y, make_const(&my_struct::foo4))(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_TEST( (_1 ->* _2)(y, make_const(&my_struct::foo4c))(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_CHECK( (_1 ->* &my_struct::foo4)(y)(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_CHECK( (_1 ->* &my_struct::foo4c)(y)(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_CHECK( (y ->* _1)(make_const(&my_struct::foo4))(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_CHECK( (y ->* _1)(make_const(&my_struct::foo4c))(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_CHECK( (_1 ->* _2)(y, make_const(&my_struct::foo4))(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
BOOST_CHECK( (_1 ->* _2)(y, make_const(&my_struct::foo4c))(1,2,3,4) == (y->mem+1+2+3+4));
|
||||
|
||||
|
||||
|
||||
// member functions with default values do not work (inherent language issue)
|
||||
// BOOST_TEST( (_1 ->* &my_struct::foo3default)(y)() == (y->mem+1+2+3));
|
||||
// BOOST_CHECK( (_1 ->* &my_struct::foo3default)(y)() == (y->mem+1+2+3));
|
||||
|
||||
}
|
||||
|
||||
@@ -118,11 +118,11 @@ class C {};
|
||||
class D {};
|
||||
|
||||
// ->* can be overloaded to do anything
|
||||
bool operator->*(A a, B b) {
|
||||
bool operator->*(A /*a*/, B /*b*/) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator->*(B b, A a) {
|
||||
bool operator->*(B /*b*/, A /*a*/) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -163,21 +163,21 @@ void test_overloaded_pointer_to_member()
|
||||
A a; B b;
|
||||
|
||||
// this won't work, can't deduce the return type
|
||||
// BOOST_TEST((_1->*_2)(a, b) == false);
|
||||
// BOOST_CHECK((_1->*_2)(a, b) == false);
|
||||
|
||||
// ret<bool> gives the return type
|
||||
BOOST_TEST(ret<bool>(_1->*_2)(a, b) == false);
|
||||
BOOST_TEST(ret<bool>(a->*_1)(b) == false);
|
||||
BOOST_TEST(ret<bool>(_1->*b)(a) == false);
|
||||
BOOST_TEST((ret<bool>((var(a))->*b))() == false);
|
||||
BOOST_TEST((ret<bool>((var(a))->*var(b)))() == false);
|
||||
BOOST_CHECK(ret<bool>(_1->*_2)(a, b) == false);
|
||||
BOOST_CHECK(ret<bool>(a->*_1)(b) == false);
|
||||
BOOST_CHECK(ret<bool>(_1->*b)(a) == false);
|
||||
BOOST_CHECK((ret<bool>((var(a))->*b))() == false);
|
||||
BOOST_CHECK((ret<bool>((var(a))->*var(b)))() == false);
|
||||
|
||||
|
||||
// this is ok without ret<bool> due to the return_type_2 spcialization above
|
||||
BOOST_TEST((_1->*_2)(b, a) == true);
|
||||
BOOST_TEST((b->*_1)(a) == true);
|
||||
BOOST_TEST((_1->*a)(b) == true);
|
||||
BOOST_TEST((var(b)->*a)() == true);
|
||||
BOOST_CHECK((_1->*_2)(b, a) == true);
|
||||
BOOST_CHECK((b->*_1)(a) == true);
|
||||
BOOST_CHECK((_1->*a)(b) == true);
|
||||
BOOST_CHECK((var(b)->*a)() == true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// operator_tests_simple.cpp -- The Boost Lambda Library ---------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -17,6 +17,10 @@
|
||||
|
||||
#include "boost/lambda/lambda.hpp"
|
||||
|
||||
#include "boost/lambda/detail/suppress_unused.hpp"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
@@ -47,7 +51,7 @@ void cout_tests()
|
||||
|
||||
(os << constant("FOO"))();
|
||||
|
||||
BOOST_TEST(os.str() == std::string("10FOO"));
|
||||
BOOST_CHECK(os.str() == std::string("10FOO"));
|
||||
|
||||
|
||||
istringstream is("ABC 1");
|
||||
@@ -57,21 +61,21 @@ void cout_tests()
|
||||
is >> s;
|
||||
is >> k;
|
||||
|
||||
BOOST_TEST(s == std::string("ABC"));
|
||||
BOOST_TEST(k == 1);
|
||||
BOOST_CHECK(s == std::string("ABC"));
|
||||
BOOST_CHECK(k == 1);
|
||||
// test for constant, constant_ref and var
|
||||
i = 5;
|
||||
constant_type<int>::type ci(constant(i));
|
||||
var_type<int>::type vi(var(i));
|
||||
|
||||
(vi = _1)(make_const(100));
|
||||
BOOST_TEST((ci)() == 5);
|
||||
BOOST_TEST(i == 100);
|
||||
BOOST_CHECK((ci)() == 5);
|
||||
BOOST_CHECK(i == 100);
|
||||
|
||||
int a;
|
||||
constant_ref_type<int>::type cr(constant_ref(i));
|
||||
(++vi, var(a) = cr)();
|
||||
BOOST_TEST(i == 101);
|
||||
BOOST_CHECK(i == 101);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -81,115 +85,117 @@ void arithmetic_operators() {
|
||||
using namespace std;
|
||||
using namespace boost::lambda;
|
||||
|
||||
BOOST_TEST((_1 + 1)(i)==2);
|
||||
BOOST_TEST(((_1 + 1) * _2)(i, j)==4);
|
||||
BOOST_TEST((_1 - 1)(i)==0);
|
||||
BOOST_CHECK((_1 + 1)(i)==2);
|
||||
BOOST_CHECK(((_1 + 1) * _2)(i, j)==4);
|
||||
BOOST_CHECK((_1 - 1)(i)==0);
|
||||
|
||||
BOOST_TEST((_1 * 2)(j)==4);
|
||||
BOOST_TEST((_1 / 2)(j)==1);
|
||||
BOOST_CHECK((_1 * 2)(j)==4);
|
||||
BOOST_CHECK((_1 / 2)(j)==1);
|
||||
|
||||
BOOST_TEST((_1 % 2)(k)==1);
|
||||
BOOST_CHECK((_1 % 2)(k)==1);
|
||||
|
||||
BOOST_TEST((-_1)(i) == -1);
|
||||
BOOST_TEST((+_1)(i) == 1);
|
||||
BOOST_CHECK((-_1)(i) == -1);
|
||||
BOOST_CHECK((+_1)(i) == 1);
|
||||
|
||||
// test that unary plus really does something
|
||||
unary_plus_tester u;
|
||||
unary_plus_tester up = (+_1)(u);
|
||||
|
||||
boost::lambda::detail::suppress_unused_variable_warnings(up);
|
||||
}
|
||||
|
||||
void bitwise_operators() {
|
||||
unsigned int ui = 2;
|
||||
|
||||
BOOST_TEST((_1 << 1)(ui)==(2 << 1));
|
||||
BOOST_TEST((_1 >> 1)(ui)==(2 >> 1));
|
||||
BOOST_CHECK((_1 << 1)(ui)==(2 << 1));
|
||||
BOOST_CHECK((_1 >> 1)(ui)==(2 >> 1));
|
||||
|
||||
BOOST_TEST((_1 & 1)(ui)==(2 & 1));
|
||||
BOOST_TEST((_1 | 1)(ui)==(2 | 1));
|
||||
BOOST_TEST((_1 ^ 1)(ui)==(2 ^ 1));
|
||||
BOOST_TEST((~_1)(ui)==~2u);
|
||||
BOOST_CHECK((_1 & 1)(ui)==(2 & 1));
|
||||
BOOST_CHECK((_1 | 1)(ui)==(2 | 1));
|
||||
BOOST_CHECK((_1 ^ 1)(ui)==(2 ^ 1));
|
||||
BOOST_CHECK((~_1)(ui)==~2u);
|
||||
}
|
||||
|
||||
void comparison_operators() {
|
||||
int i = 0, j = 1;
|
||||
|
||||
BOOST_TEST((_1 < _2)(i, j) == true);
|
||||
BOOST_TEST((_1 <= _2)(i, j) == true);
|
||||
BOOST_TEST((_1 == _2)(i, j) == false);
|
||||
BOOST_TEST((_1 != _2)(i, j) == true);
|
||||
BOOST_TEST((_1 > _2)(i, j) == false);
|
||||
BOOST_TEST((_1 >= _2)(i, j) == false);
|
||||
BOOST_CHECK((_1 < _2)(i, j) == true);
|
||||
BOOST_CHECK((_1 <= _2)(i, j) == true);
|
||||
BOOST_CHECK((_1 == _2)(i, j) == false);
|
||||
BOOST_CHECK((_1 != _2)(i, j) == true);
|
||||
BOOST_CHECK((_1 > _2)(i, j) == false);
|
||||
BOOST_CHECK((_1 >= _2)(i, j) == false);
|
||||
|
||||
BOOST_TEST((!(_1 < _2))(i, j) == false);
|
||||
BOOST_TEST((!(_1 <= _2))(i, j) == false);
|
||||
BOOST_TEST((!(_1 == _2))(i, j) == true);
|
||||
BOOST_TEST((!(_1 != _2))(i, j) == false);
|
||||
BOOST_TEST((!(_1 > _2))(i, j) == true);
|
||||
BOOST_TEST((!(_1 >= _2))(i, j) == true);
|
||||
BOOST_CHECK((!(_1 < _2))(i, j) == false);
|
||||
BOOST_CHECK((!(_1 <= _2))(i, j) == false);
|
||||
BOOST_CHECK((!(_1 == _2))(i, j) == true);
|
||||
BOOST_CHECK((!(_1 != _2))(i, j) == false);
|
||||
BOOST_CHECK((!(_1 > _2))(i, j) == true);
|
||||
BOOST_CHECK((!(_1 >= _2))(i, j) == true);
|
||||
}
|
||||
|
||||
void logical_operators() {
|
||||
|
||||
bool t = true, f = false;
|
||||
BOOST_TEST((_1 && _2)(t, t) == true);
|
||||
BOOST_TEST((_1 && _2)(t, f) == false);
|
||||
BOOST_TEST((_1 && _2)(f, t) == false);
|
||||
BOOST_TEST((_1 && _2)(f, f) == false);
|
||||
BOOST_CHECK((_1 && _2)(t, t) == true);
|
||||
BOOST_CHECK((_1 && _2)(t, f) == false);
|
||||
BOOST_CHECK((_1 && _2)(f, t) == false);
|
||||
BOOST_CHECK((_1 && _2)(f, f) == false);
|
||||
|
||||
BOOST_TEST((_1 || _2)(t, t) == true);
|
||||
BOOST_TEST((_1 || _2)(t, f) == true);
|
||||
BOOST_TEST((_1 || _2)(f, t) == true);
|
||||
BOOST_TEST((_1 || _2)(f, f) == false);
|
||||
BOOST_CHECK((_1 || _2)(t, t) == true);
|
||||
BOOST_CHECK((_1 || _2)(t, f) == true);
|
||||
BOOST_CHECK((_1 || _2)(f, t) == true);
|
||||
BOOST_CHECK((_1 || _2)(f, f) == false);
|
||||
|
||||
BOOST_TEST((!_1)(t) == false);
|
||||
BOOST_TEST((!_1)(f) == true);
|
||||
BOOST_CHECK((!_1)(t) == false);
|
||||
BOOST_CHECK((!_1)(f) == true);
|
||||
|
||||
// test short circuiting
|
||||
int i=0;
|
||||
|
||||
(false && ++_1)(i);
|
||||
BOOST_TEST(i==0);
|
||||
BOOST_CHECK(i==0);
|
||||
i = 0;
|
||||
|
||||
(true && ++_1)(i);
|
||||
BOOST_TEST(i==1);
|
||||
BOOST_CHECK(i==1);
|
||||
i = 0;
|
||||
|
||||
(false || ++_1)(i);
|
||||
BOOST_TEST(i==1);
|
||||
BOOST_CHECK(i==1);
|
||||
i = 0;
|
||||
|
||||
(true || ++_1)(i);
|
||||
BOOST_TEST(i==0);
|
||||
BOOST_CHECK(i==0);
|
||||
i = 0;
|
||||
}
|
||||
|
||||
void unary_incs_and_decs() {
|
||||
int i = 0;
|
||||
|
||||
BOOST_TEST(_1++(i) == 0);
|
||||
BOOST_TEST(i == 1);
|
||||
BOOST_CHECK(_1++(i) == 0);
|
||||
BOOST_CHECK(i == 1);
|
||||
i = 0;
|
||||
|
||||
BOOST_TEST(_1--(i) == 0);
|
||||
BOOST_TEST(i == -1);
|
||||
BOOST_CHECK(_1--(i) == 0);
|
||||
BOOST_CHECK(i == -1);
|
||||
i = 0;
|
||||
|
||||
BOOST_TEST((++_1)(i) == 1);
|
||||
BOOST_TEST(i == 1);
|
||||
BOOST_CHECK((++_1)(i) == 1);
|
||||
BOOST_CHECK(i == 1);
|
||||
i = 0;
|
||||
|
||||
BOOST_TEST((--_1)(i) == -1);
|
||||
BOOST_TEST(i == -1);
|
||||
BOOST_CHECK((--_1)(i) == -1);
|
||||
BOOST_CHECK(i == -1);
|
||||
i = 0;
|
||||
|
||||
// the result of prefix -- and ++ are lvalues
|
||||
(++_1)(i) = 10;
|
||||
BOOST_TEST(i==10);
|
||||
BOOST_CHECK(i==10);
|
||||
i = 0;
|
||||
|
||||
(--_1)(i) = 10;
|
||||
BOOST_TEST(i==10);
|
||||
BOOST_CHECK(i==10);
|
||||
i = 0;
|
||||
}
|
||||
|
||||
@@ -199,77 +205,93 @@ void compound_operators() {
|
||||
|
||||
// normal variable as the left operand
|
||||
(i += _1)(make_const(1));
|
||||
BOOST_TEST(i == 2);
|
||||
BOOST_CHECK(i == 2);
|
||||
|
||||
(i -= _1)(make_const(1));
|
||||
BOOST_TEST(i == 1);
|
||||
BOOST_CHECK(i == 1);
|
||||
|
||||
(i *= _1)(make_const(10));
|
||||
BOOST_TEST(i == 10);
|
||||
BOOST_CHECK(i == 10);
|
||||
|
||||
(i /= _1)(make_const(2));
|
||||
BOOST_TEST(i == 5);
|
||||
BOOST_CHECK(i == 5);
|
||||
|
||||
(i %= _1)(make_const(2));
|
||||
BOOST_TEST(i == 1);
|
||||
BOOST_CHECK(i == 1);
|
||||
|
||||
// lambda expression as a left operand
|
||||
(_1 += 1)(i);
|
||||
BOOST_TEST(i == 2);
|
||||
BOOST_CHECK(i == 2);
|
||||
|
||||
(_1 -= 1)(i);
|
||||
BOOST_TEST(i == 1);
|
||||
BOOST_CHECK(i == 1);
|
||||
|
||||
(_1 *= 10)(i);
|
||||
BOOST_TEST(i == 10);
|
||||
BOOST_CHECK(i == 10);
|
||||
|
||||
(_1 /= 2)(i);
|
||||
BOOST_TEST(i == 5);
|
||||
BOOST_CHECK(i == 5);
|
||||
|
||||
(_1 %= 2)(i);
|
||||
BOOST_TEST(i == 1);
|
||||
BOOST_CHECK(i == 1);
|
||||
|
||||
// lambda expression as a left operand with rvalue on RHS
|
||||
(_1 += (0 + 1))(i);
|
||||
BOOST_CHECK(i == 2);
|
||||
|
||||
(_1 -= (0 + 1))(i);
|
||||
BOOST_CHECK(i == 1);
|
||||
|
||||
(_1 *= (0 + 10))(i);
|
||||
BOOST_CHECK(i == 10);
|
||||
|
||||
(_1 /= (0 + 2))(i);
|
||||
BOOST_CHECK(i == 5);
|
||||
|
||||
(_1 %= (0 + 2))(i);
|
||||
BOOST_CHECK(i == 1);
|
||||
|
||||
// shifts
|
||||
unsigned int ui = 2;
|
||||
(_1 <<= 1)(ui);
|
||||
BOOST_TEST(ui==(2 << 1));
|
||||
BOOST_CHECK(ui==(2 << 1));
|
||||
|
||||
ui = 2;
|
||||
(_1 >>= 1)(ui);
|
||||
BOOST_TEST(ui==(2 >> 1));
|
||||
BOOST_CHECK(ui==(2 >> 1));
|
||||
|
||||
ui = 2;
|
||||
(ui <<= _1)(make_const(1));
|
||||
BOOST_TEST(ui==(2 << 1));
|
||||
BOOST_CHECK(ui==(2 << 1));
|
||||
|
||||
ui = 2;
|
||||
(ui >>= _1)(make_const(1));
|
||||
BOOST_TEST(ui==(2 >> 1));
|
||||
BOOST_CHECK(ui==(2 >> 1));
|
||||
|
||||
// and, or, xor
|
||||
ui = 2;
|
||||
(_1 &= 1)(ui);
|
||||
BOOST_TEST(ui==(2 & 1));
|
||||
BOOST_CHECK(ui==(2 & 1));
|
||||
|
||||
ui = 2;
|
||||
(_1 |= 1)(ui);
|
||||
BOOST_TEST(ui==(2 | 1));
|
||||
BOOST_CHECK(ui==(2 | 1));
|
||||
|
||||
ui = 2;
|
||||
(_1 ^= 1)(ui);
|
||||
BOOST_TEST(ui==(2 ^ 1));
|
||||
BOOST_CHECK(ui==(2 ^ 1));
|
||||
|
||||
ui = 2;
|
||||
(ui &= _1)(make_const(1));
|
||||
BOOST_TEST(ui==(2 & 1));
|
||||
BOOST_CHECK(ui==(2 & 1));
|
||||
|
||||
ui = 2;
|
||||
(ui |= _1)(make_const(1));
|
||||
BOOST_TEST(ui==(2 | 1));
|
||||
BOOST_CHECK(ui==(2 | 1));
|
||||
|
||||
ui = 2;
|
||||
(ui ^= _1)(make_const(1));
|
||||
BOOST_TEST(ui==(2 ^ 1));
|
||||
BOOST_CHECK(ui==(2 ^ 1));
|
||||
|
||||
}
|
||||
|
||||
@@ -283,24 +305,24 @@ void assignment_and_subscript() {
|
||||
string s;
|
||||
|
||||
(_1 = "one")(s);
|
||||
BOOST_TEST(s == string("one"));
|
||||
BOOST_CHECK(s == string("one"));
|
||||
|
||||
(var(s) = "two")();
|
||||
BOOST_TEST(s == string("two"));
|
||||
BOOST_CHECK(s == string("two"));
|
||||
|
||||
BOOST_TEST((var(s)[_1])(make_const(2)) == 'o');
|
||||
BOOST_TEST((_1[2])(s) == 'o');
|
||||
BOOST_TEST((_1[_2])(s, make_const(2)) == 'o');
|
||||
BOOST_CHECK((var(s)[_1])(make_const(2)) == 'o');
|
||||
BOOST_CHECK((_1[2])(s) == 'o');
|
||||
BOOST_CHECK((_1[_2])(s, make_const(2)) == 'o');
|
||||
|
||||
// subscript returns lvalue
|
||||
(var(s)[_1])(make_const(1)) = 'o';
|
||||
BOOST_TEST(s == "too");
|
||||
BOOST_CHECK(s == "too");
|
||||
|
||||
(_1[1])(s) = 'a';
|
||||
BOOST_TEST(s == "tao");
|
||||
BOOST_CHECK(s == "tao");
|
||||
|
||||
(_1[_2])(s, make_const(0)) = 'm';
|
||||
BOOST_TEST(s == "mao");
|
||||
BOOST_CHECK(s == "mao");
|
||||
|
||||
// TODO: tests for vector, set, map, multimap
|
||||
}
|
||||
@@ -311,16 +333,26 @@ void address_of_and_dereference() {
|
||||
|
||||
A a; int i = 42;
|
||||
|
||||
BOOST_TEST((&_1)(a) == &a);
|
||||
BOOST_TEST((*&_1)(i) == 42);
|
||||
BOOST_CHECK((&_1)(a) == &a);
|
||||
BOOST_CHECK((*&_1)(i) == 42);
|
||||
|
||||
std::vector<int> vi; vi.push_back(1);
|
||||
std::vector<int>::iterator it = vi.begin();
|
||||
|
||||
(*_1 = 7)(it);
|
||||
BOOST_TEST(vi[0] == 7);
|
||||
BOOST_CHECK(vi[0] == 7);
|
||||
const std::vector<int>::iterator cit(it);
|
||||
(*_1 = 8)(cit);
|
||||
BOOST_CHECK(vi[0] == 8);
|
||||
|
||||
// TODO: Add tests for more complex iterator types
|
||||
|
||||
boost::shared_ptr<int> ptr(new int(0));
|
||||
(*_1 = 7)(ptr);
|
||||
BOOST_CHECK(*ptr == 7);
|
||||
const boost::shared_ptr<int> cptr(ptr);
|
||||
(*_1 = 8)(cptr);
|
||||
BOOST_CHECK(*ptr == 8);
|
||||
}
|
||||
|
||||
|
||||
@@ -328,7 +360,7 @@ void address_of_and_dereference() {
|
||||
void comma() {
|
||||
|
||||
int i = 100;
|
||||
BOOST_TEST((_1 = 10, 2 * _1)(i) == 20);
|
||||
BOOST_CHECK((_1 = 10, 2 * _1)(i) == 20);
|
||||
|
||||
// TODO: that the return type is the exact type of the right argument
|
||||
// (that r/l valueness is preserved)
|
||||
@@ -347,32 +379,32 @@ void pointer_arithmetic() {
|
||||
|
||||
|
||||
// non-const array
|
||||
BOOST_TEST((*(_1 + 1))(ia) == 2);
|
||||
BOOST_CHECK((*(_1 + 1))(ia) == 2);
|
||||
|
||||
// non-const pointer
|
||||
BOOST_TEST((*(_1 + 1))(ip) == 2);
|
||||
BOOST_CHECK((*(_1 + 1))(ip) == 2);
|
||||
|
||||
BOOST_TEST((*(_1 - 1))(ia_last) == 3);
|
||||
BOOST_CHECK((*(_1 - 1))(ia_last) == 3);
|
||||
|
||||
// const array
|
||||
BOOST_TEST((*(_1 + 1))(cia) == 2);
|
||||
BOOST_CHECK((*(_1 + 1))(cia) == 2);
|
||||
// const pointer
|
||||
BOOST_TEST((*(_1 + 1))(cip) == 2);
|
||||
BOOST_TEST((*(_1 - 1))(cia_last) == 3);
|
||||
BOOST_CHECK((*(_1 + 1))(cip) == 2);
|
||||
BOOST_CHECK((*(_1 - 1))(cia_last) == 3);
|
||||
|
||||
// pointer arithmetic should not make non-consts const
|
||||
(*(_1 + 2))(ia) = 0;
|
||||
(*(_1 + 3))(ip) = 0;
|
||||
|
||||
BOOST_TEST(ia[2] == 0);
|
||||
BOOST_TEST(ia[3] == 0);
|
||||
BOOST_CHECK(ia[2] == 0);
|
||||
BOOST_CHECK(ia[3] == 0);
|
||||
|
||||
// pointer - pointer
|
||||
BOOST_TEST((_1 - _2)(ia_last, ia) == 3);
|
||||
BOOST_TEST((_1 - _2)(cia_last, cia) == 3);
|
||||
BOOST_TEST((ia_last - _1)(ia) == 3);
|
||||
BOOST_TEST((cia_last - _1)(cia) == 3);
|
||||
BOOST_TEST((cia_last - _1)(cip) == 3);
|
||||
BOOST_CHECK((_1 - _2)(ia_last, ia) == 3);
|
||||
BOOST_CHECK((_1 - _2)(cia_last, cia) == 3);
|
||||
BOOST_CHECK((ia_last - _1)(ia) == 3);
|
||||
BOOST_CHECK((cia_last - _1)(cia) == 3);
|
||||
BOOST_CHECK((cia_last - _1)(cip) == 3);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// phoenix_style_control_structures.cpp -- The Boost Lambda Library ------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -60,7 +60,7 @@ int test_main(int, char *[]) {
|
||||
]
|
||||
);
|
||||
|
||||
BOOST_TEST(sum == 4+5+6+7+8);
|
||||
BOOST_CHECK(sum == 4+5+6+7+8);
|
||||
|
||||
int gt = 0, eq = 0, lt = 0;
|
||||
//////////////////////////////////
|
||||
@@ -82,9 +82,9 @@ int test_main(int, char *[]) {
|
||||
]
|
||||
);
|
||||
|
||||
BOOST_TEST(lt==4);
|
||||
BOOST_TEST(eq==1);
|
||||
BOOST_TEST(gt==5);
|
||||
BOOST_CHECK(lt==4);
|
||||
BOOST_CHECK(eq==1);
|
||||
BOOST_CHECK(gt==5);
|
||||
|
||||
vector<int> t = v;
|
||||
|
||||
@@ -101,8 +101,8 @@ int test_main(int, char *[]) {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(counta == 55);
|
||||
BOOST_TEST(countb == 10);
|
||||
BOOST_CHECK(counta == 55);
|
||||
BOOST_CHECK(countb == 10);
|
||||
|
||||
|
||||
v = t;
|
||||
@@ -120,8 +120,8 @@ int test_main(int, char *[]) {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(counta == (2+11)*10/2);
|
||||
BOOST_TEST(countb == 10);
|
||||
BOOST_CHECK(counta == (2+11)*10/2);
|
||||
BOOST_CHECK(countb == 10);
|
||||
|
||||
|
||||
v = t;
|
||||
@@ -138,8 +138,8 @@ int test_main(int, char *[]) {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(counta == (1+10)*10/2);
|
||||
BOOST_TEST(countb == 10);
|
||||
BOOST_CHECK(counta == (1+10)*10/2);
|
||||
BOOST_CHECK(countb == 10);
|
||||
|
||||
v = t;
|
||||
|
||||
|
||||
314
test/result_of_tests.cpp
Normal file
314
test/result_of_tests.cpp
Normal file
@@ -0,0 +1,314 @@
|
||||
// result_of_tests.cpp -- The Boost Lambda Library ------------------
|
||||
//
|
||||
// Copyright (C) 2010 Steven Watanabe
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// For more information, see www.boost.org
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <boost/test/minimal.hpp> // see "Header Implementation Option"
|
||||
#include <boost/lambda/bind.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
struct with_result_type {
|
||||
typedef int result_type;
|
||||
int operator()() const { return 0; }
|
||||
int operator()(int) const { return 1; }
|
||||
int operator()(int, int) const { return 2; }
|
||||
int operator()(int, int, int) const { return 3; }
|
||||
int operator()(int, int, int, int) const { return 4; }
|
||||
int operator()(int, int, int, int, int) const { return 5; }
|
||||
int operator()(int, int, int, int, int, int) const { return 6; }
|
||||
int operator()(int, int, int, int, int, int, int) const { return 7; }
|
||||
int operator()(int, int, int, int, int, int, int, int) const { return 8; }
|
||||
int operator()(int, int, int, int, int, int, int, int, int) const { return 9; }
|
||||
};
|
||||
|
||||
struct with_result_template_value {
|
||||
template<class Sig>
|
||||
struct result;
|
||||
template<class This>
|
||||
struct result<This()> {
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1>
|
||||
struct result<This(A1)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2>
|
||||
struct result<This(A1, A2)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3>
|
||||
struct result<This(A1, A2, A3)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4>
|
||||
struct result<This(A1, A2, A3, A4)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4, class A5>
|
||||
struct result<This(A1, A2, A3, A4, A5)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A5, int>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
struct result<This(A1, A2, A3, A4, A5, A6)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A5, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A6, int>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
|
||||
struct result<This(A1, A2, A3, A4, A5, A6, A7)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A5, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A6, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A7, int>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
|
||||
struct result<This(A1, A2, A3, A4, A5, A6, A7, A8)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A5, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A6, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A7, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A8, int>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
|
||||
struct result<This(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A5, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A6, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A7, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A8, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A9, int>));
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
int operator()() const { return 0; }
|
||||
int operator()(int) const { return 1; }
|
||||
int operator()(int, int) const { return 2; }
|
||||
int operator()(int, int, int) const { return 3; }
|
||||
int operator()(int, int, int, int) const { return 4; }
|
||||
int operator()(int, int, int, int, int) const { return 5; }
|
||||
int operator()(int, int, int, int, int, int) const { return 6; }
|
||||
int operator()(int, int, int, int, int, int, int) const { return 7; }
|
||||
int operator()(int, int, int, int, int, int, int, int) const { return 8; }
|
||||
int operator()(int, int, int, int, int, int, int, int, int) const { return 9; }
|
||||
};
|
||||
|
||||
struct with_result_template_reference {
|
||||
template<class Sig>
|
||||
struct result;
|
||||
template<class This>
|
||||
struct result<This()> {
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1>
|
||||
struct result<This(A1)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int&>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2>
|
||||
struct result<This(A1, A2)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int&>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3>
|
||||
struct result<This(A1, A2, A3)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int&>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4>
|
||||
struct result<This(A1, A2, A3, A4)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int&>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4, class A5>
|
||||
struct result<This(A1, A2, A3, A4, A5)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A5, int&>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
struct result<This(A1, A2, A3, A4, A5, A6)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A5, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A6, int&>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
|
||||
struct result<This(A1, A2, A3, A4, A5, A6, A7)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A5, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A6, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A7, int&>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
|
||||
struct result<This(A1, A2, A3, A4, A5, A6, A7, A8)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A5, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A6, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A7, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A8, int&>));
|
||||
typedef int type;
|
||||
};
|
||||
template<class This, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
|
||||
struct result<This(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
|
||||
BOOST_MPL_ASSERT((boost::is_same<A1, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A2, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A3, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A4, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A5, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A6, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A7, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A8, int&>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<A9, int&>));
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
int operator()() const { return 0; }
|
||||
int operator()(int) const { return 1; }
|
||||
int operator()(int, int) const { return 2; }
|
||||
int operator()(int, int, int) const { return 3; }
|
||||
int operator()(int, int, int, int) const { return 4; }
|
||||
int operator()(int, int, int, int, int) const { return 5; }
|
||||
int operator()(int, int, int, int, int, int) const { return 6; }
|
||||
int operator()(int, int, int, int, int, int, int) const { return 7; }
|
||||
int operator()(int, int, int, int, int, int, int, int) const { return 8; }
|
||||
int operator()(int, int, int, int, int, int, int, int, int) const { return 9; }
|
||||
};
|
||||
|
||||
template<class F>
|
||||
typename boost::result_of<F()>::type apply0(F f) {
|
||||
return f();
|
||||
}
|
||||
template<class A, class F>
|
||||
typename boost::result_of<F(A)>::type apply1(F f, A a) {
|
||||
return f(a);
|
||||
}
|
||||
template<class A, class B, class F>
|
||||
typename boost::result_of<F(A, B)>::type apply2(F f, A a, B b) {
|
||||
return f(a, b);
|
||||
}
|
||||
template<class A, class B, class C, class F>
|
||||
typename boost::result_of<F(A, B, C)>::type apply3(F f, A a, B b, C c) {
|
||||
return f(a, b, c);
|
||||
}
|
||||
|
||||
using namespace boost::lambda;
|
||||
|
||||
int test_main(int, char *[]) {
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_type())() == 0);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_type(), 1)() == 1);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_type(), 1, 2)() == 2);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_type(), 1, 2, 3)() == 3);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_type(), 1, 2, 3, 4)() == 4);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_type(), 1, 2, 3, 4, 5)() == 5);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_type(), 1, 2, 3, 4, 5, 6)() == 6);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_type(), 1, 2, 3, 4, 5, 6, 7)() == 7);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_type(), 1, 2, 3, 4, 5, 6, 7, 8)() == 8);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_type(), 1, 2, 3, 4, 5, 6, 7, 8, 9)() == 9);
|
||||
|
||||
// Nullary result_of fails
|
||||
//BOOST_CHECK(boost::lambda::bind(with_result_template_value())() == 0);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_value(), 1)() == 1);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_value(), 1, 2)() == 2);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_value(), 1, 2, 3)() == 3);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4)() == 4);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4, 5)() == 5);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4, 5, 6)() == 6);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4, 5, 6, 7)() == 7);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4, 5, 6, 7, 8)() == 8);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4, 5, 6, 7, 8, 9)() == 9);
|
||||
|
||||
int one = 1,
|
||||
two = 2,
|
||||
three = 3,
|
||||
four = 4,
|
||||
five = 5,
|
||||
six = 6,
|
||||
seven = 7,
|
||||
eight = 8,
|
||||
nine = 9;
|
||||
|
||||
// Nullary result_of fails
|
||||
//BOOST_CHECK(boost::lambda::bind(with_result_template_reference())() == 0);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_reference(), var(one))() == 1);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_reference(), var(one), var(two))() == 2);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three))() == 3);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three), var(four))() == 4);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three), var(four), var(five))() == 5);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three), var(four), var(five), var(six))() == 6);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three), var(four), var(five), var(six), var(seven))() == 7);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three), var(four), var(five), var(six), var(seven), var(eight))() == 8);
|
||||
BOOST_CHECK(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three), var(four), var(five), var(six), var(seven), var(eight), var(nine))() == 9);
|
||||
|
||||
// Check using result_of with lambda functors
|
||||
//BOOST_CHECK(apply0(constant(0)) == 0);
|
||||
BOOST_CHECK(apply1<int>(_1, one) == 1);
|
||||
BOOST_CHECK(apply1<int&>(_1, one) == 1);
|
||||
BOOST_CHECK(apply1<const int&>(_1, one) == 1);
|
||||
BOOST_CHECK((apply2<int, int>(_1 + _2, one, two) == 3));
|
||||
BOOST_CHECK((apply2<int&, int&>(_1 + _2, one, two) == 3));
|
||||
BOOST_CHECK((apply2<const int&, const int&>(_1 + _2, one, two) == 3));
|
||||
BOOST_CHECK((apply3<int, int, int>(_1 + _2 + _3, one, two, three) == 6));
|
||||
BOOST_CHECK((apply3<int&, int&, int&>(_1 + _2 + _3, one, two, three) == 6));
|
||||
BOOST_CHECK((apply3<const int&, const int&, const int&>(_1 + _2 + _3, one, two, three) == 6));
|
||||
|
||||
return 0;
|
||||
}
|
||||
53
test/ret_test.cpp
Normal file
53
test/ret_test.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// ret_test.cpp - The Boost Lambda Library -----------------------
|
||||
//
|
||||
// Copyright (C) 2009 Steven Watanabe
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// For more information, see www.boost.org
|
||||
|
||||
#include <boost/test/minimal.hpp>
|
||||
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
template<class R, class F>
|
||||
void test_ret(R r, F f) {
|
||||
typename F::result_type x = f();
|
||||
BOOST_MPL_ASSERT((boost::is_same<R, typename F::result_type>));
|
||||
BOOST_CHECK(x == r);
|
||||
}
|
||||
|
||||
template<class R, class F, class T1>
|
||||
void test_ret(R r, F f, T1& t1) {
|
||||
typename F::result_type x = f(t1);
|
||||
BOOST_MPL_ASSERT((boost::is_same<R, typename F::result_type>));
|
||||
BOOST_CHECK(x == r);
|
||||
}
|
||||
|
||||
class add_result {
|
||||
public:
|
||||
add_result(int i = 0) : value(i) {}
|
||||
friend bool operator==(const add_result& lhs, const add_result& rhs) {
|
||||
return(lhs.value == rhs.value);
|
||||
}
|
||||
private:
|
||||
int value;
|
||||
};
|
||||
|
||||
class addable {};
|
||||
add_result operator+(addable, addable) {
|
||||
return add_result(7);
|
||||
}
|
||||
|
||||
int test_main(int, char*[]) {
|
||||
addable test;
|
||||
test_ret(add_result(7), boost::lambda::ret<add_result>(boost::lambda::_1 + test), test);
|
||||
test_ret(8.0, boost::lambda::ret<double>(boost::lambda::constant(7) + 1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
57
test/rvalue_test.cpp
Normal file
57
test/rvalue_test.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// rvalue_test - test lambda function objects with rvalue arguments
|
||||
//
|
||||
// Copyright (c) 2007 Peter Dimov
|
||||
//
|
||||
// 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
|
||||
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::lambda;
|
||||
|
||||
int x = 0;
|
||||
int const y = 1;
|
||||
int const z = 2;
|
||||
|
||||
BOOST_TEST( _1( x ) == 0 );
|
||||
BOOST_TEST( _1( y ) == 1 );
|
||||
BOOST_TEST( _1( 2 ) == 2 );
|
||||
|
||||
BOOST_TEST( _2( x, x ) == 0 );
|
||||
BOOST_TEST( _2( x, y ) == 1 );
|
||||
BOOST_TEST( _2( x, 2 ) == 2 );
|
||||
|
||||
BOOST_TEST( _2( 4, x ) == 0 );
|
||||
BOOST_TEST( _2( 4, y ) == 1 );
|
||||
BOOST_TEST( _2( 4, 2 ) == 2 );
|
||||
|
||||
(_1 = _2)( x, y );
|
||||
BOOST_TEST( x == y );
|
||||
|
||||
(_1 = _2)( x, 3 );
|
||||
BOOST_TEST( x == 3 );
|
||||
|
||||
(_2 = _1)( z, x );
|
||||
BOOST_TEST( x == z );
|
||||
|
||||
(_2 = _1)( 4, x );
|
||||
BOOST_TEST( x == 4 );
|
||||
|
||||
BOOST_TEST( _3( x, x, x ) == x );
|
||||
BOOST_TEST( _3( x, x, y ) == y );
|
||||
BOOST_TEST( _3( x, x, 2 ) == 2 );
|
||||
|
||||
BOOST_TEST( _3( x, 5, x ) == x );
|
||||
BOOST_TEST( _3( x, 5, y ) == y );
|
||||
BOOST_TEST( _3( x, 5, 2 ) == 2 );
|
||||
|
||||
BOOST_TEST( _3( 9, 5, x ) == x );
|
||||
BOOST_TEST( _3( 9, 5, y ) == y );
|
||||
BOOST_TEST( _3( 9, 5, 2 ) == 2 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// switch_test.cpp -- The Boost Lambda Library --------------------------
|
||||
//
|
||||
// Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
@@ -63,7 +63,7 @@ void do_switch_no_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 0));
|
||||
BOOST_CHECK(check(w, 0));
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -75,7 +75,7 @@ void do_switch_no_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 1));
|
||||
BOOST_CHECK(check(w, 1));
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -88,7 +88,7 @@ void do_switch_no_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 2));
|
||||
BOOST_CHECK(check(w, 2));
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -102,7 +102,7 @@ void do_switch_no_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 3));
|
||||
BOOST_CHECK(check(w, 3));
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -117,7 +117,7 @@ void do_switch_no_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 4));
|
||||
BOOST_CHECK(check(w, 4));
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -133,7 +133,7 @@ void do_switch_no_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 5));
|
||||
BOOST_CHECK(check(w, 5));
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -150,7 +150,7 @@ void do_switch_no_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 6));
|
||||
BOOST_CHECK(check(w, 6));
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -168,7 +168,7 @@ void do_switch_no_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 7));
|
||||
BOOST_CHECK(check(w, 7));
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -187,7 +187,7 @@ void do_switch_no_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 8));
|
||||
BOOST_CHECK(check(w, 8));
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
}
|
||||
@@ -216,8 +216,8 @@ void do_switch_yes_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, -1));
|
||||
BOOST_TEST(default_count == 10);
|
||||
BOOST_CHECK(check(w, -1));
|
||||
BOOST_CHECK(default_count == 10);
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -230,8 +230,8 @@ void do_switch_yes_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 0));
|
||||
BOOST_TEST(default_count == 9);
|
||||
BOOST_CHECK(check(w, 0));
|
||||
BOOST_CHECK(default_count == 9);
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -245,8 +245,8 @@ void do_switch_yes_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 1));
|
||||
BOOST_TEST(default_count == 8);
|
||||
BOOST_CHECK(check(w, 1));
|
||||
BOOST_CHECK(default_count == 8);
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -261,8 +261,8 @@ void do_switch_yes_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 2));
|
||||
BOOST_TEST(default_count == 7);
|
||||
BOOST_CHECK(check(w, 2));
|
||||
BOOST_CHECK(default_count == 7);
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -278,8 +278,8 @@ void do_switch_yes_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 3));
|
||||
BOOST_TEST(default_count == 6);
|
||||
BOOST_CHECK(check(w, 3));
|
||||
BOOST_CHECK(default_count == 6);
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -296,8 +296,8 @@ void do_switch_yes_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 4));
|
||||
BOOST_TEST(default_count == 5);
|
||||
BOOST_CHECK(check(w, 4));
|
||||
BOOST_CHECK(default_count == 5);
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -315,8 +315,8 @@ void do_switch_yes_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 5));
|
||||
BOOST_TEST(default_count == 4);
|
||||
BOOST_CHECK(check(w, 5));
|
||||
BOOST_CHECK(default_count == 4);
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -335,8 +335,8 @@ void do_switch_yes_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 6));
|
||||
BOOST_TEST(default_count == 3);
|
||||
BOOST_CHECK(check(w, 6));
|
||||
BOOST_CHECK(default_count == 3);
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
// ---
|
||||
@@ -356,8 +356,8 @@ void do_switch_yes_defaults_tests() {
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_TEST(check(w, 7));
|
||||
BOOST_TEST(default_count == 2);
|
||||
BOOST_CHECK(check(w, 7));
|
||||
BOOST_CHECK(default_count == 2);
|
||||
std::fill_n(w.begin(), 10, 0);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user