mirror of
https://github.com/boostorg/lambda.git
synced 2026-01-21 17:02:36 +00:00
Compare commits
5 Commits
boost-1.39
...
boost-1.41
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcff5b7436 | ||
|
|
e368877636 | ||
|
|
22bc52b7c4 | ||
|
|
8a943f6510 | ||
|
|
d69f83d074 |
@@ -1,21 +0,0 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# This file was automatically generated from the original CMakeLists.txt file
|
||||
# Add a variable to hold the headers for the library
|
||||
set (lib_headers
|
||||
lambda
|
||||
)
|
||||
|
||||
# Add a library target to the build system
|
||||
boost_library_project(
|
||||
lambda
|
||||
# SRCDIRS
|
||||
TESTDIRS test
|
||||
HEADERS ${lib_headers}
|
||||
# DOCDIRS
|
||||
# DESCRIPTION
|
||||
MODULARIZED
|
||||
# AUTHORS
|
||||
# MAINTAINERS
|
||||
)
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -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>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -270,6 +270,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; };
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -152,7 +176,7 @@ public:
|
||||
}
|
||||
|
||||
template<class A>
|
||||
typename inherited::template sig<tuple<A const&> >::type
|
||||
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
|
||||
@@ -168,7 +192,7 @@ public:
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
typename inherited::template sig<tuple<A const&, B&> >::type
|
||||
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
|
||||
@@ -176,7 +200,7 @@ public:
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
typename inherited::template sig<tuple<A&, B const&> >::type
|
||||
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
|
||||
@@ -184,7 +208,7 @@ public:
|
||||
}
|
||||
|
||||
template<class A, class B>
|
||||
typename inherited::template sig<tuple<A const&, B const&> >::type
|
||||
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
|
||||
@@ -201,7 +225,7 @@ public:
|
||||
}
|
||||
|
||||
template<class A, class B, class C>
|
||||
typename inherited::template sig<tuple<A const&, B const&, C const&> >::type
|
||||
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<
|
||||
|
||||
@@ -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,37 +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 boost::remove_reference<type1>::type no_reference;
|
||||
typedef typename detail::IF<
|
||||
is_reference<type1>::value,
|
||||
const no_reference &,
|
||||
const no_reference
|
||||
>::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 boost::remove_reference<type1>::type no_reference;
|
||||
typedef typename detail::IF<
|
||||
is_reference<type1>::value,
|
||||
volatile no_reference &,
|
||||
volatile no_reference
|
||||
>::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 boost::remove_reference<type1>::type no_reference;
|
||||
typedef typename detail::IF<
|
||||
is_reference<type1>::value,
|
||||
const volatile no_reference &,
|
||||
const volatile no_reference
|
||||
>::RET type;
|
||||
typedef typename contentsof_type<A>::type type;
|
||||
};
|
||||
|
||||
// standard iterator traits should take care of the pointer types
|
||||
@@ -856,44 +831,6 @@ struct return_type_2<other_action<subscript_action>, A, B> {
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace lambda
|
||||
} // namespace boost
|
||||
|
||||
|
||||
// Forward declarations are incompatible with the libstdc++ debug mode.
|
||||
#if BOOST_WORKAROUND(__GNUC__, >= 3) && defined(_GLIBCXX_DEBUG)
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#else
|
||||
|
||||
// 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
|
||||
|
||||
namespace std {
|
||||
template <class Char, class Traits, class Allocator> class basic_string;
|
||||
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;
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
boost_module(lambda DEPENDS tuple)
|
||||
@@ -1,18 +0,0 @@
|
||||
boost_additional_test_dependencies(lambda BOOST_DEPENDS test any)
|
||||
|
||||
boost_test_run(algorithm_test DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(bind_tests_simple DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(bind_tests_advanced DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(bind_tests_simple_f_refs DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(bll_and_function DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(lambda_cast_test
|
||||
cast_test.cpp DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(constructor_tests DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(control_structures DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(exception_test DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(extending_rt_traits DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(is_instance_of_test DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(member_pointer_test DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(operator_tests_simple DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(phoenix_control_structures DEPENDS boost_test_exec_monitor)
|
||||
boost_test_run(switch_construct DEPENDS boost_test_exec_monitor)
|
||||
@@ -30,4 +30,5 @@ test-suite lambda
|
||||
[ run operator_tests_simple.cpp ]
|
||||
[ run phoenix_control_structures.cpp ]
|
||||
[ run switch_construct.cpp ]
|
||||
[ run ret_test.cpp ]
|
||||
;
|
||||
|
||||
@@ -27,7 +27,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; }
|
||||
@@ -91,7 +92,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)
|
||||
@@ -116,11 +117,11 @@ void test_unlambda() {
|
||||
|
||||
BOOST_CHECK(call_with_101(_1 + 1) == 102);
|
||||
|
||||
BOOST_CHECK(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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::lambda;
|
||||
using namespace boost::lambda;
|
||||
|
||||
|
||||
int sum_of_args_0() { return 0; }
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::lambda;
|
||||
using namespace boost::lambda;
|
||||
|
||||
|
||||
int sum_of_args_0() { return 0; }
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#endif
|
||||
|
||||
using namespace boost::lambda;
|
||||
using namespace std;
|
||||
namespace bl = boost::lambda;
|
||||
|
||||
template<class T>
|
||||
bool check_tuple(int n, const T& t)
|
||||
@@ -212,17 +212,17 @@ 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));
|
||||
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));
|
||||
std::for_each(ct, ct+10, bind(delete_ptr(), _1));
|
||||
BOOST_CHECK(count_deletes::count == 10);
|
||||
|
||||
}
|
||||
@@ -240,16 +240,16 @@ void test_array_new_and_delete()
|
||||
|
||||
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 *[]) {
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "boost/lambda/detail/suppress_unused.hpp"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
@@ -323,8 +325,18 @@ void address_of_and_dereference() {
|
||||
|
||||
(*_1 = 7)(it);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user