mirror of
https://github.com/boostorg/lambda.git
synced 2026-01-21 17:02:36 +00:00
Compare commits
10 Commits
boost-1.34
...
svn-branch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
428b712ea5 | ||
|
|
9ac88e5b39 | ||
|
|
797b5756cf | ||
|
|
bd4da55f0f | ||
|
|
47bf3df0ae | ||
|
|
ff0929e6e3 | ||
|
|
9b925abaff | ||
|
|
bf50f2fe7f | ||
|
|
85630d55a6 | ||
|
|
2e8c4eb8f3 |
@@ -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;
|
||||
}
|
||||
|
||||
@@ -3191,7 +3191,7 @@ to extend the library with new features.
|
||||
|
||||
|
||||
|
||||
<appendix>
|
||||
<section>
|
||||
<title>Rationale for some of the design decisions</title>
|
||||
|
||||
<section id="lambda.why_weak_arity">
|
||||
@@ -3256,7 +3256,7 @@ was dropped.
|
||||
|
||||
</section>
|
||||
|
||||
</appendix>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -148,6 +148,14 @@ public:
|
||||
>(a, cnull_type(), cnull_type(), cnull_type());
|
||||
}
|
||||
|
||||
template<class A>
|
||||
typename inherited::template sig<tuple<A const&> >::type
|
||||
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 +164,30 @@ public:
|
||||
>(a, b, cnull_type(), cnull_type());
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
typename inherited::template sig<tuple<A const&, B&> >::type
|
||||
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>
|
||||
typename inherited::template sig<tuple<A&, B const&> >::type
|
||||
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>
|
||||
typename inherited::template sig<tuple<A const&, B const&> >::type
|
||||
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 +197,15 @@ public:
|
||||
>(a, b, c, cnull_type());
|
||||
}
|
||||
|
||||
template<class A, class B, class C>
|
||||
typename inherited::template sig<tuple<A const&, B const&, C const&> >::type
|
||||
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
|
||||
@@ -207,6 +248,28 @@ public:
|
||||
} // 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
|
||||
|
||||
|
||||
|
||||
33
test/Jamfile
Normal file
33
test/Jamfile
Normal file
@@ -0,0 +1,33 @@
|
||||
# Lambda library
|
||||
|
||||
# Copyright (C) 2001-2003 Jaakko Järvi
|
||||
|
||||
# Use, modification and distribution is subject to the Boost Software License,
|
||||
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# For more information, see http://www.boost.org/
|
||||
|
||||
import testing ;
|
||||
|
||||
project
|
||||
: requirements <library>/boost/test//boost_test_exec_monitor
|
||||
;
|
||||
|
||||
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 ]
|
||||
;
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user