early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,323 @@
#==============================================================================
# Copyright (c) 2003-2006 Joel de Guzman
# Copyright (c) 2014-2015 John Fletcher
#
# 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)
#==============================================================================
# bring in rules for testing
import testing ;
import os ;
import ../../config/checks/config : requires ;
if [ os.environ CI ]
{
CI_DEFINES = <define>CI_SKIP_KNOWN_FAILURE=1 ;
CI_DEFINES += <define>RUNNING_ON_TRAVIS=1 ; # for backward compatibility
CI_DEFINES += <define>RUNNING_ON_APPVEYOR=1 ; # for backward compatibility
}
project
: requirements
<toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
<toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
$(CI_DEFINES)
;
local multi-threading = <library>/boost/thread
<threading>multi <define>BOOST_ALL_NO_LIB=1 ;
test-suite phoenix_core :
[ run core/custom_terminal.cpp ]
[ run core/intel_test.cpp ]
[ run core/primitives_tests.cpp ]
;
test-suite phoenix_stdlib :
[ run stdlib/cmath.cpp ]
;
test-suite phoenix_operator :
[ run operator/arithmetic_tests.cpp ]
[ run operator/bitwise_tests.cpp ]
[ run operator/comparison_tests.cpp ]
[ run operator/if_else_tests.cpp ]
[ run operator/io_tests.cpp ]
[ run operator/logical_tests.cpp ]
[ run operator/misc_binary_tests.cpp ]
[ run operator/self_tests.cpp ]
[ run operator/unary_tests.cpp ]
[ run operator/member.cpp ]
;
test-suite phoenix_object :
[ run object/cast_tests.cpp ]
[ run object/new_delete_tests.cpp ]
;
test-suite phoenix_function :
[ run function/adapt_function.cpp ]
[ run function/function_tests.cpp ]
[ run function/lazy_argument_tests.cpp ]
# [ run function/lazy_compose_tests.cpp ]
# [ run function/lazy_fold_tests.cpp ]
[ run function/lazy_list_tests.cpp ]
[ run function/lazy_list2_tests.cpp ]
[ run function/lazy_list3_tests.cpp ]
[ run function/lazy_make_pair_tests.cpp ]
# [ run function/lazy_ptr_tests.cpp ]
# [ run function/lazy_scan_tests.cpp ]
[ run function/lazy_templated_struct_tests.cpp ]
# [ run function/lazy_thunk_tests.cpp ]
[ run function/lazy_operator_tests.cpp ]
;
test-suite phoenix_bind :
[ run bind/bind_function_tests.cpp ]
[ run bind/bind_function_object_tests.cpp ]
[ run bind/bind_member_function_tests.cpp ]
[ run bind/bind_member_variable_tests.cpp ]
[ run bind/bug5782.cpp ]
;
test-suite phoenix_statement :
[ run statement/if_tests.cpp ]
[ run statement/loops_tests.cpp ]
[ run statement/switch_tests.cpp ]
[ run statement/exceptions.cpp ]
[ run statement/bug5715.cpp ]
;
test-suite phoenix_container :
[ run container/container_tests1a.cpp ]
[ run container/container_tests1b.cpp ]
[ run container/container_tests2a.cpp ]
[ run container/container_tests2b.cpp ]
[ run container/container_tests3a.cpp ]
[ run container/container_tests3b.cpp ]
[ run container/container_tests4a.cpp ]
[ run container/container_tests4b.cpp ]
[ run container/container_tests5a.cpp ]
[ run container/container_tests5b.cpp ]
[ run container/container_tests6a.cpp ]
[ run container/container_tests6b.cpp ]
[ run container/container_tests7a.cpp ]
[ run container/container_tests7b.cpp ]
[ run container/container_tests8a.cpp ]
[ run container/container_tests8b.cpp : : : [ requires cxx11_hdr_unordered_map ] ]
[ run container/container_tests9a.cpp : : : [ requires cxx11_hdr_unordered_map ] ]
[ run container/container_tests9b.cpp : : : [ requires cxx11_hdr_unordered_map ] ]
[ run container/container_tests10a.cpp : : : [ requires cxx11_hdr_unordered_map ] ]
[ run container/container_tests10b.cpp : : : [ requires cxx11_hdr_unordered_map ] ]
[ run container/container_tests11a.cpp : : : [ requires cxx11_hdr_unordered_set ] ]
[ run container/container_tests11b.cpp : : : [ requires cxx11_hdr_unordered_set ] ]
[ run container/container_tests12a.cpp : : : [ requires cxx11_hdr_unordered_set ] ]
[ run container/container_tests12b.cpp : : : [ requires cxx11_hdr_unordered_set ] ]
;
test-suite phoenix_scope :
[ run scope/lambda_tests1.cpp ]
[ run scope/lambda_tests2.cpp ]
[ run scope/lambda_tests3.cpp ]
[ run scope/lambda_tests4.cpp ]
[ run scope/lambda_tests5.cpp ]
[ run scope/lambda_tests6.cpp ]
[ run scope/lambda_tests7.cpp ]
[ run scope/lambda_tests8.cpp ]
[ run scope/lambda_tests9.cpp ]
[ run scope/lambda_tests10.cpp ]
[ run scope/lambda_tests11.cpp ]
[ run scope/lambda_tests12.cpp ]
[ run scope/lambda_tests13.cpp ]
[ run scope/lambda_tests14.cpp ]
[ run scope/lambda_tests15.cpp ]
[ run scope/lambda_tests16.cpp ]
[ run scope/lambda_tests17.cpp ]
[ run scope/lambda_tests18.cpp ]
[ run scope/lambda_tests19.cpp ]
[ run scope/lambda_tests20.cpp ]
[ run scope/lambda_tests21.cpp ]
[ run scope/lambda_tests22.cpp ]
[ run scope/lambda_tests23.cpp ]
[ run scope/let_tests.cpp ]
[ run scope/let_tests_113.cpp ]
# [ run scope/let_tests_113a.cpp ]
[ run scope/let_tests_157.cpp ]
# [ run scope/let_tests_157a.cpp ]
[ run scope/let_tests_rest.cpp ]
[ run scope/more_lambda_tests.cpp ]
[ run scope/more_let_tests.cpp ]
# [ run scope/more_let_tests1.cpp ]
# [ run scope/more_let_tests2a.cpp ]
# [ run scope/more_let_tests2b.cpp ]
[ run scope/dynamic_tests.cpp ]
[ run scope/bug3289.cpp ]
[ run scope/bug8298.cpp ]
[ compile-fail scope/bug8298f.cpp ]
[ run scope/bug_000008.cpp : : : $(multi-threading) ]
;
test-suite phoenix_algorithm :
[ run algorithm/for_each.cpp ]
[ run algorithm/for_each2.cpp ]
[ run algorithm/for_test.cpp ]
[ run algorithm/for_test2.cpp ]
[ run algorithm/iteration.cpp ]
[ run algorithm/transformation1.cpp ]
[ run algorithm/transformation2.cpp ]
[ run algorithm/transformation3.cpp ]
[ run algorithm/transformation4.cpp ]
[ run algorithm/querying.cpp ]
[ run algorithm/querying_find.cpp ]
[ run algorithm/querying2.cpp ]
[ run algorithm/querying_find2.cpp ]
;
test-suite phoenix_boost_bind_compatibility :
[ run boost_bind_compatibility/bind_and_or_test.cpp ]
[ run boost_bind_compatibility/bind_const_test.cpp ]
[ run boost_bind_compatibility/bind_cv_test.cpp ]
[ run boost_bind_compatibility/bind_dm_test.cpp ]
# [ run boost_bind_compatibility/bind_dm1_test.cpp ]
[ run boost_bind_compatibility/bind_dm2_test.cpp ]
[ run boost_bind_compatibility/bind_dm3_test.cpp ]
[ run boost_bind_compatibility/bind_eq_test.cpp ]
[ run boost_bind_compatibility/bind_eq2_test.cpp ]
[ run boost_bind_compatibility/bind_eq3_test.cpp ]
[ run boost_bind_compatibility/bind_fn2_test.cpp ]
[ run boost_bind_compatibility/bind_function_test.cpp ]
[ run boost_bind_compatibility/bind_interoperation_test.cpp ]
[ run boost_bind_compatibility/bind_mf2_test.cpp ]
[ run boost_bind_compatibility/bind_not_test.cpp ]
[ run boost_bind_compatibility/bind_placeholder_test.cpp ]
[ run boost_bind_compatibility/bind_ref_test.cpp ]
[ run boost_bind_compatibility/bind_rel_test.cpp ]
[ run boost_bind_compatibility/bind_rvalue_test.cpp ]
[ run boost_bind_compatibility/bind_rv_sp_test.cpp ]
# [ run boost_bind_compatibility/bind_rv_sp1_test.cpp ]
# [ run boost_bind_compatibility/bind_rv_sp2_test.cpp ]
# [ run boost_bind_compatibility/bind_rv_sp3_test.cpp ]
# [ run boost_bind_compatibility/bind_rv_sp4_test.cpp ]
# [ run boost_bind_compatibility/bind_rv_sp5_test.cpp ]
# [ run boost_bind_compatibility/bind_rv_sp6_test.cpp ]
# [ run boost_bind_compatibility/bind_rv_sp7_test.cpp ]
[ run boost_bind_compatibility/bind_stateful_test.cpp ]
[ run boost_bind_compatibility/bind_test.cpp ]
# [ run boost_bind_compatibility/bind_void_dm_test.cpp ]
;
test-suite phoenix_bll_compatibility :
[ run bll_compatibility/algorithm_test.cpp ]
[ run bll_compatibility/bind_tests_advanced.cpp ]
# [ run bll_compatibility/bind_tests_simple.cpp ]
# [ run bll_compatibility/bind_tests_simple_f_refs.cpp ]
# [ run bll_compatibility/bll_and_function.cpp ]
# [ run bll_compatibility/cast_test.cpp ]
# [ run bll_compatibility/constructor_tests.cpp ]
# [ run bll_compatibility/control_structures.cpp ]
# [ run bll_compatibility/exception_test.cpp ]
# [ run bll_compatibility/extending_rt_traits.cpp ]
# [ run bll_compatibility/is_instance_of_test.cpp ]
# [ run bll_compatibility/istreambuf_test.cpp ]
# [ run bll_compatibility/member_pointer_test.cpp ]
# [ run bll_compatibility/operator_tests_simple.cpp ]
# [ run bll_compatibility/phoenix_control_structures.cpp ]
# [ run bll_compatibility/result_of_tests.cpp ]
# [ run bll_compatibility/ret_test.cpp ]
# [ run bll_compatibility/rvalue_test.cpp ]
# [ run bll_compatibility/switch_construct.cpp ]
;
test-suite phoenix_regression :
[ run regression/bug4853.cpp ]
[ run regression/bug5626.cpp ]
[ run regression/bug5824.cpp ]
# [ run regression/bug5875.cpp ]
[ run regression/bug5968.cpp ]
[ run regression/bug6040.cpp ]
[ run regression/bug6268.cpp ]
[ run regression/bug7165.cpp ]
[ compile-fail regression/bug7166.cpp ]
[ run regression/bug7624.cpp ]
[ compile regression/from_array.cpp ]
[ run regression/actor_assignment.cpp ]
;
test-suite phoenix_include :
[ run include/bind.cpp ]
[ run include/core.cpp ]
[ run include/function.cpp ]
[ run include/fusion.cpp ]
[ run include/object.cpp ]
[ run include/operator.cpp ]
[ run include/scope.cpp ]
# [ run include/spirit.cpp ]
# [ run include/spirit_no_specialize.cpp ]
[ run include/statement.cpp ]
[ run include/stl.cpp ]
[ run include/version.cpp ]
[ run include/bind/bind_member_function.cpp ]
[ run include/bind/bind_member_variable.cpp ]
[ run include/core/actor.cpp ]
[ run include/core/argument.cpp ]
[ run include/core/arity.cpp ]
[ run include/core/debug.cpp ]
[ run include/core/domain.cpp ]
[ run include/core/environment.cpp ]
[ run include/core/expression.cpp ]
[ run include/core/function_equal.cpp ]
[ run include/core/is_actor.cpp ]
[ run include/core/is_nullary.cpp ]
[ run include/core/limits.cpp ]
[ run include/core/meta_grammar.cpp ]
[ run include/core/nothing.cpp ]
[ run include/core/reference.cpp ]
[ run include/core/terminal.cpp ]
# [ run include/core/bug7730.cpp ]
[ run include/core/value.cpp ]
[ run include/function/function.cpp : : : : function_function ]
[ run include/function/lazy_headers.cpp ]
[ run include/fusion/at.cpp ]
[ run include/object/const_cast.cpp ]
[ run include/object/construct.cpp ]
[ run include/object/delete.cpp ]
[ run include/object/dynamic_cast.cpp ]
[ run include/object/new.cpp ]
[ run include/object/reinterpret_cast.cpp ]
[ run include/object/static_cast.cpp ]
[ run include/operator/arithmetic.cpp ]
[ run include/operator/bitwise.cpp ]
[ run include/operator/comparison.cpp ]
[ run include/operator/if_else.cpp ]
[ run include/operator/io.cpp ]
[ run include/operator/logical.cpp ]
[ run include/operator/member.cpp : : : : operator_member ]
[ run include/operator/self.cpp ]
[ run include/scope/dynamic.cpp ]
[ run include/scope/lambda.cpp ]
[ run include/scope/let.cpp ]
[ run include/scope/local_variable.cpp ]
[ run include/scope/scoped_environment.cpp ]
[ run include/scope/this.cpp ]
[ run include/statement/do_while.cpp ]
[ run include/statement/for.cpp ]
[ run include/statement/if.cpp ]
[ run include/statement/sequence.cpp ]
[ run include/statement/switch.cpp ]
[ run include/statement/throw.cpp ]
[ run include/statement/try_catch.cpp ]
[ run include/statement/while.cpp ]
[ run include/stl/algorithm.cpp ]
[ run include/stl/container.cpp ]
[ run include/stl/container/container.cpp : : : : container_container ]
[ run include/stl/algorithm/iteration.cpp : : : : include_iteration ]
[ run include/stl/algorithm/querying.cpp : : : : include_querying ]
[ run include/stl/algorithm/transformation.cpp ]
[ run include/support/iterate.cpp ]
[ run include/support/preprocessor/round.cpp ]
;

View File

@@ -0,0 +1,51 @@
/*=============================================================================
Copyright (c) 2005-2007 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
Copyright (c) 2014 John Fletcher
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/phoenix.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/iteration.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <functional>
#include <vector>
#include <string>
#include <sstream>
namespace
{
void for_each_test()
{
using boost::phoenix::for_each;
using boost::phoenix::lambda;
using boost::phoenix::val;
using boost::phoenix::arg_names::arg1;
std::vector<int> v;
for (int i = 1; i < 10; i++)
v.push_back(i);
std::string test_str("(123456789)");
std::ostringstream out;
(
out << val("("),
for_each(arg1, lambda[out << arg1]),
out << val(")")
)(v);
BOOST_TEST(out.str() == test_str);
return;
}
}
int main()
{
for_each_test();
boost::report_errors();
}

View File

@@ -0,0 +1,47 @@
/*=============================================================================
Copyright (c) 2005-2007 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
Copyright (c) 2014-2015 John Fletcher
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/phoenix.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/iteration.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <functional>
#include <vector>
#include <string>
#include <sstream>
namespace
{
void for_each_test()
{
return;
using boost::phoenix::for_each;
using boost::phoenix::lambda;
using boost::phoenix::ref;
using boost::phoenix::arg_names::arg1;
std::vector<int> v;
for (int i = 1; i < 10; i++)
v.push_back(i);
int x = 0;
for_each(arg1, lambda[ref(x) += arg1])(v);
BOOST_TEST(x == 45);
return;
}
}
int main()
{
for_each_test();
boost::report_errors();
}

View File

@@ -0,0 +1,55 @@
/*=============================================================================
Copyright (c) 2005-2007 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
Copyright (c) 2014 John Fletcher
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/phoenix.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/iteration.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <functional>
#include <vector>
#include <string>
#include <sstream>
#include <boost/typeof/std/ostream.hpp>
namespace
{
void for_test()
{
using boost::phoenix::for_;
using boost::phoenix::val;
using boost::phoenix::ref;
using boost::phoenix::arg_names::arg1;
std::vector<int> v;
for (int i = 1; i < 10; i++)
v.push_back(i);
std::string test_str("(123456789)");
std::ostringstream out;
int iii;
int size = v.size();
(
out << val("("),
for_(ref(iii) = 0, ref(iii) < size, ++ref(iii) )
[ out << arg1[ref(iii)] ],
out << val(")")
)(v);
BOOST_TEST(out.str() == test_str);
return;
}
}
int main()
{
for_test();
boost::report_errors();
}

View File

@@ -0,0 +1,52 @@
/*=============================================================================
Copyright (c) 2005-2007 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
Copyright (c) 2014-2015 John Fletcher
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/phoenix.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/iteration.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <functional>
#include <vector>
#include <string>
#include <sstream>
#include <boost/typeof/std/ostream.hpp>
namespace
{
void for_test()
{
using boost::phoenix::for_;
using boost::phoenix::val;
using boost::phoenix::ref;
using boost::phoenix::arg_names::arg1;
std::vector<int> v;
for (int i = 1; i < 10; i++)
v.push_back(i);
//std::string test_str("(123456789)");
//std::ostringstream out;
int iii;
int x = 0;
int size = v.size();
for_(ref(iii) = 0, ref(iii) < size, ++ref(iii) )
[ ref(x) += arg1[ref(iii)] ] (v);
BOOST_TEST(x == 45);
return;
}
}
int main()
{
for_test();
boost::report_errors();
}

View File

@@ -0,0 +1,57 @@
/*=============================================================================
Copyright (c) 2005-2007 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
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/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/iteration.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <functional>
namespace
{
struct for_each_tester
{
int value_;
for_each_tester() : value_(0) { }
void operator()(
int& i)
{
value_ += i++;
return;
}
};
void for_each_test()
{
using boost::phoenix::for_each;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
BOOST_TEST(for_each(arg1, for_each_tester())(array).value_ == 6);
BOOST_TEST(array[0] == 2);
BOOST_TEST(array[1] == 3);
BOOST_TEST(array[2] == 4);
return;
}
void accumulate_test()
{
using boost::phoenix::accumulate;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
BOOST_TEST(accumulate(arg1, 0)(array) == 6);
BOOST_TEST(boost::phoenix::accumulate(arg1, 0, std::minus<int>())(array) == -6);
return;
}
}
int main()
{
for_each_test();
accumulate_test();
boost::report_errors();
}

View File

@@ -0,0 +1,286 @@
/*=============================================================================
Copyright (c) 2005 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
Copyright (c) 2007 Hartmut Kaiser
Copyright (c) 2015 John Fletcher
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/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/querying.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/config.hpp>
#ifdef BOOST_PHOENIX_HAS_HASH
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include BOOST_PHOENIX_HASH_SET_HEADER
#include BOOST_PHOENIX_HASH_MAP_HEADER
#endif
#include <set>
#include <map>
#include <functional>
namespace
{
struct even
{
bool operator()(const int i) const
{
return i % 2 == 0;
}
};
struct mod_2_comparison
{
bool operator()(
const int lhs,
const int rhs)
{
return lhs % 2 == rhs % 2;
}
};
void find_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
BOOST_TEST(boost::phoenix::find(arg1,2)(array) == array + 1);
std::set<int> s(array, array + 3);
BOOST_TEST(boost::phoenix::find(arg1, 2)(s) == s.find(2));
#if !(defined(BOOST_MSVC) && (BOOST_MSVC >= 1900))
std::map<int, int> m = boost::assign::map_list_of(0, 1)(2, 3)(4, 5);
BOOST_TEST(boost::phoenix::find(arg1, 2)(m) == m.find(2));
#endif
#ifdef BOOST_PHOENIX_HAS_HASH
BOOST_PHOENIX_HASH_NAMESPACE::hash_set<int> hs(array, array + 3);
BOOST_TEST(boost::phoenix::find(arg1, 2)(hs) == hs.find(2));
BOOST_PHOENIX_HASH_NAMESPACE::hash_map<int, int> hm = boost::assign::map_list_of(0, 1)(2, 3)(4, 5);
BOOST_TEST(boost::phoenix::find(arg1, 2)(hm) == hm.find(2));
#endif
return;
}
void find_if_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
BOOST_TEST(boost::phoenix::find_if(arg1, even())(array) == array + 1);
return;
}
void find_end_test()
{
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3,1,2,3,1};
int pattern[] = {1,2,3};
BOOST_TEST(boost::phoenix::find_end(arg1, arg2)(array, pattern) == array + 3);
int pattern2[] = {5,6,5};
BOOST_TEST(boost::phoenix::find_end(arg1, arg2, mod_2_comparison())(array, pattern2) == array + 3);
return;
}
void find_first_of_test()
{
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int search_for[] = {2,3,4};
BOOST_TEST(boost::phoenix::find_first_of(arg1, arg2)(array, search_for) == array + 1);
int search_for2[] = {0};
BOOST_TEST(boost::phoenix::find_first_of(arg1, arg2, mod_2_comparison())(array, search_for2) == array + 1);
return;
}
void adjacent_find_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {0,1,3,4,4};
BOOST_TEST(boost::phoenix::adjacent_find(arg1)(array) == array + 3);
BOOST_TEST(boost::phoenix::adjacent_find(arg1, mod_2_comparison())(array) == array + 1);
return;
}
void count_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,1,0,1,1};
BOOST_TEST(boost::phoenix::count(arg1, 1)(array) == 4);
return;
}
void count_if_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3,4,5};
BOOST_TEST(boost::phoenix::count_if(arg1, even())(array) == 2);
return;
}
void distance_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,1,0,1,1};
BOOST_TEST(boost::phoenix::distance(arg1)(array) == 5);
return;
}
void mismatch_test()
{
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3,4,5};
int search[] = {1,2,4};
BOOST_TEST(
boost::phoenix::mismatch(arg1, arg2)(array, search) ==
std::make_pair(array + 2, search + 2));
int search2[] = {1,2,1,1};
BOOST_TEST(
boost::phoenix::mismatch(arg1, arg2, mod_2_comparison())(array, search2)
== std::make_pair(array + 3, search2 + 3));
return;
}
void equal_test()
{
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int array2[] = {1,2,3};
int array3[] = {1,2,4};
BOOST_TEST(
boost::phoenix::equal(arg1, arg2)(array, array2));
BOOST_TEST(
!boost::phoenix::equal(arg1, arg2)(array, array3));
BOOST_TEST(
boost::phoenix::equal(arg1, arg2, mod_2_comparison())(array, array2));
BOOST_TEST(
!boost::phoenix::equal(arg1, arg2, mod_2_comparison())(array, array3));
return;
}
void search_test()
{
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3,1,2,3};
int pattern[] = {2,3};
BOOST_TEST(
boost::phoenix::search(arg1, arg2)(array, pattern) == array + 1);
int pattern2[] = {1,1};
BOOST_TEST(
boost::phoenix::search(arg1, arg2, mod_2_comparison())(array, pattern2) == array + 2);
return;
}
void lower_bound_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
const std::set<int> test_set(array, array + 3);
BOOST_TEST(boost::phoenix::lower_bound(arg1, 2)(array) == array + 1);
BOOST_TEST(boost::phoenix::lower_bound(arg1, 2)(test_set) == test_set.lower_bound(2));
int array2[] = {3,2,1};
const std::set<int, std::greater<int> > test_set2(array2, array2 + 3);
BOOST_TEST(boost::phoenix::lower_bound(arg1, 2, std::greater<int>())(array2) ==
array2 + 1);
BOOST_TEST(boost::phoenix::lower_bound(arg1, 2, std::greater<int>())(test_set2) ==
test_set2.lower_bound(2));
return;
}
void upper_bound_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
const std::set<int> test_set(array, array + 3);
BOOST_TEST(upper_bound(arg1, 2)(array) == array + 2);
BOOST_TEST(upper_bound(arg1, 2)(test_set) == test_set.upper_bound(2));
int array2[] = {3,2,1};
const std::set<int, std::greater<int> > test_set2(array2, array2 + 3);
BOOST_TEST(boost::phoenix::upper_bound(arg1, 2, std::greater<int>())(array2) ==
array2 + 2);
BOOST_TEST(boost::phoenix::upper_bound(arg1, 2, std::greater<int>())(test_set2) ==
test_set2.upper_bound(2));
return;
}
void equal_range_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,2,3};
const std::set<int> test_set(array, array + 4);
BOOST_TEST(boost::phoenix::equal_range(arg1, 2)(array).first ==
array + 1);
BOOST_TEST(boost::phoenix::equal_range(arg1, 2)(array).second ==
array + 3);
BOOST_TEST(boost::phoenix::equal_range(arg1, 2)(test_set).first ==
test_set.equal_range(2).first);
BOOST_TEST(boost::phoenix::equal_range(arg1, 2)(test_set).second ==
test_set.equal_range(2).second);
int array2[] = {3,2,2,1};
const std::set<int, std::greater<int> > test_set2(array2, array2 + 4);
BOOST_TEST(boost::phoenix::equal_range(arg1, 2, std::greater<int>())(array2).first ==
array2 + 1);
BOOST_TEST(boost::phoenix::equal_range(arg1, 2, std::greater<int>())(array2).second ==
array2 + 3);
BOOST_TEST(boost::phoenix::equal_range(arg1, 2, std::greater<int>())(test_set2).first ==
test_set2.equal_range(2).first);
BOOST_TEST(boost::phoenix::equal_range(arg1, 2, std::greater<int>())(test_set2).second ==
test_set2.equal_range(2).second);
return;
}
void binary_search_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
BOOST_TEST(boost::phoenix::binary_search(arg1, 2)(array));
BOOST_TEST(!boost::phoenix::binary_search(arg1, 4)(array));
return;
}
}
int main()
{
find_test();
find_if_test();
find_end_test();
find_first_of_test();
adjacent_find_test();
count_test();
count_if_test();
distance_test();
mismatch_test();
equal_test();
search_test();
lower_bound_test();
upper_bound_test();
equal_range_test();
binary_search_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,85 @@
/*=============================================================================
Copyright (c) 2005-2007 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
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/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/querying.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/range.hpp>
#include <functional>
namespace
{
void includes_test()
{
using boost::phoenix::includes;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int array2[] = {1,2};
BOOST_TEST(includes(arg1, arg2)(array, array2));
boost::iterator_range<int*> rng(array + 1, array + 3);
BOOST_TEST(!includes(arg1, arg2)(rng, array2));
int array3[] = {3,2,1};
int array4[] = {2,1};
BOOST_TEST(boost::phoenix::includes(arg1, arg2, std::greater<int>())(array3, array4));
boost::iterator_range<int*> rng2(array3, array3 + 2);
BOOST_TEST(!boost::phoenix::includes(arg1, arg2, std::greater<int>())(rng2, array4));
return;
}
void min_element_test()
{
using boost::phoenix::min_element;
using boost::phoenix::arg_names::arg1;
int array[] = {1,3,2};
BOOST_TEST(min_element(arg1)(array) == array);
BOOST_TEST(boost::phoenix::min_element(arg1, std::greater<int>())(array) == array + 1);
return;
}
void max_element_test()
{
using boost::phoenix::max_element;
using boost::phoenix::arg_names::arg1;
int array[] = {1,3,2};
BOOST_TEST(max_element(arg1)(array) == array + 1);
BOOST_TEST(boost::phoenix::max_element(arg1, std::greater<int>())(array) == array);
return;
}
void lexicographical_compare_test()
{
using boost::phoenix::lexicographical_compare;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int array2[] = {1,2,4};
BOOST_TEST(lexicographical_compare(arg1, arg2)(array, array2));
BOOST_TEST(!lexicographical_compare(arg1, arg2)(array2, array));
BOOST_TEST(!lexicographical_compare(arg1, arg2)(array, array));
BOOST_TEST(!boost::phoenix::lexicographical_compare(arg1, arg2, std::greater<int>())(array, array2));
BOOST_TEST(boost::phoenix::lexicographical_compare(arg1, arg2, std::greater<int>())(array2, array));
BOOST_TEST(!boost::phoenix::lexicographical_compare(arg1, arg2, std::greater<int>())(array, array));
return;
}
}
int main()
{
includes_test();
min_element_test();
max_element_test();
lexicographical_compare_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,96 @@
/*=============================================================================
Copyright (c) 2005 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
Copyright (c) 2007 Hartmut Kaiser
Copyright (c) 2015 John Fletcher
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/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/querying.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/config.hpp>
#ifdef BOOST_PHOENIX_HAS_HASH
#include BOOST_PHOENIX_HASH_SET_HEADER
#include BOOST_PHOENIX_HASH_MAP_HEADER
#endif
#ifdef BOOST_PHOENIX_HAS_UNORDERED_SET_AND_MAP
#include BOOST_PHOENIX_UNORDERED_SET_HEADER
#include BOOST_PHOENIX_UNORDERED_MAP_HEADER
#endif
#include <set>
#include <map>
#include <functional>
namespace
{
struct even
{
bool operator()(const int i) const
{
return i % 2 == 0;
}
};
struct mod_2_comparison
{
bool operator()(
const int lhs,
const int rhs)
{
return lhs % 2 == rhs % 2;
}
};
void find_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
BOOST_TEST(boost::phoenix::find(arg1,2)(array) == array + 1);
std::set<int> s(array, array + 3);
BOOST_TEST(boost::phoenix::find(arg1, 2)(s) == s.find(2));
//#if !(defined(BOOST_MSVC) && (BOOST_MSVC >= 1900))
//std::map<int, int> m = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).to_container(m);
std::map<int, int> m = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
convert_to_container<std::map<int, int> >();
BOOST_TEST(boost::phoenix::find(arg1, 2)(m) == m.find(2));
//#endif
#ifdef BOOST_PHOENIX_HAS_HASH
BOOST_PHOENIX_HASH_NAMESPACE::hash_set<int> hs(array, array + 3);
BOOST_TEST(boost::phoenix::find(arg1, 2)(hs) == hs.find(2));
BOOST_PHOENIX_HASH_NAMESPACE::hash_map<int, int> hm = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
convert_to_container<BOOST_PHOENIX_HASH_NAMESPACE::hash_map<int, int> >();
BOOST_TEST(boost::phoenix::find(arg1, 2)(hm) == hm.find(2));
#endif
#ifdef BOOST_PHOENIX_HAS_UNORDERED_SET_AND_MAP
std::unordered_set<int> us(array, array + 3);
BOOST_TEST(boost::phoenix::find(arg1, 2)(us) == us.find(2));
std::unordered_map<int, int> um = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
convert_to_container<std::unordered_map<int, int> >();
BOOST_TEST(boost::phoenix::find(arg1, 2)(um) == um.find(2));
#endif
return;
}
}
int main()
{
find_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,103 @@
/*=============================================================================
Copyright (c) 2005 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
Copyright (c) 2007 Hartmut Kaiser
Copyright (c) 2015 John Fletcher
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/phoenix/config.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/querying.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/assign/list_of.hpp>
#include <set>
#include <map>
#include <functional>
#ifdef BOOST_PHOENIX_HAS_HASH
#include BOOST_PHOENIX_HASH_SET_HEADER
#include BOOST_PHOENIX_HASH_MAP_HEADER
#endif
#ifdef BOOST_PHOENIX_HAS_UNORDERED_SET_AND_MAP
#include BOOST_PHOENIX_UNORDERED_SET_HEADER
#include BOOST_PHOENIX_UNORDERED_MAP_HEADER
#endif
namespace
{
struct even
{
bool operator()(const int i) const
{
return i % 2 == 0;
}
};
struct mod_2_comparison
{
bool operator()(
const int lhs,
const int rhs)
{
return lhs % 2 == rhs % 2;
}
};
void find_test()
{
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
BOOST_TEST(boost::phoenix::find(arg1,2)(array) == array + 1);
std::set<int> s(array, array + 3);
BOOST_TEST(boost::phoenix::find(arg1, 2)(s) == s.find(2));
std::map<int, int> m = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
convert_to_container<std::map<int, int> >();
BOOST_TEST(boost::phoenix::find(arg1, 2)(m) == m.find(2));
#ifdef BOOST_PHOENIX_HAS_HASH
BOOST_PHOENIX_HASH_NAMESPACE::hash_set<int> hs(array, array + 3);
BOOST_TEST(boost::phoenix::find(arg1, 2)(hs) == hs.find(2));
BOOST_PHOENIX_HASH_NAMESPACE::hash_map<int, int> hm = boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
convert_to_container<BOOST_PHOENIX_HASH_NAMESPACE::hash_map<int, int> >();
BOOST_TEST(boost::phoenix::find(arg1, 2)(hm) == hm.find(2));
#endif
#ifdef BOOST_PHOENIX_HAS_UNORDERED_SET_AND_MAP
std::unordered_set<int> us(array, array + 3);
BOOST_TEST(boost::phoenix::find(arg1, 2)(us) == us.find(2));
int marray[] = {1,1,2,3,3};
std::unordered_multiset<int> ums(marray, marray + 5);
BOOST_TEST(boost::phoenix::find(arg1, 2)(ums) == ums.find(2));
std::unordered_map<int, int> um =
boost::assign::map_list_of(0, 1)(2, 3)(4, 5).
convert_to_container<std::unordered_map<int, int> >();
BOOST_TEST(boost::phoenix::find(arg1, 2)(um) == um.find(2));
std::unordered_multimap<int, int> umm =
boost::assign::map_list_of(0, 1)(2, 3)(4, 5)(4, 6).
convert_to_container<std::unordered_multimap<int, int> >();
BOOST_TEST(boost::phoenix::find(arg1, 2)(umm) == umm.find(2));
#endif
return;
}
}
int main()
{
find_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,403 @@
/*=============================================================================
Copyright (c) 2005-2007 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
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/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/transformation.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <functional>
#include <list>
namespace
{
struct even
{
bool operator()(const int i) const
{
return i % 2 == 0;
}
};
struct mod_2_comparison
{
bool operator()(
const int lhs,
const int rhs)
{
return lhs % 2 == rhs % 2;
}
};
void swap_test()
{
using boost::phoenix::swap;
using boost::phoenix::ref;
using boost::phoenix::arg_names::_1;
using boost::phoenix::arg_names::_2;
int a = 123;
int b = 456;
swap(ref(a), ref(b))();
BOOST_TEST(a == 456 && b == 123);
swap(ref(a), _1)(b);
BOOST_TEST(a == 123 && b == 456);
swap(_1, _2)(a, b);
BOOST_TEST(a == 456 && b == 123);
return;
}
void copy_test()
{
using boost::phoenix::copy;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int output[4];
BOOST_TEST(
copy(arg1, arg2)(array, output) == output + 3);
BOOST_TEST(output[0] == 1);
BOOST_TEST(output[1] == 2);
BOOST_TEST(output[2] == 3);
return;
}
void copy_backward_test()
{
using boost::phoenix::copy_backward;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int output[4];
int* output_end = output + 3;
BOOST_TEST(
copy_backward(arg1, arg2)(array, output_end) == output);
BOOST_TEST(output[0] == 1);
BOOST_TEST(output[1] == 2);
BOOST_TEST(output[2] == 3);
return;
}
struct increment
{
int operator()(
int i) const
{
return i+1;
}
};
void transform_test()
{
using boost::phoenix::transform;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
using boost::phoenix::arg_names::arg3;
int array[] = {1,2,3};
BOOST_TEST(
transform(arg1, arg2, increment())(array, array) ==
array + 3);
BOOST_TEST(array[0] == 2);
BOOST_TEST(array[1] == 3);
BOOST_TEST(array[2] == 4);
int array2[] = {1,2,3};
BOOST_TEST(
boost::phoenix::transform(arg1, arg2, arg3, std::plus<int>())(array, array2, array) ==
array +3);
BOOST_TEST(array[0] == 2 + 1);
BOOST_TEST(array[1] == 3 + 2);
BOOST_TEST(array[2] == 4 + 3);
return;
}
void replace_test()
{
using boost::phoenix::replace;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
replace(arg1,2,4)(array);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 4);
BOOST_TEST(array[2] == 3);
return;
}
void replace_if_test()
{
using boost::phoenix::replace_if;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
replace_if(arg1, even(), 4)(array);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 4);
BOOST_TEST(array[2] == 3);
return;
}
void replace_copy_test()
{
using boost::phoenix::replace_copy;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int input[] = {1,2,3};
int output[3];
replace_copy(arg1, arg2, 2, 4)(input, output);
BOOST_TEST(output[0] == 1);
BOOST_TEST(output[1] == 4);
BOOST_TEST(output[2] == 3);
return;
}
void replace_copy_if_test()
{
using boost::phoenix::replace_copy_if;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int input[] = {1,2,3};
int output[3];
replace_copy_if(arg1, arg2, even(), 4)(input, output);
BOOST_TEST(output[0] == 1);
BOOST_TEST(output[1] == 4);
BOOST_TEST(output[2] == 3);
return;
}
void fill_test()
{
using boost::phoenix::fill;
using boost::phoenix::arg_names::arg1;
int array[] = {0,0,0};
fill(arg1, 1)(array);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 1);
BOOST_TEST(array[2] == 1);
return;
}
void fill_n_test()
{
using boost::phoenix::fill_n;
using boost::phoenix::arg_names::arg1;
int array[] = {0,0,0};
fill_n(arg1, 2, 1)(array);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 1);
BOOST_TEST(array[2] == 0);
return;
}
class int_seq
{
public:
int_seq() : val_(0) { }
int operator()()
{
return val_++;
}
private:
int val_;
};
void generate_test()
{
using boost::phoenix::generate;
using boost::phoenix::arg_names::arg1;
int array[3];
generate(arg1, int_seq())(array);
BOOST_TEST(array[0] == 0);
BOOST_TEST(array[1] == 1);
BOOST_TEST(array[2] == 2);
return;
}
void generate_n_test()
{
using boost::phoenix::generate_n;
using boost::phoenix::arg_names::arg1;
int array[] = {0,0,1};
generate_n(arg1, 2, int_seq())(array);
BOOST_TEST(array[0] == 0);
BOOST_TEST(array[1] == 1);
BOOST_TEST(array[2] == 1);
return;
}
void remove_test()
{
using boost::phoenix::remove;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
std::list<int> test_list(array, array + 3);
BOOST_TEST(boost::phoenix::remove(arg1, 2)(array) == array + 2);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 3);
BOOST_TEST(boost::phoenix::remove(arg1, 2)(test_list) == test_list.end());
std::list<int>::const_iterator it(test_list.begin());
BOOST_TEST(*it++ == 1);
BOOST_TEST(*it++ == 3);
return;
}
void remove_if_test()
{
using boost::phoenix::remove_if;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
std::list<int> test_list(array, array + 3);
BOOST_TEST(boost::phoenix::remove_if(arg1, even())(array) == array + 2);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 3);
BOOST_TEST(boost::phoenix::remove_if(arg1, even())(test_list) == test_list.end());
std::list<int>::const_iterator it(test_list.begin());
BOOST_TEST(*it++ == 1);
BOOST_TEST(*it++ == 3);
return;
}
void remove_copy_test()
{
using boost::phoenix::remove_copy;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int array2[2];
BOOST_TEST(boost::phoenix::remove_copy(arg1, arg2, 2)(array, array2) == array2 + 2);
BOOST_TEST(array2[0] == 1);
BOOST_TEST(array2[1] == 3);
return;
}
void remove_copy_if_test()
{
using boost::phoenix::remove_copy_if;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int array2[2];
BOOST_TEST(boost::phoenix::remove_copy_if(arg1, arg2, even())(array, array2) == array2 + 2);
BOOST_TEST(array2[0] == 1);
BOOST_TEST(array2[1] == 3);
return;
}
void unique_test()
{
using boost::phoenix::unique;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,2,3};
std::list<int> test_list(array, array + 4);
BOOST_TEST(unique(arg1)(array) == array + 3);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 2);
BOOST_TEST(array[2] == 3);
BOOST_TEST(unique(arg1)(test_list) == test_list.end());
std::list<int>::const_iterator it(test_list.begin());
BOOST_TEST(*it++ == 1);
BOOST_TEST(*it++ == 2);
BOOST_TEST(*it++ == 3);
int array2[] = {1,3,2};
std::list<int> test_list2(array2, array2 + 3);
BOOST_TEST(unique(arg1, mod_2_comparison())(array2) == array2 + 2);
BOOST_TEST(array2[0] == 1);
BOOST_TEST(array2[1] == 2);
BOOST_TEST(unique(arg1, mod_2_comparison())(test_list2) == test_list2.end());
std::list<int>::const_iterator jt(test_list2.begin());
BOOST_TEST(*jt++ == 1);
BOOST_TEST(*jt++ == 2);
return;
}
void unique_copy_test()
{
using boost::phoenix::unique_copy;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,2,3};
int out[3];
BOOST_TEST(unique_copy(arg1, arg2)(array, out) == out + 3);
BOOST_TEST(out[0] == 1);
BOOST_TEST(out[1] == 2);
BOOST_TEST(out[2] == 3);
int array2[] = {1,3,2};
int out2[2];
BOOST_TEST(unique_copy(arg1, arg2, mod_2_comparison())(array2, out2) == out2 + 2);
BOOST_TEST(out2[0] == 1);
BOOST_TEST(out2[1] == 2);
return;
}
void reverse_test()
{
using boost::phoenix::reverse;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
std::list<int> test_list(array, array + 3);
reverse(arg1)(array);
BOOST_TEST(array[0] == 3);
BOOST_TEST(array[1] == 2);
BOOST_TEST(array[2] == 1);
reverse(arg1)(test_list);
std::list<int>::iterator it(test_list.begin());
BOOST_TEST(*it++ == 3);
BOOST_TEST(*it++ == 2);
BOOST_TEST(*it++ == 1);
return;
}
void reverse_copy_test()
{
using boost::phoenix::reverse_copy;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int array2[3];
reverse_copy(arg1, arg2)(array, array2);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 2);
BOOST_TEST(array[2] == 3);
BOOST_TEST(array2[0] == 3);
BOOST_TEST(array2[1] == 2);
BOOST_TEST(array2[2] == 1);
return;
}
}
int main()
{
swap_test();
copy_test();
copy_backward_test();
transform_test();
replace_test();
replace_if_test();
replace_copy_test();
replace_copy_if_test();
fill_test();
fill_n_test();
generate_test();
generate_n_test();
remove_test();
remove_if_test();
remove_copy_test();
remove_copy_if_test();
unique_test();
unique_copy_test();
reverse_test();
reverse_copy_test();
boost::report_errors();
}

View File

@@ -0,0 +1,195 @@
/*=============================================================================
Copyright (c) 2005-2007 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
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 <functional>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/transformation.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <list>
namespace
{
struct even
{
bool operator()(const int i) const
{
return i % 2 == 0;
}
};
void rotate_test()
{
using boost::phoenix::rotate;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
rotate(arg1, array + 1)(array);
std::cout << array[0] << array[1] << array[2] << std::endl;
BOOST_TEST(array[0] == 2);
BOOST_TEST(array[1] == 3);
BOOST_TEST(array[2] == 1);
return;
}
void rotate_copy_test()
{
using boost::phoenix::rotate_copy;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int array2[3];
rotate_copy(arg1, array + 1, arg2)(array, array2);
BOOST_TEST(array2[0] == 2);
BOOST_TEST(array2[1] == 3);
BOOST_TEST(array2[2] == 1);
return;
}
void random_shuffle_test()
{
#ifndef BOOST_NO_CXX98_RANDOM_SHUFFLE
using boost::phoenix::random_shuffle;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
random_shuffle(arg1)(array);
const int first = array[0];
BOOST_TEST(first == 1 || first == 2 || first == 3);
const int second = array[1];
BOOST_TEST(second == 1 || second == 2 || second == 3);
BOOST_TEST(first != second);
const int third = array[2];
BOOST_TEST(third == 1 || third == 2 || third == 3);
BOOST_TEST(first != third && second != third);
return;
#endif
}
void partition_test()
{
using boost::phoenix::partition;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
int* const end = partition(arg1, even())(array);
BOOST_TEST(end == array + 1);
BOOST_TEST(array[0] % 2 == 0);
BOOST_TEST(array[1] % 2 != 0);
BOOST_TEST(array[2] % 2 != 0);
return;
}
void stable_partition_test()
{
using boost::phoenix::stable_partition;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
int* const end = stable_partition(arg1, even())(array);
BOOST_TEST(end == array + 1);
BOOST_TEST(array[0] == 2);
BOOST_TEST(array[1] == 1);
BOOST_TEST(array[2] == 3);
return;
}
void sort_test()
{
using boost::phoenix::sort;
using boost::phoenix::arg_names::arg1;
int array[] = {3,1,2};
std::list<int> test_list(array, array + 3);
sort(arg1)(array);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 2);
BOOST_TEST(array[2] == 3);
sort(arg1)(test_list);
std::list<int>::const_iterator it(test_list.begin());
BOOST_TEST(*it++ == 1);
BOOST_TEST(*it++ == 2);
BOOST_TEST(*it++ == 3);
boost::phoenix::sort(arg1, std::greater<int>())(array);
BOOST_TEST(array[0] == 3);
BOOST_TEST(array[1] == 2);
BOOST_TEST(array[2] == 1);
boost::phoenix::sort(arg1, std::greater<int>())(test_list);
std::list<int>::const_iterator jt(test_list.begin());
BOOST_TEST(*jt++ == 3);
BOOST_TEST(*jt++ == 2);
BOOST_TEST(*jt++ == 1);
return;
}
void stable_sort_test()
{
using boost::phoenix::stable_sort;
using boost::phoenix::arg_names::arg1;
int array[] = {3,1,2};
stable_sort(arg1)(array);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 2);
BOOST_TEST(array[2] == 3);
boost::phoenix::stable_sort(arg1, std::greater<int>())(array);
BOOST_TEST(array[0] == 3);
BOOST_TEST(array[1] == 2);
BOOST_TEST(array[2] == 1);
return;
}
void partial_sort_test()
{
using boost::phoenix::partial_sort;
using boost::phoenix::arg_names::arg1;
int array[] = {2,4,1,3};
partial_sort(arg1, array + 2)(array);
BOOST_TEST(array[0] == 1);
BOOST_TEST(array[1] == 2);
boost::phoenix::partial_sort(arg1, array + 2, std::greater<int>())(array);
BOOST_TEST(array[0] == 4);
BOOST_TEST(array[1] == 3);
return;
}
void partial_sort_copy_test()
{
using boost::phoenix::partial_sort_copy;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {2,4,1,3};
int array2[2];
partial_sort_copy(arg1, arg2)(array, array2);
BOOST_TEST(array2[0] == 1);
BOOST_TEST(array2[1] == 2);
boost::phoenix::partial_sort_copy(arg1, arg2, std::greater<int>())(array, array2);
BOOST_TEST(array2[0] == 4);
BOOST_TEST(array2[1] == 3);
return;
}
}
int main()
{
rotate_test();
rotate_copy_test();
random_shuffle_test();
partition_test();
stable_partition_test();
sort_test();
stable_sort_test();
partial_sort_test();
partial_sort_copy_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,187 @@
/*=============================================================================
Copyright (c) 2005-2007 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
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 <functional>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/transformation.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <list>
namespace
{
void nth_element_test()
{
using boost::phoenix::nth_element;
using boost::phoenix::arg_names::arg1;
int array[] = {5,1,4,3,2};
nth_element(arg1, array + 2)(array);
BOOST_TEST(array[0] < 3);
BOOST_TEST(array[1] < 3);
BOOST_TEST(array[2] == 3);
BOOST_TEST(array[3] > 3);
BOOST_TEST(array[4] > 3);
boost::phoenix::nth_element(arg1, array + 2, std::greater<int>())(array);
BOOST_TEST(array[0] > 3);
BOOST_TEST(array[1] > 3);
BOOST_TEST(array[2] == 3);
BOOST_TEST(array[3] < 3);
BOOST_TEST(array[4] < 3);
return;
}
void merge_test()
{
using boost::phoenix::merge;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
using boost::phoenix::arg_names::arg3;
int array[] = {1,2,3};
int array2[] = {2,3,4};
int output[6];
BOOST_TEST(merge(arg1, arg2, arg3)(array, array2, output) == output + 6);
int expected_result[] = {1,2,2,3,3,4};
BOOST_TEST(std::equal(output, output + 6, expected_result));
int array3[] = {5,4,3};
int array4[] = {3,2,1};
int output2[6];
BOOST_TEST(boost::phoenix::merge(arg1, arg2, arg3, std::greater<int>())(array3, array4, output2) ==
output2 + 6);
int expected_result2[] = {5,4,3,3,2,1};
BOOST_TEST(std::equal(output2, output2 + 6, expected_result2));
return;
}
void inplace_merge_test()
{
using boost::phoenix::inplace_merge;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3,2,3,4};
inplace_merge(arg1, array + 3)(array);
int expected_result[] = {1,2,2,3,3,4};
BOOST_TEST(std::equal(array, array + 6, expected_result));
int array2[] = {5,4,3,4,3,2};
boost::phoenix::inplace_merge(arg1, array2 + 3, std::greater<int>())(array2);
int expected_result2[] = {5,4,4,3,3,2};
BOOST_TEST(std::equal(array2, array2 + 6, expected_result2));
return;
}
void set_union_test()
{
using boost::phoenix::set_union;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
using boost::phoenix::arg_names::arg3;
int array[] = {1,2,3};
int array2[] = {2,3,4};
int output[4];
BOOST_TEST(set_union(arg1, arg2, arg3)(array, array2, output) == output + 4);
int expected_result[] = {1,2,3,4};
BOOST_TEST(std::equal(output, output + 4, expected_result));
int array3[] = {3,2,1};
int array4[] = {4,3,2};
int output2[4];
BOOST_TEST(boost::phoenix::set_union(arg1, arg2, arg3, std::greater<int>())
(array3, array4, output2) ==
output2 + 4);
int expected_result2[] = {4,3,2,1};
BOOST_TEST(std::equal(output2, output2 + 4, expected_result2));
return;
}
void set_intersection_test()
{
using boost::phoenix::set_intersection;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
using boost::phoenix::arg_names::arg3;
int array[] = {1,2,3};
int array2[] = {2,3,4};
int output[2];
BOOST_TEST(set_intersection(arg1, arg2, arg3)(array, array2, output) == output + 2);
int expected_result[] = {2,3};
BOOST_TEST(std::equal(output, output + 2, expected_result));
int array3[] = {3,2,1};
int array4[] = {4,3,2};
int output2[2];
BOOST_TEST(boost::phoenix::set_intersection(arg1, arg2, arg3, std::greater<int>())
(array3, array4, output2) ==
output2 + 2);
int expected_result2[] = {3,2};
BOOST_TEST(std::equal(output2, output2 + 2, expected_result2));
return;
}
void set_difference_test()
{
using boost::phoenix::set_difference;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
using boost::phoenix::arg_names::arg3;
int array[] = {1,2,3};
int array2[] = {2,3,4};
int output[1];
BOOST_TEST(set_difference(arg1, arg2, arg3)(array, array2, output) == output + 1);
int expected_result[] = {1};
BOOST_TEST(std::equal(output, output + 1, expected_result));
int array3[] = {3,2,1};
int array4[] = {4,3,2};
int output2[1];
BOOST_TEST(boost::phoenix::set_difference(arg1, arg2, arg3, std::greater<int>())
(array3, array4, output2) ==
output2 + 1);
int expected_result2[] = {1};
BOOST_TEST(std::equal(output2, output2 + 1, expected_result2));
return;
}
void set_symmetric_difference_test()
{
using boost::phoenix::set_symmetric_difference;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
using boost::phoenix::arg_names::arg3;
int array[] = {1,2,3};
int array2[] = {2,3,4};
int output[2];
BOOST_TEST(set_symmetric_difference(arg1, arg2, arg3)(array, array2, output) == output + 2);
int expected_result[] = {1,4};
BOOST_TEST(std::equal(output, output + 2, expected_result));
int array3[] = {3,2,1};
int array4[] = {4,3,2};
int output2[2];
BOOST_TEST(boost::phoenix::set_symmetric_difference(arg1, arg2, arg3, std::greater<int>())
(array3, array4, output2) ==
output2 + 2);
int expected_result2[] = {4,1};
BOOST_TEST(std::equal(output2, output2 + 2, expected_result2));
return;
}
}
int main()
{
nth_element_test();
merge_test();
inplace_merge_test();
set_union_test();
set_intersection_test();
set_difference_test();
set_symmetric_difference_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,159 @@
/*=============================================================================
Copyright (c) 2005-2007 Dan Marsden
Copyright (c) 2005-2007 Joel de Guzman
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/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/transformation.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <vector>
#include <functional>
#include <algorithm>
namespace
{
void heap_test()
{
using boost::phoenix::make_heap;
using boost::phoenix::pop_heap;
using boost::phoenix::push_heap;
using boost::phoenix::sort_heap;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2,3};
std::vector<int> vec(array, array + 3);
boost::phoenix::make_heap(arg1)(vec);
vec.push_back(5);
boost::phoenix::push_heap(arg1)(vec);
vec.push_back(4);
boost::phoenix::push_heap(arg1)(vec);
boost::phoenix::pop_heap(arg1)(vec);
BOOST_TEST(vec.back() == 5);
vec.pop_back();
boost::phoenix::sort_heap(arg1)(vec);
int expected_result[] = {1,2,3,4};
BOOST_TEST(std::equal(vec.begin(), vec.end(), expected_result));
int array2[] = {3,2,1};
std::vector<int> vec2(array2, array2 + 3);
boost::phoenix::make_heap(arg1, std::greater<int>())(vec2);
vec2.push_back(5);
boost::phoenix::push_heap(arg1, std::greater<int>())(vec2);
vec2.push_back(4);
boost::phoenix::push_heap(arg1, std::greater<int>())(vec2);
boost::phoenix::pop_heap(arg1, std::greater<int>())(vec2);
BOOST_TEST(vec2.back() == 1);
vec2.pop_back();
boost::phoenix::sort_heap(arg1, std::greater<int>())(vec2);
int expected_result2[] = {5,4,3,2};
BOOST_TEST(std::equal(vec2.begin(), vec2.end(), expected_result2));
return;
}
void next_permutation_test()
{
using boost::phoenix::next_permutation;
using boost::phoenix::arg_names::arg1;
int array[] = {1,2};
int expected_result[] = {2,1};
int expected_result2[] = {1,2};
BOOST_TEST(next_permutation(arg1)(array));
BOOST_TEST(std::equal(array, array + 2, expected_result));
BOOST_TEST(!next_permutation(arg1)(array));
BOOST_TEST(std::equal(array, array + 2, expected_result2));
std::reverse(array, array + 2);
BOOST_TEST(boost::phoenix::next_permutation(arg1, std::greater<int>())(array));
BOOST_TEST(std::equal(array, array + 2, expected_result2));
BOOST_TEST(!boost::phoenix::next_permutation(arg1, std::greater<int>())(array));
BOOST_TEST(std::equal(array, array + 2, expected_result));
return;
}
void prev_permutation_test()
{
using boost::phoenix::prev_permutation;
using boost::phoenix::arg_names::arg1;
int array[] = {2,1};
int expected_result[] = {1,2};
int expected_result2[] = {2,1};
BOOST_TEST(prev_permutation(arg1)(array));
BOOST_TEST(std::equal(array, array + 2, expected_result));
BOOST_TEST(!prev_permutation(arg1)(array));
BOOST_TEST(std::equal(array, array + 2, expected_result2));
std::reverse(array, array + 2);
BOOST_TEST(boost::phoenix::prev_permutation(arg1, std::greater<int>())(array));
BOOST_TEST(std::equal(array, array + 2, expected_result2));
BOOST_TEST(!boost::phoenix::prev_permutation(arg1, std::greater<int>())(array));
BOOST_TEST(std::equal(array, array + 2, expected_result));
return;
}
void inner_product_test()
{
using boost::phoenix::inner_product;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int lhs[] = {1,2,3};
int rhs[] = {4,5,6};
BOOST_TEST(inner_product(arg1, arg2, 0)
(lhs, rhs) == 1*4 + 2*5 + 3*6);
BOOST_TEST(boost::phoenix::inner_product(arg1, arg2, 1, std::multiplies<int>(), std::minus<int>())
(lhs, rhs) == (1 - 4) * (2 - 5) * (3 - 6));
return;
}
void partial_sum_test()
{
using boost::phoenix::partial_sum;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int output[3];
BOOST_TEST(partial_sum(arg1, arg2)(array, output) == output + 3);
int expected_result[] = {1, 3, 6};
BOOST_TEST(std::equal(output, output + 3, expected_result));
BOOST_TEST(boost::phoenix::partial_sum(arg1, arg2, std::multiplies<int>())
(array, output) == output + 3);
int expected_result2[] = {1, 2, 6};
BOOST_TEST(std::equal(output, output + 3, expected_result2));
return;
}
void adjacent_difference_test()
{
using boost::phoenix::adjacent_difference;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int array[] = {1,2,3};
int output[3];
BOOST_TEST(adjacent_difference(arg1, arg2)(array, output) == output + 3);
int expected_result[] = {1, 1, 1};
BOOST_TEST(std::equal(output, output + 3, expected_result));
BOOST_TEST(boost::phoenix::adjacent_difference(arg1, arg2, std::plus<int>())
(array, output) == output + 3);
int expected_result2[] = {1, 3, 5};
BOOST_TEST(std::equal(output, output + 3, expected_result2));
return;
}
}
int main()
{
heap_test();
next_permutation_test();
prev_permutation_test();
inner_product_test();
partial_sum_test();
adjacent_difference_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,137 @@
/*=============================================================================
Copyright (c) 2001-2007 Joel de Guzman
Copyright (c) 2015 John Fletcher
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 <iostream>
#include <cmath>
#include <boost/detail/lightweight_test.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/phoenix/bind.hpp>
namespace phoenix = boost::phoenix;
using std::cout;
using std::pow;
struct test
{
typedef void result_type;
void
operator()() const
{
cout << "Test lazy functions...\n";
}
};
struct sqr
{
template <typename Sig>
struct result;
template <typename This, typename Arg>
struct result<This(Arg&)>
{
typedef Arg type;
};
template <typename Arg>
Arg
operator()(Arg n) const
{
return n * n;
}
};
struct fact
{
template <typename Sig>
struct result;
template <typename This, typename Arg>
struct result<This(Arg&)>
{
typedef Arg type;
};
template <typename Arg>
Arg
operator()(Arg n) const
{
return (n <= 0) ? 1 : n * (*this)(n-1);
}
};
struct power
{
template<typename Sig>
struct result;
template<typename This, typename Arg1, typename Arg2>
struct result<This(Arg1&, Arg2&)>
{
typedef Arg1 type;
};
template <typename Arg1, typename Arg2>
Arg1
operator()(Arg1 a, Arg2 b) const
{
return pow(a, b);
}
};
struct add
{
template <typename Sig>
struct result;
template <typename This, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
struct result<This(Arg1&, Arg2&, Arg3&, Arg4&)>
{
typedef Arg1 type;
};
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
Arg1
operator()(Arg1 a, Arg2 b, Arg3 c, Arg4 d) const
{
return a + b + c + d;
}
};
int
main()
{
using phoenix::bind;
using phoenix::ref;
using phoenix::arg_names::_1;
using phoenix::arg_names::arg1;
using phoenix::arg_names::arg2;
int i5 = 5;
double d5 = 5, d3 = 3;
test()();
BOOST_TEST(bind(sqr(), arg1)(i5) == (i5*i5));
BOOST_TEST(bind(fact(), 4)() == 24);
BOOST_TEST(bind(fact(), arg1)(i5) == 120);
BOOST_TEST((int)bind(power(), arg1, arg2)(d5, d3) == (int)std::pow(d5, d3));
BOOST_TEST((bind(sqr(), arg1) + 5)(i5) == ((i5*i5)+5));
BOOST_TEST(bind(add(), arg1, arg1, arg1, arg1)(i5) == (5+5+5+5));
int const ic5 = 5;
// testing consts
BOOST_TEST(bind(sqr(), arg1)(ic5) == (ic5*ic5));
// From Steven Watanabe
sqr s;
int x = 2;
int result = bind(ref(s), _1)(x);
BOOST_TEST(result == 4);
return boost::report_errors();
}

View File

@@ -0,0 +1,56 @@
/*=============================================================================
Copyright (c) 2001-2007 Joel de Guzman
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 <iostream>
#include <cmath>
#include <boost/detail/lightweight_test.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
namespace test
{
void
test()
{
std::cout << "Test binding functions...\n";
}
int
negate(int n)
{
return -n;
}
int
plus(int a, int b)
{
return a + b;
}
int
plus4(int a, int b, int c, int d)
{
return a + b + c + d;
}
}
int
main()
{
using boost::phoenix::bind;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
int a = 123;
int b = 256;
bind(test::test)();
BOOST_TEST(bind(test::negate, arg1)(a) == -a);
BOOST_TEST(bind(test::plus, arg1, arg2)(a, b) == a+b);
BOOST_TEST(bind(test::plus4, arg1, arg2, 3, 4)(a, b) == a+b+3+4);
return boost::report_errors();
}

View File

@@ -0,0 +1,77 @@
/*=============================================================================
Copyright (c) 2001-2007 Joel de Guzman
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 <iostream>
#include <cmath>
#include <boost/detail/lightweight_test.hpp>
#include <boost/noncopyable.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/phoenix/bind.hpp>
namespace test
{
struct x //: boost::noncopyable // test non-copyable (hold this by reference)
{
void
test() const
{
std::cout << "Test binding member functions...\n";
}
};
struct y //: boost::noncopyable // test non-copyable (hold this by reference)
{
int
negate(int n) const
{
return -n;
}
};
struct z //: boost::noncopyable // test non-copyable (hold this by reference)
{
int
plus(int a, int b) const
{
return a + b;
}
};
struct zz //: boost::noncopyable // test non-copyable (hold this by reference)
{
int
plus3(int a, int b, int c) const
{
return a + b + c;
}
};
}
int
main()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
using boost::phoenix::arg_names::arg1;
using boost::phoenix::arg_names::arg2;
using boost::phoenix::arg_names::arg3;
int a = 123;
int b = 256;
test::x x_;
test::y y_;
test::z z_;
test::zz zz_;
bind(&test::x::test, x_)();
BOOST_TEST(bind(&test::y::negate, y_, arg1)(a) == -a);
BOOST_TEST(bind(&test::z::plus, arg1, arg2, arg3)(z_, a, b) == a+b);
BOOST_TEST(bind(&test::zz::plus3, zz_, arg1, arg2, arg3)(a, b, a) == a+b+a);
BOOST_TEST(bind(&test::y::negate, &y_, 777)(a) == -777);
return boost::report_errors();
}

View File

@@ -0,0 +1,111 @@
/*=============================================================================
Copyright (c) 2001-2007 Joel de Guzman
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 <iostream>
#include <cmath>
#include <boost/noncopyable.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
namespace test
{
struct x //: boost::noncopyable // test non-copyable (hold this by reference)
{
int m;
};
struct xx {
int m;
};
}
template <typename T, typename F>
void
write_test(F f)
{
using boost::phoenix::arg_names::arg1;
using boost::phoenix::bind;
T x_;
bind(&T::m, f(x_))() = 122;
BOOST_TEST(x_.m == 122);
bind(&T::m, arg1)(f(x_)) = 123;
BOOST_TEST(x_.m == 123);
}
template <typename T, typename F>
void
read_test(F f)
{
using boost::phoenix::arg_names::arg1;
using boost::phoenix::bind;
T x_;
x_.m = 123;
BOOST_TEST(bind(&T::m, f(x_))() == 123);
BOOST_TEST(bind(&T::m, arg1)(f(x_)) == 123);
}
struct identity
{
template <typename T>
T&
operator()(T& t) const
{
return t;
}
};
struct constify
{
template <typename T>
T const&
operator()(T const& t) const
{
return t;
}
};
struct add_pointer
{
template <typename T>
T* /*const*/
operator()(T& t) const
{
return &t;
}
};
struct add_const_pointer
{
template <typename T>
const T* /*const*/
operator()(T const& t) const
{
return &t;
}
};
int
main()
{
write_test<test::x>(add_pointer());
write_test<test::xx>(add_pointer());
read_test<test::x>(identity());
read_test<test::x>(constify());
read_test<test::x>(add_pointer());
read_test<test::x>(add_const_pointer());
read_test<test::xx>(identity());
read_test<test::xx>(constify());
read_test<test::xx>(add_pointer());
read_test<test::xx>(add_const_pointer());
return boost::report_errors();
}

View File

@@ -0,0 +1,23 @@
/*=============================================================================
Copyright (c) 2001-2007 Joel de Guzman
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/phoenix/bind/bind_function.hpp>
#include <boost/phoenix/core/argument.hpp>
#include <iostream>
using namespace boost::phoenix;
using namespace boost::phoenix::placeholders;
void foo(int n)
{
std::cout << n << std::endl;
}
int main()
{
bind(&foo, arg1)(4);
}

View File

@@ -0,0 +1,78 @@
// bll_and_function.cpp - The Boost Lambda Library -----------------------
//
// 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
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// test using BLL and boost::function
#include <boost/core/lightweight_test.hpp>
/*
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/bind.hpp"
#include "boost/lambda/algorithm.hpp"
*/
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/phoenix/scope.hpp>
#include <boost/phoenix/stl/algorithm/iteration.hpp>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <iostream>
namespace phoenix = boost::phoenix;
void test_foreach() {
using phoenix::placeholders::_1;
using phoenix::ref;
using phoenix::lambda;
int a[10][20];
int sum = 0;
//for_each(arg1, for_each_tester())(array).value_;
// Was:
// std::for_each(a, a + 10,
// bind(ll::for_each(), _1, _1 + 20,
// protect((_1 = var(sum), ++var(sum)))));
// var replaced with ref, protect(..) replaced with lambda[..], no need for bind
// phoenix algorithms are range based
std::for_each(a, a + 10,
phoenix::for_each(_1, lambda[_1 = ref(sum), ++ref(sum)]));
/*phoenix::bind(phoenix::for_each, _1,
lambda[_1 = ref(sum), ++ref(sum)]));*/
sum = 0;
// Was:
// std::for_each(a, a + 10,
// bind(ll::for_each(), _1, _1 + 20,
// protect((sum += _1))));
//
std::for_each(a, a + 10,
phoenix::for_each( _1,
lambda[(ref(sum) += _1)]));
BOOST_TEST_EQ(sum, (199 + 1)/ 2 * 199);
}
// More tests needed (for all algorithms)
int main()
{
test_foreach();
return boost::report_errors();
}

View File

@@ -0,0 +1,433 @@
// bind_tests_advanced.cpp -- The Boost Lambda Library ------------------
//
// 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
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// -----------------------------------------------------------------------
#include <boost/core/lightweight_test.hpp>
/*
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/bind.hpp"
*/
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/phoenix/scope.hpp>
#include "boost/any.hpp"
#include "boost/type_traits/is_reference.hpp"
#include "boost/mpl/assert.hpp"
#include "boost/mpl/if.hpp"
#include <iostream>
#include <functional>
#include <algorithm>
namespace phoenix = boost::phoenix;
int sum_0() { return 0; }
int sum_1(int a) { return a; }
int sum_2(int a, int b) { return a+b; }
int product_2(int a, int b) { return a*b; }
// unary function that returns a pointer to a binary function
typedef int (*fptr_type)(int, int);
fptr_type sum_or_product(bool x) {
return x ? sum_2 : product_2;
}
// a nullary functor that returns a pointer to a unary function that
// returns a pointer to a binary function.
struct which_one {
typedef fptr_type (*result_type)(bool x);
// Was:
// template <class T> struct sig { typedef result_type type; };
// phoenix follows the standard result_of protocol
result_type operator()() const { return sum_or_product; }
};
void test_nested_binds()
{
using phoenix::bind;
using phoenix::placeholders::_1;
using phoenix::placeholders::_2;
using phoenix::placeholders::_3;
int j = 2; int k = 3;
// bind calls can be nested (the target function can be a lambda functor)
// The interpretation is, that the innermost lambda functor returns something
// that is bindable (another lambda functor, function pointer ...)
bool condition;
condition = true;
BOOST_TEST_EQ(bind(bind(&sum_or_product, _1), 1, 2)(condition), 3);
BOOST_TEST_EQ(bind(bind(&sum_or_product, _1), _2, _3)(condition, j, k), 5);
condition = false;
BOOST_TEST_EQ(bind(bind(&sum_or_product, _1), 1, 2)(condition), 2);
BOOST_TEST_EQ(bind(bind(&sum_or_product, _1), _2, _3)(condition, j, k), 6);
which_one wo;
BOOST_TEST_EQ(bind(bind(bind(wo), _1), _2, _3)(condition, j, k), 6);
return;
}
// unlambda -------------------------------------------------
// Sometimes it may be necessary to prevent the argument substitution of
// taking place. For example, we may end up with a nested bind expression
// inadvertently when using the target function is received as a parameter
template<class F>
int call_with_100(const F& f) {
// bind(f, _1)(make_const(100));
// This would result in;
// bind(_1 + 1, _1)(make_const(100)) , which would be a compile time error
//return bl::bind(unlambda(f), _1)(make_const(100));
return 5;
// for other functors than lambda functors, unlambda has no effect
// (except for making them const)
}
template<class F>
int call_with_101(const F& f) {
//return bind(unlambda(f), _1)(make_const(101));
return 5;
}
void test_unlambda() {
using phoenix::placeholders::_1;
using phoenix::placeholders::_2;
int i = 1;
//BOOST_TEST_EQ(unlambda(_1 + _2)(i, i), 2);
//BOOST_TEST_EQ(unlambda(++var(i))(), 2);
//BOOST_TEST_EQ(call_with_100(_1 + 1), 101);
//BOOST_TEST_EQ(call_with_101(_1 + 1), 102);
//BOOST_TEST_EQ(call_with_100(bl::bind(std_functor(std::bind1st(std::plus<int>(), 1)), _1)), 101);
// Was:
// std_functor insturcts LL that the functor defines a result_type typedef
// rather than a sig template.
//bl::bind(std_functor(std::plus<int>()), _1, _2)(i, i);
// Standard functors can be used without any further action needed.
phoenix::bind(std::plus<int>(), _1, _2)(i, i);
}
// protect ------------------------------------------------------------
// protect protects a lambda functor from argument substitution.
// protect is useful e.g. with nested stl algorithm calls.
#if 0
namespace ll {
struct for_each {
// Was:
// note, std::for_each returns it's last argument
// We want the same behaviour from our ll::for_each.
// However, the functor can be called with any arguments, and
// the return type thus depends on the argument types.
// 1. Provide a sig class member template:
// The return type deduction system instantiate this class as:
// sig<Args>::type, where Args is a boost::tuples::cons-list
// The head type is the function object type itself
// cv-qualified (so it is possilbe to provide different return types
// for differently cv-qualified operator()'s.
// The tail type is the list of the types of the actual arguments the
// function was called with.
// So sig should contain a typedef type, which defines a mapping from
// the operator() arguments to its return type.
// Note, that it is possible to provide different sigs for the same functor
// if the functor has several operator()'s, even if they have different
// number of arguments.
// Note, that the argument types in Args are guaranteed to be non-reference
// types, but they can have cv-qualifiers.
// template <class Args>
//struct sig {
// typedef typename boost::remove_const<
// typename boost::tuples::element<3, Args>::type
// >::type type;
//};
// We follow the result_of protocol ...
template <typename Sig>
struct result;
template <typename This, typename A, typename B, typename C>
struct result<This(A&,B&,C&)>
{typedef C type;};
template <class A, class B, class C>
C
operator()(const A& a, const B& b, const C& c) const
{ return std::for_each(a, b, c);}
};
} // end of ll namespace
#endif
void test_protect()
{
using phoenix::placeholders::_1;
int i = 0;
int b[3][5];
int* a[3];
for(int j=0; j<3; ++j) a[j] = b[j];
// Was:
//std::for_each(a, a+3,
// bind(ll::for_each(), _1, _1 + 5, protect(_1 = ++var(i))));
#if 0
std::for_each(a, a+3,
phoenix::bind(ll::for_each(), _1, _1 + 5, phoenix::lambda[_1 = ++phoenix::ref(i)]));
#endif
// This is how you could output the values (it is uncommented, no output
// from a regression test file):
// std::for_each(a, a+3,
// bind(ll::for_each(), _1, _1 + 5,
// std::cout << constant("\nLine ") << (&_1 - a) << " : "
// << protect(_1)
// )
// );
int sum = 0;
// Was:
//std::for_each(a, a+3,
// bind(ll::for_each(), _1, _1 + 5,
// protect(sum += _1))
// );
#if 0
std::for_each(a, a+3,
phoenix::bind(ll::for_each(), _1, _1 + 5,
phoenix::lambda[phoenix::ref(sum) += _1])
);
BOOST_TEST_EQ(sum, (1+15)*15/2);
#endif
sum = 0;
// Was:
//std::for_each(a, a+3,
// bind(ll::for_each(), _1, _1 + 5,
// sum += 1 + protect(_1)) // add element count
// );
#if 0
std::for_each(a, a+3,
phoenix::bind(ll::for_each(), _1, _1 + 5,
phoenix::ref(sum) += 1 + phoenix::lambda[_1]) // add element count
);
BOOST_TEST_EQ(sum, (1+15)*15/2 + 15);
#endif
// Was:
//(1 + protect(_1))(sum);
(1 + phoenix::lambda[_1])(sum);
int k = 0;
// Was:
//((k += constant(1)) += protect(constant(2)))();
((phoenix::ref(k) += 1) += phoenix::lambda[phoenix::cref(2)])();
BOOST_TEST_EQ(k, 1);
k = 0;
// Was:
//((k += constant(1)) += protect(constant(2)))()();
//((phoenix::ref(k) += 1) += phoenix::lambda[std::cout << phoenix::cref("ok ...\n"), phoenix::cref(2)])()();
//std::cout << ((phoenix::ref(k) += 1) + phoenix::lambda[phoenix::cref(2)])()() << "\n";
((phoenix::ref(k) += 1) += 2)();
std::cout << k << "\n";
BOOST_TEST_EQ(k, 3);
// note, the following doesn't work:
// ((var(k) = constant(1)) = protect(constant(2)))();
// (var(k) = constant(1))() returns int& and thus the
// second assignment fails.
// We should have something like:
// bind(var, var(k) = constant(1)) = protect(constant(2)))();
// But currently var is not bindable.
// The same goes with ret. A bindable ret could be handy sometimes as well
// (protect(std::cout << _1), std::cout << _1)(i)(j); does not work
// because the comma operator tries to store the result of the evaluation
// of std::cout << _1 as a copy (and you can't copy std::ostream).
// something like this:
// (protect(std::cout << _1), bind(ref, std::cout << _1))(i)(j);
// the stuff below works, but we do not want extra output to
// cout, must be changed to stringstreams but stringstreams do not
// work due to a bug in the type deduction. Will be fixed...
#if 0
// But for now, ref is not bindable. There are other ways around this:
int x = 1, y = 2;
(protect(std::cout << _1), (std::cout << _1, 0))(x)(y);
// added one dummy value to make the argument to comma an int
// instead of ostream&
// Note, the same problem is more apparent without protect
// (std::cout << 1, std::cout << constant(2))(); // does not work
(boost::ref(std::cout << 1), std::cout << constant(2))(); // this does
#endif
}
void test_lambda_functors_as_arguments_to_lambda_functors() {
using phoenix::bind;
using phoenix::cref;
using phoenix::placeholders::_1;
using phoenix::placeholders::_2;
using phoenix::placeholders::_3;
// lambda functor is a function object, and can therefore be used
// as an argument to another lambda functors function call object.
// Note however, that the argument/type substitution is not entered again.
// This means, that something like this will not work:
(_1 + _2)(_1, cref(7));
(_1 + _2)(bind(&sum_0), cref(7));
// or it does work, but the effect is not to call
// 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_EQ((_1 + _2)(bind(&sum_0), cref(7))(), 7);
int i = 3, j = 12;
BOOST_TEST_EQ((_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
// defint the sig template, or then
// the return type must be defined within the bind call. Lambda functors
// do define the sig template, so if the return type deduction system
// covers the case, there is no need to specify the return type
// explicitly.
int a = 5, b = 6;
// Let type deduction find out the return type
//BOOST_TEST_EQ(bind(_1, _2, _3)(unlambda(_1 + _2), a, b), 11);
//specify it yourself:
BOOST_TEST_EQ(bind(_1, _2, _3)(_1 + _2, a, b), 11);
bind(_1,1.0)(_1+_1);
return;
}
/*
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_TEST_EQ(bind(func<int>(), 1)(), 1);
BOOST_TEST_EQ(bind(func<const int>(), _1)(static_cast<const int&>(i)), 1);
BOOST_TEST_EQ(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_TEST_EQ(bind(&base::foo, var(b))(), 1);
BOOST_TEST_EQ(bind(&base::foo, *_1)(&b), 1);
}
*/
int main()
{
test_nested_binds();
test_unlambda();
test_protect();
test_lambda_functors_as_arguments_to_lambda_functors();
//test_sig();
//test_abstract();
return boost::report_errors();
}

View File

@@ -0,0 +1,170 @@
// bind_tests_simple.cpp -- The Boost Lambda Library ------------------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/bind.hpp"
#include <iostream>
using namespace boost::lambda;
int sum_of_args_0() { return 0; }
int sum_of_args_1(int a) { return a; }
int sum_of_args_2(int a, int b) { return a+b; }
int sum_of_args_3(int a, int b, int c) { return a+b+c; }
int sum_of_args_4(int a, int b, int c, int d) { return a+b+c+d; }
int sum_of_args_5(int a, int b, int c, int d, int e) { return a+b+c+d+e; }
int sum_of_args_6(int a, int b, int c, int d, int e, int f) { return a+b+c+d+e+f; }
int sum_of_args_7(int a, int b, int c, int d, int e, int f, int g) { return a+b+c+d+e+f+g; }
int sum_of_args_8(int a, int b, int c, int d, int e, int f, int g, int h) { return a+b+c+d+e+f+g+h; }
int sum_of_args_9(int a, int b, int c, int d, int e, int f, int g, int h, int i) { return a+b+c+d+e+f+g+h+i; }
// ----------------------------
class A {
int i;
public:
A(int n) : i(n) {};
int add(const int& j) { return i + j; }
int add2(int a1, int a2) { return i + a1 + a2; }
int add3(int a1, int a2, int a3) { return i + a1 + a2 + a3; }
int add4(int a1, int a2, int a3, int a4) { return i + a1 + a2 + a3 + a4; }
int add5(int a1, int a2, int a3, int a4, int a5)
{ return i + a1 + a2 + a3 + a4 + a5; }
int add6(int a1, int a2, int a3, int a4, int a5, int a6)
{ return i + a1 + a2 + a3 + a4 + a5 + a6; }
int add7(int a1, int a2, int a3, int a4, int a5, int a6, int a7)
{ return i + a1 + a2 + a3 + a4 + a5 + a6 + a7; }
int add8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
{ return i + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8; }
};
void test_member_functions()
{
using boost::ref;
A a(10);
int i = 1;
BOOST_TEST_EQ(bind(&A::add, ref(a), _1)(i), 11);
BOOST_TEST_EQ(bind(&A::add, &a, _1)(i), 11);
BOOST_TEST_EQ(bind(&A::add, _1, 1)(a), 11);
BOOST_TEST_EQ(bind(&A::add, _1, 1)(make_const(&a)), 11);
BOOST_TEST_EQ(bind(&A::add2, _1, 1, 1)(a), 12);
BOOST_TEST_EQ(bind(&A::add3, _1, 1, 1, 1)(a), 13);
BOOST_TEST_EQ(bind(&A::add4, _1, 1, 1, 1, 1)(a), 14);
BOOST_TEST_EQ(bind(&A::add5, _1, 1, 1, 1, 1, 1)(a), 15);
BOOST_TEST_EQ(bind(&A::add6, _1, 1, 1, 1, 1, 1, 1)(a), 16);
BOOST_TEST_EQ(bind(&A::add7, _1, 1, 1, 1, 1, 1, 1, 1)(a), 17);
BOOST_TEST_EQ(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);
}
int main()
{
int i = 1; int j = 2; int k = 3;
int result;
// bind all parameters
BOOST_TEST_EQ(bind(&sum_of_args_0)(), 0);
BOOST_TEST_EQ(bind(&sum_of_args_1, 1)(), 1);
BOOST_TEST_EQ(bind(&sum_of_args_2, 1, 2)(), 3);
BOOST_TEST_EQ(bind(&sum_of_args_3, 1, 2, 3)(), 6);
BOOST_TEST_EQ(bind(&sum_of_args_4, 1, 2, 3, 4)(), 10);
BOOST_TEST_EQ(bind(&sum_of_args_5, 1, 2, 3, 4, 5)(), 15);
BOOST_TEST_EQ(bind(&sum_of_args_6, 1, 2, 3, 4, 5, 6)(), 21);
BOOST_TEST_EQ(bind(&sum_of_args_7, 1, 2, 3, 4, 5, 6, 7)(), 28);
BOOST_TEST_EQ(bind(&sum_of_args_8, 1, 2, 3, 4, 5, 6, 7, 8)(), 36);
BOOST_TEST_EQ(bind(&sum_of_args_9, 1, 2, 3, 4, 5, 6, 7, 8, 9)(), 45);
// first parameter open
BOOST_TEST_EQ(bind(&sum_of_args_0)(), 0);
BOOST_TEST_EQ(bind(&sum_of_args_1, _1)(i), 1);
BOOST_TEST_EQ(bind(&sum_of_args_2, _1, 2)(i), 3);
BOOST_TEST_EQ(bind(&sum_of_args_3, _1, 2, 3)(i), 6);
BOOST_TEST_EQ(bind(&sum_of_args_4, _1, 2, 3, 4)(i), 10);
BOOST_TEST_EQ(bind(&sum_of_args_5, _1, 2, 3, 4, 5)(i), 15);
BOOST_TEST_EQ(bind(&sum_of_args_6, _1, 2, 3, 4, 5, 6)(i), 21);
BOOST_TEST_EQ(bind(&sum_of_args_7, _1, 2, 3, 4, 5, 6, 7)(i), 28);
BOOST_TEST_EQ(bind(&sum_of_args_8, _1, 2, 3, 4, 5, 6, 7, 8)(i), 36);
BOOST_TEST_EQ(bind(&sum_of_args_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i), 45);
// two open arguments
BOOST_TEST_EQ(bind(&sum_of_args_0)(), 0);
BOOST_TEST_EQ(bind(&sum_of_args_1, _1)(i), 1);
BOOST_TEST_EQ(bind(&sum_of_args_2, _1, _2)(i, j), 3);
BOOST_TEST_EQ(bind(&sum_of_args_3, _1, _2, 3)(i, j), 6);
BOOST_TEST_EQ(bind(&sum_of_args_4, _1, _2, 3, 4)(i, j), 10);
BOOST_TEST_EQ(bind(&sum_of_args_5, _1, _2, 3, 4, 5)(i, j), 15);
BOOST_TEST_EQ(bind(&sum_of_args_6, _1, _2, 3, 4, 5, 6)(i, j), 21);
BOOST_TEST_EQ(bind(&sum_of_args_7, _1, _2, 3, 4, 5, 6, 7)(i, j), 28);
BOOST_TEST_EQ(bind(&sum_of_args_8, _1, _2, 3, 4, 5, 6, 7, 8)(i, j), 36);
BOOST_TEST_EQ(bind(&sum_of_args_9, _1, _2, 3, 4, 5, 6, 7, 8, 9)(i, j), 45);
// three open arguments
BOOST_TEST_EQ(bind(&sum_of_args_0)(), 0);
BOOST_TEST_EQ(bind(&sum_of_args_1, _1)(i), 1);
BOOST_TEST_EQ(bind(&sum_of_args_2, _1, _2)(i, j), 3);
BOOST_TEST_EQ(bind(&sum_of_args_3, _1, _2, _3)(i, j, k), 6);
BOOST_TEST_EQ(bind(&sum_of_args_4, _1, _2, _3, 4)(i, j, k), 10);
BOOST_TEST_EQ(bind(&sum_of_args_5, _1, _2, _3, 4, 5)(i, j, k), 15);
BOOST_TEST_EQ(bind(&sum_of_args_6, _1, _2, _3, 4, 5, 6)(i, j, k), 21);
BOOST_TEST_EQ(bind(&sum_of_args_7, _1, _2, _3, 4, 5, 6, 7)(i, j, k), 28);
BOOST_TEST_EQ(bind(&sum_of_args_8, _1, _2, _3, 4, 5, 6, 7, 8)(i, j, k), 36);
BOOST_TEST_EQ(bind(&sum_of_args_9, _1, _2, _3, 4, 5, 6, 7, 8, 9)(i, j, k), 45);
// function compositions with bind
BOOST_TEST_EQ(bind(&sum_of_args_3, bind(&sum_of_args_2, _1, 2), 2, 3)(i), 8);
BOOST_TEST_EQ(
bind(&sum_of_args_9,
bind(&sum_of_args_0), // 0
bind(&sum_of_args_1, _1), // 1
bind(&sum_of_args_2, _1, _2), // 3
bind(&sum_of_args_3, _1, _2, _3), // 6
bind(&sum_of_args_4, _1, _2, _3, 4), // 10
bind(&sum_of_args_5, _1, _2, _3, 4, 5), // 15
bind(&sum_of_args_6, _1, _2, _3, 4, 5, 6), // 21
bind(&sum_of_args_7, _1, _2, _3, 4, 5, 6, 7), // 28
bind(&sum_of_args_8, _1, _2, _3, 4, 5, 6, 7, 8) // 36
)(i, j, k), 120);
// deeper nesting
result =
bind(&sum_of_args_1, // 12
bind(&sum_of_args_4, // 12
bind(&sum_of_args_2, // 3
bind(&sum_of_args_1, // 1
bind(&sum_of_args_1, _1) // 1
),
_2),
_2,
_3,
4)
)(i, j, k);
BOOST_TEST_EQ(result, 12);
test_member_functions();
return boost::report_errors();
}

View File

@@ -0,0 +1,147 @@
// bind_tests_simple.cpp -- The Boost Lambda Library ------------------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/bind.hpp"
#include <iostream>
using namespace boost::lambda;
int sum_of_args_0() { return 0; }
int sum_of_args_1(int a) { return a; }
int sum_of_args_2(int a, int b) { return a+b; }
int sum_of_args_3(int a, int b, int c) { return a+b+c; }
int sum_of_args_4(int a, int b, int c, int d) { return a+b+c+d; }
int sum_of_args_5(int a, int b, int c, int d, int e) { return a+b+c+d+e; }
int sum_of_args_6(int a, int b, int c, int d, int e, int f) { return a+b+c+d+e+f; }
int sum_of_args_7(int a, int b, int c, int d, int e, int f, int g) { return a+b+c+d+e+f+g; }
int sum_of_args_8(int a, int b, int c, int d, int e, int f, int g, int h) { return a+b+c+d+e+f+g+h; }
int sum_of_args_9(int a, int b, int c, int d, int e, int f, int g, int h, int i) { return a+b+c+d+e+f+g+h+i; }
// ----------------------------
class A {
int i;
public:
A(int n) : i(n) {};
int add(const int& j) { return i + j; }
};
void test_member_functions()
{
using boost::ref;
A a(10);
int i = 1;
BOOST_TEST_EQ(bind(&A::add, ref(a), _1)(i), 11);
BOOST_TEST_EQ(bind(&A::add, &a, _1)(i), 11);
BOOST_TEST_EQ(bind(&A::add, _1, 1)(a), 11);
BOOST_TEST_EQ(bind(&A::add, _1, 1)(make_const(&a)), 11);
// This should fail, as lambda functors store arguments as const
// bind(&A::add, a, _1);
}
int main()
{
int i = 1; int j = 2; int k = 3;
int result;
// bind all parameters
BOOST_TEST_EQ(bind(sum_of_args_0)(), 0);
BOOST_TEST_EQ(bind(sum_of_args_1, 1)(), 1);
BOOST_TEST_EQ(bind(sum_of_args_2, 1, 2)(), 3);
BOOST_TEST_EQ(bind(sum_of_args_3, 1, 2, 3)(), 6);
BOOST_TEST_EQ(bind(sum_of_args_4, 1, 2, 3, 4)(), 10);
BOOST_TEST_EQ(bind(sum_of_args_5, 1, 2, 3, 4, 5)(), 15);
BOOST_TEST_EQ(bind(sum_of_args_6, 1, 2, 3, 4, 5, 6)(), 21);
BOOST_TEST_EQ(bind(sum_of_args_7, 1, 2, 3, 4, 5, 6, 7)(), 28);
BOOST_TEST_EQ(bind(sum_of_args_8, 1, 2, 3, 4, 5, 6, 7, 8)(), 36);
BOOST_TEST_EQ(bind(sum_of_args_9, 1, 2, 3, 4, 5, 6, 7, 8, 9)(), 45);
// first parameter open
BOOST_TEST_EQ(bind(sum_of_args_0)(), 0);
BOOST_TEST_EQ(bind(sum_of_args_1, _1)(i), 1);
BOOST_TEST_EQ(bind(sum_of_args_2, _1, 2)(i), 3);
BOOST_TEST_EQ(bind(sum_of_args_3, _1, 2, 3)(i), 6);
BOOST_TEST_EQ(bind(sum_of_args_4, _1, 2, 3, 4)(i), 10);
BOOST_TEST_EQ(bind(sum_of_args_5, _1, 2, 3, 4, 5)(i), 15);
BOOST_TEST_EQ(bind(sum_of_args_6, _1, 2, 3, 4, 5, 6)(i), 21);
BOOST_TEST_EQ(bind(sum_of_args_7, _1, 2, 3, 4, 5, 6, 7)(i), 28);
BOOST_TEST_EQ(bind(sum_of_args_8, _1, 2, 3, 4, 5, 6, 7, 8)(i), 36);
BOOST_TEST_EQ(bind(sum_of_args_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i), 45);
// two open arguments
BOOST_TEST_EQ(bind(sum_of_args_0)(), 0);
BOOST_TEST_EQ(bind(sum_of_args_1, _1)(i), 1);
BOOST_TEST_EQ(bind(sum_of_args_2, _1, _2)(i, j), 3);
BOOST_TEST_EQ(bind(sum_of_args_3, _1, _2, 3)(i, j), 6);
BOOST_TEST_EQ(bind(sum_of_args_4, _1, _2, 3, 4)(i, j), 10);
BOOST_TEST_EQ(bind(sum_of_args_5, _1, _2, 3, 4, 5)(i, j), 15);
BOOST_TEST_EQ(bind(sum_of_args_6, _1, _2, 3, 4, 5, 6)(i, j), 21);
BOOST_TEST_EQ(bind(sum_of_args_7, _1, _2, 3, 4, 5, 6, 7)(i, j), 28);
BOOST_TEST_EQ(bind(sum_of_args_8, _1, _2, 3, 4, 5, 6, 7, 8)(i, j), 36);
BOOST_TEST_EQ(bind(sum_of_args_9, _1, _2, 3, 4, 5, 6, 7, 8, 9)(i, j), 45);
// three open arguments
BOOST_TEST_EQ(bind(sum_of_args_0)(), 0);
BOOST_TEST_EQ(bind(sum_of_args_1, _1)(i), 1);
BOOST_TEST_EQ(bind(sum_of_args_2, _1, _2)(i, j), 3);
BOOST_TEST_EQ(bind(sum_of_args_3, _1, _2, _3)(i, j, k), 6);
BOOST_TEST_EQ(bind(sum_of_args_4, _1, _2, _3, 4)(i, j, k), 10);
BOOST_TEST_EQ(bind(sum_of_args_5, _1, _2, _3, 4, 5)(i, j, k), 15);
BOOST_TEST_EQ(bind(sum_of_args_6, _1, _2, _3, 4, 5, 6)(i, j, k), 21);
BOOST_TEST_EQ(bind(sum_of_args_7, _1, _2, _3, 4, 5, 6, 7)(i, j, k), 28);
BOOST_TEST_EQ(bind(sum_of_args_8, _1, _2, _3, 4, 5, 6, 7, 8)(i, j, k), 36);
BOOST_TEST_EQ(bind(sum_of_args_9, _1, _2, _3, 4, 5, 6, 7, 8, 9)(i, j, k), 45);
// function compositions with bind
BOOST_TEST_EQ(bind(sum_of_args_3, bind(sum_of_args_2, _1, 2), 2, 3)(i), 8);
BOOST_TEST_EQ(
bind(sum_of_args_9,
bind(sum_of_args_0), // 0
bind(sum_of_args_1, _1), // 1
bind(sum_of_args_2, _1, _2), // 3
bind(sum_of_args_3, _1, _2, _3), // 6
bind(sum_of_args_4, _1, _2, _3, 4), // 10
bind(sum_of_args_5, _1, _2, _3, 4, 5), // 15
bind(sum_of_args_6, _1, _2, _3, 4, 5, 6), // 21
bind(sum_of_args_7, _1, _2, _3, 4, 5, 6, 7), // 28
bind(sum_of_args_8, _1, _2, _3, 4, 5, 6, 7, 8) // 36
)(i, j, k), 120);
// deeper nesting
result =
bind(sum_of_args_1, // 12
bind(sum_of_args_4, // 12
bind(sum_of_args_2, // 3
bind(sum_of_args_1, // 1
bind(sum_of_args_1, _1) // 1
),
_2),
_2,
_3,
4)
)(i, j, k);
BOOST_TEST_EQ(result, 12);
test_member_functions();
return boost::report_errors();
}

View File

@@ -0,0 +1,62 @@
// bll_and_function.cpp - The Boost Lambda Library -----------------------
//
// 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
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// test using BLL and boost::function
#include <boost/core/lightweight_test.hpp>
#include "boost/lambda/lambda.hpp"
#include "boost/function.hpp"
#include <vector>
#include <map>
#include <set>
#include <string>
using namespace boost::lambda;
using namespace std;
void test_function() {
boost::function<int (int, int)> f;
f = _1 + _2;
BOOST_TEST_EQ(f(1, 2), 3);
int i=1; int j=2;
boost::function<int& (int&, int)> g = _1 += _2;
g(i, j);
BOOST_TEST_EQ(i, 3);
int* sum = new int();
*sum = 0;
boost::function<int& (int)> counter = *sum += _1;
counter(5); // ok, sum* = 5;
BOOST_TEST_EQ(*sum, 5);
delete sum;
// The next statement would lead to a dangling reference
// counter(3); // error, *sum does not exist anymore
}
int main()
{
test_function();
return boost::report_errors();
}

View File

@@ -0,0 +1,107 @@
// cast_tests.cpp -- The Boost Lambda Library ------------------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/casts.hpp"
#include <string>
using namespace boost::lambda;
using namespace std;
class base {
int x;
public:
virtual const char* class_name() const { return "const base"; }
virtual const char* class_name() { return "base"; }
virtual ~base() {}
};
class derived : public base {
int y[100];
public:
virtual const char* class_name() const { return "const derived"; }
virtual const char* class_name() { return "derived"; }
};
void do_test() {
derived *p_derived = new derived;
base *p_base = new base;
base *b = NULL;
derived *d = NULL;
(var(b) = ll_static_cast<base *>(p_derived))();
(var(d) = ll_static_cast<derived *>(b))();
BOOST_TEST_CSTR_EQ(b->class_name(), "derived");
BOOST_TEST_CSTR_EQ(d->class_name(), "derived");
(var(b) = ll_dynamic_cast<derived *>(b))();
BOOST_TEST_NE(b, static_cast<base *>(NULL));
BOOST_TEST_CSTR_EQ(b->class_name(), "derived");
(var(d) = ll_dynamic_cast<derived *>(p_base))();
BOOST_TEST_EQ(d, static_cast<derived *>(NULL));
const derived* p_const_derived = p_derived;
BOOST_TEST_CSTR_EQ(p_const_derived->class_name(), "const derived");
(var(d) = ll_const_cast<derived *>(p_const_derived))();
BOOST_TEST_CSTR_EQ(d->class_name(), "derived");
int i = 10;
char* cp = reinterpret_cast<char*>(&i);
int* ip;
(var(ip) = ll_reinterpret_cast<int *>(cp))();
BOOST_TEST_EQ(*ip, 10);
// typeid
BOOST_TEST_CSTR_EQ(ll_typeid(d)().name(), typeid(d).name());
// sizeof
BOOST_TEST_EQ(ll_sizeof(_1)(p_derived), sizeof(p_derived));
BOOST_TEST_EQ(ll_sizeof(_1)(*p_derived), sizeof(*p_derived));
BOOST_TEST_EQ(ll_sizeof(_1)(p_base), sizeof(p_base));
BOOST_TEST_EQ(ll_sizeof(_1)(*p_base), sizeof(*p_base));
int an_array[100];
BOOST_TEST_EQ(ll_sizeof(_1)(an_array), 100 * sizeof(int));
delete p_derived;
delete p_base;
}
int main()
{
do_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,274 @@
// constructor_tests.cpp -- The Boost Lambda Library ------------------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/bind.hpp"
#include "boost/lambda/construct.hpp"
#include <iostream>
#include <algorithm>
#include <vector>
#ifdef BOOST_MSVC
#pragma warning(disable:4512)
#endif
using namespace boost::lambda;
namespace bl = boost::lambda;
template<class T>
bool check_tuple(int n, const T& t)
{
return (t.get_head() == n) && check_tuple(n+1, t.get_tail());
}
template<class T>
bool check_tuple(int n, T * t)
{
bool ok = check_tuple(n, *t);
delete t;
return ok;
}
template <>
bool check_tuple(int /*n*/, const null_type& ) { return true; }
void constructor_all_lengths()
{
bool ok;
ok = check_tuple(
1,
bind(constructor<tuple<int> >(),
1)()
);
BOOST_TEST(ok);
ok = check_tuple(
1,
bind(constructor<tuple<int, int> >(),
1, 2)()
);
BOOST_TEST(ok);
ok = check_tuple(
1,
bind(constructor<tuple<int, int, int> >(),
1, 2, 3)()
);
BOOST_TEST(ok);
ok = check_tuple(
1,
bind(constructor<tuple<int, int, int, int> >(),
1, 2, 3, 4)()
);
BOOST_TEST(ok);
ok = check_tuple(
1,
bind(constructor<tuple<int, int, int, int, int> >(),
1, 2, 3, 4, 5)()
);
BOOST_TEST(ok);
ok = check_tuple(
1,
bind(constructor<tuple<int, int, int, int, int, int> >(),
1, 2, 3, 4, 5, 6)()
);
BOOST_TEST(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);
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);
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);
}
void new_ptr_all_lengths()
{
bool ok;
ok = check_tuple(
1,
(bind(new_ptr<tuple<int> >(),
1))()
);
BOOST_TEST(ok);
ok = check_tuple(
1,
(bind(new_ptr<tuple<int, int> >(),
1, 2))()
);
BOOST_TEST(ok);
ok = check_tuple(
1,
(bind(new_ptr<tuple<int, int, int> >(),
1, 2, 3))()
);
BOOST_TEST(ok);
ok = check_tuple(
1,
(bind(new_ptr<tuple<int, int, int, int> >(),
1, 2, 3, 4))()
);
BOOST_TEST(ok);
ok = check_tuple(
1,
(bind(new_ptr<tuple<int, int, int, int, int> >(),
1, 2, 3, 4, 5))()
);
BOOST_TEST(ok);
ok = check_tuple(
1,
(bind(new_ptr<tuple<int, int, int, int, int, int> >(),
1, 2, 3, 4, 5, 6))()
);
BOOST_TEST(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);
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);
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);
}
class is_destructor_called {
bool& b;
public:
is_destructor_called(bool& bb) : b(bb) { b = false; }
~is_destructor_called() { b = true; }
};
void test_destructor ()
{
char space[sizeof(is_destructor_called)];
bool flag = false;
is_destructor_called* idc = new(space) is_destructor_called(flag);
BOOST_TEST_EQ(flag, false);
bind(destructor(), _1)(idc);
BOOST_TEST_EQ(flag, true);
idc = new(space) is_destructor_called(flag);
BOOST_TEST_EQ(flag, false);
bind(destructor(), _1)(*idc);
BOOST_TEST_EQ(flag, true);
}
class count_deletes {
public:
static int count;
~count_deletes() { ++count; }
};
int count_deletes::count = 0;
void test_news_and_deletes ()
{
int* i[10];
std::for_each(i, i+10, _1 = bind(new_ptr<int>(), 2));
int count_errors = 0;
std::for_each(i, i+10, (*_1 == 2) || ++var(count_errors));
BOOST_TEST_EQ(count_errors, 0);
std::for_each(i, i+10, bind(delete_ptr(), _1));
count_deletes* ct[10];
std::for_each(ct, ct+10, _1 = bind(new_ptr<count_deletes>()));
count_deletes::count = 0;
std::for_each(ct, ct+10, bind(delete_ptr(), _1));
BOOST_TEST_EQ(count_deletes::count, 10);
}
void test_array_new_and_delete()
{
count_deletes* c;
(_1 = bind(new_array<count_deletes>(), 5))(c);
count_deletes::count = 0;
bind(delete_array(), _1)(c);
BOOST_TEST_EQ(count_deletes::count, 5);
}
void delayed_construction()
{
std::vector<int> x(3);
std::vector<int> y(3);
std::fill(x.begin(), x.end(), 0);
std::fill(y.begin(), y.end(), 1);
std::vector<std::pair<int, int> > v;
std::transform(x.begin(), x.end(), y.begin(), std::back_inserter(v),
bl::bind(constructor<std::pair<int, int> >(), _1, _2) );
}
int main()
{
constructor_all_lengths();
new_ptr_all_lengths();
delayed_construction();
test_destructor();
test_news_and_deletes();
test_array_new_and_delete();
return boost::report_errors();
}

View File

@@ -0,0 +1,123 @@
// -- control_structures.cpp -- The Boost Lambda Library ------------------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/if.hpp"
#include "boost/lambda/loops.hpp"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace boost;
using boost::lambda::constant;
using boost::lambda::_1;
using boost::lambda::_2;
using boost::lambda::_3;
using boost::lambda::make_const;
using boost::lambda::for_loop;
using boost::lambda::while_loop;
using boost::lambda::do_while_loop;
using boost::lambda::if_then;
using boost::lambda::if_then_else;
using boost::lambda::if_then_else_return;
// 2 container for_each
template <class InputIter1, class InputIter2, class Function>
Function for_each(InputIter1 first, InputIter1 last,
InputIter2 first2, Function f) {
for ( ; first != last; ++first, ++first2)
f(*first, *first2);
return f;
}
void simple_loops() {
// for loops ---------------------------------------------------------
int i;
int arithmetic_series = 0;
for_loop(_1 = 0, _1 < 10, _1++, arithmetic_series += _1)(i);
BOOST_TEST_EQ(arithmetic_series, 45);
// no body case
for_loop(boost::lambda::var(i) = 0, boost::lambda::var(i) < 100, ++boost::lambda::var(i))();
BOOST_TEST_EQ(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_EQ(c, 3);
int count;
count = 0; i = 0;
while_loop(_1++ < 10, ++boost::lambda::var(count))(i);
BOOST_TEST_EQ(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_EQ(count, 11);
a = 0;
do_while_loop(constant(false), _1++)(a);
BOOST_TEST_EQ(a, 1);
// no body cases
a = 40; b = 30;
while_loop(--_1 > _2)(a, b);
BOOST_TEST_EQ(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_EQ(a, b);
}
void simple_ifs () {
int value = 42;
if_then(_1 < 0, _1 = 0)(value);
BOOST_TEST_EQ(value, 42);
value = -42;
if_then(_1 < 0, _1 = -_1)(value);
BOOST_TEST_EQ(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_EQ(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_EQ(min, 3);
int x, y;
x = -1; y = 1;
BOOST_TEST_EQ(if_then_else_return(_1 < _2, _2, _1)(x, y), (std::max)(x ,y));
BOOST_TEST_EQ(if_then_else_return(_1 < _2, _2, _1)(y, x), (std::max)(x ,y));
}
int main()
{
simple_loops();
simple_ifs();
return boost::report_errors();
}

View File

@@ -0,0 +1,613 @@
// -- exception_test.cpp -- The Boost Lambda Library ------------------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/exceptions.hpp"
#include "boost/lambda/bind.hpp"
#include<iostream>
#include<algorithm>
#include <cstdlib>
#include <iostream>
using namespace boost::lambda;
using namespace std;
// to prevent unused variables warnings
template <class T> void dummy(const T&) {}
void erroneous_exception_related_lambda_expressions() {
int i = 0;
dummy(i);
// Uncommenting any of the below code lines should result in a compile
// time error
// this should fail (a rethrow binder outside of catch
// rethrow()();
// this should fail too for the same reason
// try_catch(rethrow(), catch_all(cout << constant("Howdy")))();
// this fails too (_e outside of catch_exception)
// (_1 + _2 + _e)(i, i, i);
// and this (_e outside of catch_exception)
// try_catch( throw_exception(1), catch_all(cout << _e));
// and this (_3 in catch_exception
// try_catch( throw_exception(1), catch_exception<int>(cout << _3));
}
class A1 {};
class A2 {};
class A3 {};
class A4 {};
class A5 {};
class A6 {};
class A7 {};
class A8 {};
class A9 {};
void throw_AX(int j) {
int i = j;
switch(i) {
case 1: throw A1();
case 2: throw A2();
case 3: throw A3();
case 4: throw A4();
case 5: throw A5();
case 6: throw A6();
case 7: throw A7();
case 8: throw A8();
case 9: throw A9();
}
}
void test_different_number_of_catch_blocks() {
int ecount;
// no catch(...) cases
ecount = 0;
for(int i=1; i<=1; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 1);
ecount = 0;
for(int i=1; i<=2; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 2);
ecount = 0;
for(int i=1; i<=3; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 3);
ecount = 0;
for(int i=1; i<=4; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 4);
ecount = 0;
for(int i=1; i<=5; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
),
catch_exception<A5>(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 5);
ecount = 0;
for(int i=1; i<=6; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
),
catch_exception<A5>(
var(ecount)++
),
catch_exception<A6>(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 6);
ecount = 0;
for(int i=1; i<=7; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
),
catch_exception<A5>(
var(ecount)++
),
catch_exception<A6>(
var(ecount)++
),
catch_exception<A7>(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 7);
ecount = 0;
for(int i=1; i<=8; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
),
catch_exception<A5>(
var(ecount)++
),
catch_exception<A6>(
var(ecount)++
),
catch_exception<A7>(
var(ecount)++
),
catch_exception<A8>(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 8);
ecount = 0;
for(int i=1; i<=9; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
),
catch_exception<A5>(
var(ecount)++
),
catch_exception<A6>(
var(ecount)++
),
catch_exception<A7>(
var(ecount)++
),
catch_exception<A8>(
var(ecount)++
),
catch_exception<A9>(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 9);
// with catch(...) blocks
ecount = 0;
for(int i=1; i<=1; i++)
{
try_catch(
bind(throw_AX, _1),
catch_all(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 1);
ecount = 0;
for(int i=1; i<=2; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_all(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 2);
ecount = 0;
for(int i=1; i<=3; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_all(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 3);
ecount = 0;
for(int i=1; i<=4; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_all(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 4);
ecount = 0;
for(int i=1; i<=5; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
),
catch_all(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 5);
ecount = 0;
for(int i=1; i<=6; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
),
catch_exception<A5>(
var(ecount)++
),
catch_all(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 6);
ecount = 0;
for(int i=1; i<=7; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
),
catch_exception<A5>(
var(ecount)++
),
catch_exception<A6>(
var(ecount)++
),
catch_all(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 7);
ecount = 0;
for(int i=1; i<=8; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
),
catch_exception<A5>(
var(ecount)++
),
catch_exception<A6>(
var(ecount)++
),
catch_exception<A7>(
var(ecount)++
),
catch_all(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 8);
ecount = 0;
for(int i=1; i<=9; i++)
{
try_catch(
bind(throw_AX, _1),
catch_exception<A1>(
var(ecount)++
),
catch_exception<A2>(
var(ecount)++
),
catch_exception<A3>(
var(ecount)++
),
catch_exception<A4>(
var(ecount)++
),
catch_exception<A5>(
var(ecount)++
),
catch_exception<A6>(
var(ecount)++
),
catch_exception<A7>(
var(ecount)++
),
catch_exception<A8>(
var(ecount)++
),
catch_all(
var(ecount)++
)
)(i);
}
BOOST_TEST_EQ(ecount, 9);
}
void test_empty_catch_blocks() {
try_catch(
bind(throw_AX, _1),
catch_exception<A1>()
)(make_const(1));
try_catch(
bind(throw_AX, _1),
catch_all()
)(make_const(1));
}
void return_type_matching() {
// Rules for return types of the lambda functors in try and catch parts:
// 1. The try part dictates the return type of the whole
// try_catch lambda functor
// 2. If return type of try part is void, catch parts can return anything,
// but the return types are ignored
// 3. If the return type of the try part is A, then each catch return type
// must be implicitly convertible to A, or then it must throw for sure
int i = 1;
BOOST_TEST_EQ(
try_catch(
_1 + 1,
catch_exception<int>((&_1, rethrow())), // no match, but ok since throws
catch_exception<char>(_e) // ok, char convertible to int
)(i), 2
);
// note that while e.g. char is convertible to int, it is not convertible
// to int&, (some lambda functors return references)
// try_catch(
// _1 += 1,
// catch_exception<char>(_e) // NOT ok, char not convertible to int&
// )(i);
// if you don't care about the return type, you can use make_void
try_catch(
make_void(_1 += 1),
catch_exception<char>(_e) // since try is void, catch can return anything
)(i);
BOOST_TEST_EQ(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_EQ(i, 3);
char a = 'a';
try_catch(
try_catch(
throw_exception(1),
catch_exception<int>(throw_exception('b'))
),
catch_exception<char>( _1 = _e )
)(a);
BOOST_TEST_EQ(a, 'b');
}
int main()
{
try
{
test_different_number_of_catch_blocks();
return_type_matching();
test_empty_catch_blocks();
}
catch (int)
{
BOOST_TEST(false);
}
catch(...)
{
BOOST_TEST(false);
}
return boost::report_errors();
}

View File

@@ -0,0 +1,389 @@
// extending_return_type_traits.cpp -- The Boost Lambda Library --------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/bind.hpp"
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/detail/suppress_unused.hpp"
#include <iostream>
#include <functional>
#include <algorithm>
using boost::lambda::detail::suppress_unused_variable_warnings;
class A {};
class B {};
using namespace boost::lambda;
B operator--(const A&, int) { return B(); }
B operator--(A&) { return B(); }
B operator++(const A&, int) { return B(); }
B operator++(A&) { return B(); }
B operator-(const A&) { return B(); }
B operator+(const A&) { return B(); }
B operator!(const A&) { return B(); }
B operator&(const A&) { return B(); }
B operator*(const A&) { return B(); }
namespace boost {
namespace lambda {
// unary + and -
template<class Act>
struct plain_return_type_1<unary_arithmetic_action<Act>, A > {
typedef B type;
};
// post incr/decr
template<class Act>
struct plain_return_type_1<post_increment_decrement_action<Act>, A > {
typedef B type;
};
// pre incr/decr
template<class Act>
struct plain_return_type_1<pre_increment_decrement_action<Act>, A > {
typedef B type;
};
// !
template<>
struct plain_return_type_1<logical_action<not_action>, A> {
typedef B type;
};
// &
template<>
struct plain_return_type_1<other_action<addressof_action>, A> {
typedef B type;
};
// *
template<>
struct plain_return_type_1<other_action<contentsof_action>, A> {
typedef B type;
};
} // lambda
} // boost
void ok(B /*b*/) {}
void test_unary_operators()
{
A a; int i = 1;
ok((++_1)(a));
ok((--_1)(a));
ok((_1++)(a));
ok((_1--)(a));
ok((+_1)(a));
ok((-_1)(a));
ok((!_1)(a));
ok((&_1)(a));
ok((*_1)(a));
BOOST_TEST_EQ((*_1)(make_const(&i)), 1);
}
class X {};
class Y {};
class Z {};
Z operator+(const X&, const Y&) { return Z(); }
Z operator-(const X&, const Y&) { return Z(); }
X operator*(const X&, const Y&) { return X(); }
Z operator/(const X&, const Y&) { return Z(); }
Z operator%(const X&, const Y&) { return Z(); }
class XX {};
class YY {};
class ZZ {};
class VV {};
// it is possible to support differently cv-qualified versions
YY operator*(XX&, YY&) { return YY(); }
ZZ operator*(const XX&, const YY&) { return ZZ(); }
XX operator*(volatile XX&, volatile YY&) { return XX(); }
VV operator*(const volatile XX&, const volatile YY&) { return VV(); }
// the traits can be more complex:
template <class T>
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*/)
{
typedef typename
return_type_2<arithmetic_action<plus_action>, A&, B&>::type res_type;
return my_vector<res_type>();
}
// bitwise ops:
X operator<<(const X&, const Y&) { return X(); }
Z operator>>(const X&, const Y&) { return Z(); }
Z operator&(const X&, const Y&) { return Z(); }
Z operator|(const X&, const Y&) { return Z(); }
Z operator^(const X&, const Y&) { return Z(); }
// comparison ops:
X operator<(const X&, const Y&) { return X(); }
Z operator>(const X&, const Y&) { return Z(); }
Z operator<=(const X&, const Y&) { return Z(); }
Z operator>=(const X&, const Y&) { return Z(); }
Z operator==(const X&, const Y&) { return Z(); }
Z operator!=(const X&, const Y&) { return Z(); }
// logical
X operator&&(const X&, const Y&) { return X(); }
Z operator||(const X&, const Y&) { return Z(); }
// arithh assignment
Z operator+=( X&, const Y&) { return Z(); }
Z operator-=( X&, const Y&) { return Z(); }
Y operator*=( X&, const Y&) { return Y(); }
Z operator/=( X&, const Y&) { return Z(); }
Z operator%=( X&, const Y&) { return Z(); }
// bitwise assignment
Z operator<<=( X&, const Y&) { return Z(); }
Z operator>>=( X&, const Y&) { return Z(); }
Y operator&=( X&, const Y&) { return Y(); }
Z operator|=( X&, const Y&) { return Z(); }
Z operator^=( X&, const Y&) { return Z(); }
// assignment
class Assign {
public:
void operator=(const Assign& /*a*/) {}
X operator[](const int& /*i*/) { return X(); }
};
namespace boost {
namespace lambda {
// you can do action groups
template<class Act>
struct plain_return_type_2<arithmetic_action<Act>, X, Y> {
typedef Z type;
};
// or specialize the exact action
template<>
struct plain_return_type_2<arithmetic_action<multiply_action>, X, Y> {
typedef X type;
};
// if you want to make a distinction between differently cv-qualified
// types, you need to specialize on a different level:
template<>
struct return_type_2<arithmetic_action<multiply_action>, XX, YY> {
typedef YY type;
};
template<>
struct return_type_2<arithmetic_action<multiply_action>, const XX, const YY> {
typedef ZZ type;
};
template<>
struct return_type_2<arithmetic_action<multiply_action>, volatile XX, volatile YY> {
typedef XX type;
};
template<>
struct return_type_2<arithmetic_action<multiply_action>, volatile const XX, const volatile YY> {
typedef VV type;
};
// the mapping can be more complex:
template<class A, class B>
struct plain_return_type_2<arithmetic_action<plus_action>, my_vector<A>, my_vector<B> > {
typedef typename
return_type_2<arithmetic_action<plus_action>, A&, B&>::type res_type;
typedef my_vector<res_type> type;
};
// bitwise binary:
// you can do action groups
template<class Act>
struct plain_return_type_2<bitwise_action<Act>, X, Y> {
typedef Z type;
};
// or specialize the exact action
template<>
struct plain_return_type_2<bitwise_action<leftshift_action>, X, Y> {
typedef X type;
};
// comparison binary:
// you can do action groups
template<class Act>
struct plain_return_type_2<relational_action<Act>, X, Y> {
typedef Z type;
};
// or specialize the exact action
template<>
struct plain_return_type_2<relational_action<less_action>, X, Y> {
typedef X type;
};
// logical binary:
// you can do action groups
template<class Act>
struct plain_return_type_2<logical_action<Act>, X, Y> {
typedef Z type;
};
// or specialize the exact action
template<>
struct plain_return_type_2<logical_action<and_action>, X, Y> {
typedef X type;
};
// arithmetic assignment :
// you can do action groups
template<class Act>
struct plain_return_type_2<arithmetic_assignment_action<Act>, X, Y> {
typedef Z type;
};
// or specialize the exact action
template<>
struct plain_return_type_2<arithmetic_assignment_action<multiply_action>, X, Y> {
typedef Y type;
};
// arithmetic assignment :
// you can do action groups
template<class Act>
struct plain_return_type_2<bitwise_assignment_action<Act>, X, Y> {
typedef Z type;
};
// or specialize the exact action
template<>
struct plain_return_type_2<bitwise_assignment_action<and_action>, X, Y> {
typedef Y type;
};
// assignment
template<>
struct plain_return_type_2<other_action<assignment_action>, Assign, Assign> {
typedef void type;
};
// subscript
template<>
struct plain_return_type_2<other_action<subscript_action>, Assign, int> {
typedef X type;
};
} // end lambda
} // end boost
void test_binary_operators() {
X x; Y y;
(_1 + _2)(x, y);
(_1 - _2)(x, y);
(_1 * _2)(x, y);
(_1 / _2)(x, y);
(_1 % _2)(x, y);
// make a distinction between differently cv-qualified operators
XX xx; YY yy;
const XX& cxx = xx;
const YY& cyy = yy;
volatile XX& vxx = xx;
volatile YY& vyy = yy;
const volatile XX& cvxx = xx;
const volatile YY& cvyy = yy;
ZZ dummy1 = (_1 * _2)(cxx, cyy);
YY dummy2 = (_1 * _2)(xx, yy);
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 >> _2)(x, y);
(_1 | _2)(x, y);
(_1 & _2)(x, y);
(_1 ^ _2)(x, y);
// comparison
(_1 < _2)(x, y);
(_1 > _2)(x, y);
(_1 <= _2)(x, y);
(_1 >= _2)(x, y);
(_1 == _2)(x, y);
(_1 != _2)(x, y);
// logical
(_1 || _2)(x, y);
(_1 && _2)(x, y);
// arithmetic assignment
(_1 += _2)(x, y);
(_1 -= _2)(x, y);
(_1 *= _2)(x, y);
(_1 /= _2)(x, y);
(_1 %= _2)(x, y);
// bitwise assignment
(_1 <<= _2)(x, y);
(_1 >>= _2)(x, y);
(_1 |= _2)(x, y);
(_1 &= _2)(x, y);
(_1 ^= _2)(x, y);
}
int main()
{
test_unary_operators();
test_binary_operators();
return boost::report_errors();
}

View File

@@ -0,0 +1,78 @@
// is_instance_of_test.cpp -- The Boost Lambda Library ------------------
//
// 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
// 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/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include "boost/lambda/detail/is_instance_of.hpp"
#include <iostream>
template <class T1> struct A1 {};
template <class T1, class T2> struct A2 {};
template <class T1, class T2, class T3> struct A3 {};
template <class T1, class T2, class T3, class T4> struct A4 {};
class B1 : public A1<int> {};
class B2 : public A2<int,int> {};
class B3 : public A3<int,int,int> {};
class B4 : public A4<int,int,int,int> {};
// classes that are convertible to classes that derive from A instances
// This is not enough to make the test succeed
class C1 { public: operator A1<int>() { return A1<int>(); } };
class C2 { public: operator B2() { return B2(); } };
class C3 { public: operator B3() { return B3(); } };
class C4 { public: operator B4() { return B4(); } };
// test that the result is really a constant
// (in an alternative implementation, gcc 3.0.2. claimed that it was
// a non-constant)
template <bool b> class X {};
// this should compile
X<boost::lambda::is_instance_of_2<int, A2>::value> x;
int main()
{
using boost::lambda::is_instance_of_1;
using boost::lambda::is_instance_of_2;
using boost::lambda::is_instance_of_3;
using boost::lambda::is_instance_of_4;
BOOST_TEST_TRAIT_TRUE((is_instance_of_1<B1, A1>));
BOOST_TEST_TRAIT_TRUE((is_instance_of_1<A1<float>, A1>));
BOOST_TEST_TRAIT_FALSE((is_instance_of_1<int, A1>));
BOOST_TEST_TRAIT_FALSE((is_instance_of_1<C1, A1>));
BOOST_TEST_TRAIT_TRUE((is_instance_of_2<B2, A2>));
BOOST_TEST_TRAIT_TRUE((is_instance_of_2<A2<int, float>, A2>));
BOOST_TEST_TRAIT_FALSE((is_instance_of_2<int, A2>));
BOOST_TEST_TRAIT_FALSE((is_instance_of_2<C2, A2>));
BOOST_TEST_TRAIT_TRUE((is_instance_of_3<B3, A3>));
BOOST_TEST_TRAIT_TRUE((is_instance_of_3<A3<int, float, char>, A3>));
BOOST_TEST_TRAIT_FALSE((is_instance_of_3<int, A3>));
BOOST_TEST_TRAIT_FALSE((is_instance_of_3<C3, A3>));
BOOST_TEST_TRAIT_TRUE((is_instance_of_4<B4, A4>));
BOOST_TEST_TRAIT_TRUE((is_instance_of_4<A4<int, float, char, double>, A4>));
BOOST_TEST_TRAIT_FALSE((is_instance_of_4<int, A4>));
BOOST_TEST_TRAIT_FALSE((is_instance_of_4<C4, A4>));
return boost::report_errors();
}

View 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();
}

View File

@@ -0,0 +1,193 @@
// member_pointer_test.cpp -- The Boost Lambda Library ------------------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/bind.hpp"
#include <string>
using namespace boost::lambda;
using namespace std;
struct my_struct {
my_struct(int x) : mem(x) {};
int mem;
int fooc() const { return mem; }
int foo() { return mem; }
int foo1c(int y) const { return y + mem; }
int foo1(int y) { return y + mem; }
int foo2c(int y, int x) const { return y + x + mem; }
int foo2(int y, int x) { return y + x + mem; }
int foo3c(int y, int x, int z) const { return y + x + z + mem; }
int foo3(int y, int x, int z ){ return y + x + z + mem; }
int foo4c(int a1, int a2, int a3, int a4) const { return a1+a2+a3+a4+mem; }
int foo4(int a1, int a2, int a3, int a4){ return a1+a2+a3+a4+mem; }
int foo3default(int y = 1, int x = 2, int z = 3) { return y + x + z + mem; }
};
my_struct x(3);
void pointer_to_data_member_tests() {
// int i = 0;
my_struct *y = &x;
BOOST_TEST_EQ((_1 ->* &my_struct::mem)(y), 3);
(_1 ->* &my_struct::mem)(y) = 4;
BOOST_TEST_EQ(x.mem, 4);
((_1 ->* &my_struct::mem) = 5)(y);
BOOST_TEST_EQ(x.mem, 5);
// &my_struct::mem is a temporary, must be constified
((y ->* _1) = 6)(make_const(&my_struct::mem));
BOOST_TEST_EQ(x.mem, 6);
((_1 ->* _2) = 7)(y, make_const(&my_struct::mem));
BOOST_TEST_EQ(x.mem, 7);
}
void pointer_to_member_function_tests() {
my_struct *y = new my_struct(1);
BOOST_TEST_EQ( (_1 ->* &my_struct::foo)(y)(), (y->mem));
BOOST_TEST_EQ( (_1 ->* &my_struct::fooc)(y)(), (y->mem));
BOOST_TEST_EQ( (y ->* _1)(make_const(&my_struct::foo))(), (y->mem));
BOOST_TEST_EQ( (y ->* _1)(make_const(&my_struct::fooc))(), (y->mem));
BOOST_TEST_EQ( (_1 ->* _2)(y, make_const(&my_struct::foo))(), (y->mem));
BOOST_TEST_EQ( (_1 ->* _2)(y, make_const(&my_struct::fooc))(), (y->mem));
BOOST_TEST_EQ( (_1 ->* &my_struct::foo1)(y)(1), (y->mem+1));
BOOST_TEST_EQ( (_1 ->* &my_struct::foo1c)(y)(1), (y->mem+1));
BOOST_TEST_EQ( (y ->* _1)(make_const(&my_struct::foo1))(1), (y->mem+1));
BOOST_TEST_EQ( (y ->* _1)(make_const(&my_struct::foo1c))(1), (y->mem+1));
BOOST_TEST_EQ( (_1 ->* _2)(y, make_const(&my_struct::foo1))(1), (y->mem+1));
BOOST_TEST_EQ( (_1 ->* _2)(y, make_const(&my_struct::foo1c))(1), (y->mem+1));
BOOST_TEST_EQ( (_1 ->* &my_struct::foo2)(y)(1,2), (y->mem+1+2));
BOOST_TEST_EQ( (_1 ->* &my_struct::foo2c)(y)(1,2), (y->mem+1+2));
BOOST_TEST_EQ( (y ->* _1)(make_const(&my_struct::foo2))(1,2), (y->mem+1+2));
BOOST_TEST_EQ( (y ->* _1)(make_const(&my_struct::foo2c))(1,2), (y->mem+1+2));
BOOST_TEST_EQ( (_1 ->* _2)(y, make_const(&my_struct::foo2))(1,2), (y->mem+1+2));
BOOST_TEST_EQ( (_1 ->* _2)(y, make_const(&my_struct::foo2c))(1,2), (y->mem+1+2));
BOOST_TEST_EQ( (_1 ->* &my_struct::foo3)(y)(1,2,3), (y->mem+1+2+3));
BOOST_TEST_EQ( (_1 ->* &my_struct::foo3c)(y)(1,2,3), (y->mem+1+2+3));
BOOST_TEST_EQ( (y ->* _1)(make_const(&my_struct::foo3))(1,2,3), (y->mem+1+2+3));
BOOST_TEST_EQ( (y ->* _1)(make_const(&my_struct::foo3c))(1,2,3), (y->mem+1+2+3));
BOOST_TEST_EQ( (_1 ->* _2)(y, make_const(&my_struct::foo3))(1,2,3), (y->mem+1+2+3));
BOOST_TEST_EQ( (_1 ->* _2)(y, make_const(&my_struct::foo3c))(1,2,3), (y->mem+1+2+3));
BOOST_TEST_EQ( (_1 ->* &my_struct::foo4)(y)(1,2,3,4), (y->mem+1+2+3+4));
BOOST_TEST_EQ( (_1 ->* &my_struct::foo4c)(y)(1,2,3,4), (y->mem+1+2+3+4));
BOOST_TEST_EQ( (y ->* _1)(make_const(&my_struct::foo4))(1,2,3,4), (y->mem+1+2+3+4));
BOOST_TEST_EQ( (y ->* _1)(make_const(&my_struct::foo4c))(1,2,3,4), (y->mem+1+2+3+4));
BOOST_TEST_EQ( (_1 ->* _2)(y, make_const(&my_struct::foo4))(1,2,3,4), (y->mem+1+2+3+4));
BOOST_TEST_EQ( (_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_EQ( (_1 ->* &my_struct::foo3default)(y)(), (y->mem+1+2+3));
delete y;
}
class A {};
class B {};
class C {};
class D {};
// ->* can be overloaded to do anything
bool operator->*(A /*a*/, B /*b*/) {
return false;
}
bool operator->*(B /*b*/, A /*a*/) {
return true;
}
// let's provide specializations to take care of the return type deduction.
// Note, that you need to provide all four cases for non-const and const
// or use the plain_return_type_2 template.
namespace boost {
namespace lambda {
template <>
struct return_type_2<other_action<member_pointer_action>, B, A> {
typedef bool type;
};
template<>
struct return_type_2<other_action<member_pointer_action>, const B, A> {
typedef bool type;
};
template<>
struct return_type_2<other_action<member_pointer_action>, B, const A> {
typedef bool type;
};
template<>
struct return_type_2<other_action<member_pointer_action>, const B, const A> {
typedef bool type;
};
} // lambda
} // boost
void test_overloaded_pointer_to_member()
{
A a; B b;
// this won't work, can't deduce the return type
// BOOST_TEST_EQ((_1->*_2)(a, b), false);
// ret<bool> gives the return type
BOOST_TEST_EQ(ret<bool>(_1->*_2)(a, b), false);
BOOST_TEST_EQ(ret<bool>(a->*_1)(b), false);
BOOST_TEST_EQ(ret<bool>(_1->*b)(a), false);
BOOST_TEST_EQ((ret<bool>((var(a))->*b))(), false);
BOOST_TEST_EQ((ret<bool>((var(a))->*var(b)))(), false);
// this is ok without ret<bool> due to the return_type_2 spcialization above
BOOST_TEST_EQ((_1->*_2)(b, a), true);
BOOST_TEST_EQ((b->*_1)(a), true);
BOOST_TEST_EQ((_1->*a)(b), true);
BOOST_TEST_EQ((var(b)->*a)(), true);
return;
}
int main()
{
pointer_to_data_member_tests();
pointer_to_member_function_tests();
test_overloaded_pointer_to_member();
return boost::report_errors();
}

View File

@@ -0,0 +1,425 @@
// operator_tests_simple.cpp -- The Boost Lambda Library ---------------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/detail/suppress_unused.hpp"
#include <boost/shared_ptr.hpp>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <iostream>
#ifndef BOOST_NO_STRINGSTREAM
#include <sstream>
#endif
using namespace std;
using namespace boost;
using namespace boost::lambda;
class unary_plus_tester {};
unary_plus_tester operator+(const unary_plus_tester& a) { return a; }
void cout_tests()
{
#ifndef BOOST_NO_STRINGSTREAM
using std::cout;
ostringstream os;
int i = 10;
(os << _1)(i);
(os << constant("FOO"))();
BOOST_TEST_EQ(os.str(), std::string("10FOO"));
istringstream is("ABC 1");
std::string s;
int k;
is >> s;
is >> k;
BOOST_TEST_EQ(s, std::string("ABC"));
BOOST_TEST_EQ(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_EQ((ci)(), 5);
BOOST_TEST_EQ(i, 100);
int a;
constant_ref_type<int>::type cr(constant_ref(i));
(++vi, var(a) = cr)();
BOOST_TEST_EQ(i, 101);
#endif
}
void arithmetic_operators() {
int i = 1; int j = 2; int k = 3;
using namespace std;
using namespace boost::lambda;
BOOST_TEST_EQ((_1 + 1)(i), 2);
BOOST_TEST_EQ(((_1 + 1) * _2)(i, j), 4);
BOOST_TEST_EQ((_1 - 1)(i), 0);
BOOST_TEST_EQ((_1 * 2)(j), 4);
BOOST_TEST_EQ((_1 / 2)(j), 1);
BOOST_TEST_EQ((_1 % 2)(k), 1);
BOOST_TEST_EQ((-_1)(i), -1);
BOOST_TEST_EQ((+_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_EQ((_1 << 1)(ui), (2 << 1));
BOOST_TEST_EQ((_1 >> 1)(ui), (2 >> 1));
BOOST_TEST_EQ((_1 & 1)(ui), (2 & 1));
BOOST_TEST_EQ((_1 | 1)(ui), (2 | 1));
BOOST_TEST_EQ((_1 ^ 1)(ui), (2 ^ 1));
BOOST_TEST_EQ((~_1)(ui), ~2u);
}
void comparison_operators() {
int i = 0, j = 1;
BOOST_TEST((_1 < _2)(i, j));
BOOST_TEST((_1 <= _2)(i, j));
BOOST_TEST(!(_1 == _2)(i, j));
BOOST_TEST((_1 != _2)(i, j));
BOOST_TEST(!(_1 > _2)(i, j));
BOOST_TEST(!(_1 >= _2)(i, j));
BOOST_TEST(!(!(_1 < _2))(i, j));
BOOST_TEST(!(!(_1 <= _2))(i, j));
BOOST_TEST((!(_1 == _2))(i, j));
BOOST_TEST(!(!(_1 != _2))(i, j));
BOOST_TEST((!(_1 > _2))(i, j));
BOOST_TEST((!(_1 >= _2))(i, j));
}
void logical_operators() {
bool t = true, f = false;
BOOST_TEST((_1 && _2)(t, t));
BOOST_TEST(!(_1 && _2)(t, f));
BOOST_TEST(!(_1 && _2)(f, t));
BOOST_TEST(!(_1 && _2)(f, f));
BOOST_TEST((_1 || _2)(t, t));
BOOST_TEST((_1 || _2)(t, f));
BOOST_TEST((_1 || _2)(f, t));
BOOST_TEST(!(_1 || _2)(f, f));
BOOST_TEST(!(!_1)(t));
BOOST_TEST((!_1)(f));
// test short circuiting
int i=0;
(false && ++_1)(i);
BOOST_TEST_EQ(i, 0);
i = 0;
(true && ++_1)(i);
BOOST_TEST_EQ(i, 1);
i = 0;
(false || ++_1)(i);
BOOST_TEST_EQ(i, 1);
i = 0;
(true || ++_1)(i);
BOOST_TEST_EQ(i, 0);
i = 0;
}
void unary_incs_and_decs() {
int i = 0;
BOOST_TEST_EQ(_1++(i), 0);
BOOST_TEST_EQ(i, 1);
i = 0;
BOOST_TEST_EQ(_1--(i), 0);
BOOST_TEST_EQ(i, -1);
i = 0;
BOOST_TEST_EQ((++_1)(i), 1);
BOOST_TEST_EQ(i, 1);
i = 0;
BOOST_TEST_EQ((--_1)(i), -1);
BOOST_TEST_EQ(i, -1);
i = 0;
// the result of prefix -- and ++ are lvalues
(++_1)(i) = 10;
BOOST_TEST_EQ(i, 10);
i = 0;
(--_1)(i) = 10;
BOOST_TEST_EQ(i, 10);
i = 0;
}
void compound_operators() {
int i = 1;
// normal variable as the left operand
(i += _1)(make_const(1));
BOOST_TEST_EQ(i, 2);
(i -= _1)(make_const(1));
BOOST_TEST_EQ(i, 1);
(i *= _1)(make_const(10));
BOOST_TEST_EQ(i, 10);
(i /= _1)(make_const(2));
BOOST_TEST_EQ(i, 5);
(i %= _1)(make_const(2));
BOOST_TEST_EQ(i, 1);
// lambda expression as a left operand
(_1 += 1)(i);
BOOST_TEST_EQ(i, 2);
(_1 -= 1)(i);
BOOST_TEST_EQ(i, 1);
(_1 *= 10)(i);
BOOST_TEST_EQ(i, 10);
(_1 /= 2)(i);
BOOST_TEST_EQ(i, 5);
(_1 %= 2)(i);
BOOST_TEST_EQ(i, 1);
// lambda expression as a left operand with rvalue on RHS
(_1 += (0 + 1))(i);
BOOST_TEST_EQ(i, 2);
(_1 -= (0 + 1))(i);
BOOST_TEST_EQ(i, 1);
(_1 *= (0 + 10))(i);
BOOST_TEST_EQ(i, 10);
(_1 /= (0 + 2))(i);
BOOST_TEST_EQ(i, 5);
(_1 %= (0 + 2))(i);
BOOST_TEST_EQ(i, 1);
// shifts
unsigned int ui = 2;
(_1 <<= 1)(ui);
BOOST_TEST_EQ(ui, (2 << 1));
ui = 2;
(_1 >>= 1)(ui);
BOOST_TEST_EQ(ui, (2 >> 1));
ui = 2;
(ui <<= _1)(make_const(1));
BOOST_TEST_EQ(ui, (2 << 1));
ui = 2;
(ui >>= _1)(make_const(1));
BOOST_TEST_EQ(ui, (2 >> 1));
// and, or, xor
ui = 2;
(_1 &= 1)(ui);
BOOST_TEST_EQ(ui, (2 & 1));
ui = 2;
(_1 |= 1)(ui);
BOOST_TEST_EQ(ui, (2 | 1));
ui = 2;
(_1 ^= 1)(ui);
BOOST_TEST_EQ(ui, (2 ^ 1));
ui = 2;
(ui &= _1)(make_const(1));
BOOST_TEST_EQ(ui, (2 & 1));
ui = 2;
(ui |= _1)(make_const(1));
BOOST_TEST_EQ(ui, (2 | 1));
ui = 2;
(ui ^= _1)(make_const(1));
BOOST_TEST_EQ(ui, (2 ^ 1));
}
void assignment_and_subscript() {
// assignment and subscript need to be defined as member functions.
// Hence, if you wish to use a normal variable as the left hand argument,
// you must wrap it with var to turn it into a lambda expression
using std::string;
string s;
(_1 = "one")(s);
BOOST_TEST_EQ(s, string("one"));
(var(s) = "two")();
BOOST_TEST_EQ(s, string("two"));
BOOST_TEST_EQ((var(s)[_1])(make_const(2)), 'o');
BOOST_TEST_EQ((_1[2])(s), 'o');
BOOST_TEST_EQ((_1[_2])(s, make_const(2)), 'o');
// subscript returns lvalue
(var(s)[_1])(make_const(1)) = 'o';
BOOST_TEST_EQ(s, "too");
(_1[1])(s) = 'a';
BOOST_TEST_EQ(s, "tao");
(_1[_2])(s, make_const(0)) = 'm';
BOOST_TEST_EQ(s, "mao");
// TODO: tests for vector, set, map, multimap
}
class A {};
void address_of_and_dereference() {
A a; int i = 42;
BOOST_TEST_EQ((&_1)(a), &a);
BOOST_TEST_EQ((*&_1)(i), 42);
std::vector<int> vi; vi.push_back(1);
std::vector<int>::iterator it = vi.begin();
(*_1 = 7)(it);
BOOST_TEST_EQ(vi[0], 7);
const std::vector<int>::iterator cit(it);
(*_1 = 8)(cit);
BOOST_TEST_EQ(vi[0], 8);
// TODO: Add tests for more complex iterator types
boost::shared_ptr<int> ptr(new int(0));
(*_1 = 7)(ptr);
BOOST_TEST_EQ(*ptr, 7);
const boost::shared_ptr<int> cptr(ptr);
(*_1 = 8)(cptr);
BOOST_TEST_EQ(*ptr, 8);
}
void comma() {
int i = 100;
BOOST_TEST_EQ((_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)
}
void pointer_arithmetic() {
int ia[4] = { 1, 2, 3, 4 };
int* ip = ia;
int* ia_last = &ia[3];
const int cia[4] = { 1, 2, 3, 4 };
const int* cip = cia;
const int* cia_last = &cia[3];
// non-const array
BOOST_TEST_EQ((*(_1 + 1))(ia), 2);
// non-const pointer
BOOST_TEST_EQ((*(_1 + 1))(ip), 2);
BOOST_TEST_EQ((*(_1 - 1))(ia_last), 3);
// const array
BOOST_TEST_EQ((*(_1 + 1))(cia), 2);
// const pointer
BOOST_TEST_EQ((*(_1 + 1))(cip), 2);
BOOST_TEST_EQ((*(_1 - 1))(cia_last), 3);
// pointer arithmetic should not make non-consts const
(*(_1 + 2))(ia) = 0;
(*(_1 + 3))(ip) = 0;
BOOST_TEST_EQ(ia[2], 0);
BOOST_TEST_EQ(ia[3], 0);
// pointer - pointer
BOOST_TEST_EQ((_1 - _2)(ia_last, ia), 3);
BOOST_TEST_EQ((_1 - _2)(cia_last, cia), 3);
BOOST_TEST_EQ((ia_last - _1)(ia), 3);
BOOST_TEST_EQ((cia_last - _1)(cia), 3);
BOOST_TEST_EQ((cia_last - _1)(cip), 3);
}
int main()
{
arithmetic_operators();
bitwise_operators();
comparison_operators();
logical_operators();
unary_incs_and_decs();
compound_operators();
assignment_and_subscript();
address_of_and_dereference();
comma();
pointer_arithmetic();
cout_tests();
return boost::report_errors();
}

View File

@@ -0,0 +1,148 @@
// phoenix_style_control_structures.cpp -- The Boost Lambda Library ------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/if.hpp"
#include "boost/lambda/loops.hpp"
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
using namespace boost::lambda;
using namespace std;
// If-else, while, do-while, for statements
int main()
{
vector<int> v;
v.clear();
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);
v.push_back(5);
v.push_back(6);
v.push_back(7);
v.push_back(8);
v.push_back(9);
v.push_back(10);
int sum = 0;
//////////////////////////////////
for_each(v.begin(), v.end(),
if_(_1 > 3 && _1 <= 8)
[
sum += _1
]
);
BOOST_TEST_EQ(sum, 4+5+6+7+8);
int gt = 0, eq = 0, lt = 0;
//////////////////////////////////
for_each(v.begin(), v.end(),
if_(_1 > 5)
[
++var(gt)
]
.else_
[
if_(_1 == 5)
[
++var(eq)
]
.else_
[
++var(lt)
]
]
);
BOOST_TEST_EQ(lt, 4);
BOOST_TEST_EQ(eq, 1);
BOOST_TEST_EQ(gt, 5);
vector<int> t = v;
int counta = 0;
int countb = 0;
//////////////////////////////////
for_each(v.begin(), v.end(),
(
while_(_1--)
[
++var(counta)
],
++var(countb)
)
);
BOOST_TEST_EQ(counta, 55);
BOOST_TEST_EQ(countb, 10);
v = t;
counta = 0; countb = 0;
//////////////////////////////////
for_each(v.begin(), v.end(),
(
do_
[
++var(counta)
]
.while_(_1--),
++var(countb)
)
);
BOOST_TEST_EQ(counta, (2+11)*10/2);
BOOST_TEST_EQ(countb, 10);
v = t;
counta = 0; countb = 0;
//////////////////////////////////
int iii;
for_each(v.begin(), v.end(),
(
for_(var(iii) = 0, var(iii) < _1, ++var(iii))
[
++var(counta)
],
++var(countb)
)
);
BOOST_TEST_EQ(counta, (1+10)*10/2);
BOOST_TEST_EQ(countb, 10);
v = t;
return boost::report_errors();
}

View File

@@ -0,0 +1,315 @@
// 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/core/lightweight_test.hpp>
#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 main()
{
BOOST_TEST_EQ(boost::lambda::bind(with_result_type())(), 0);
BOOST_TEST_EQ(boost::lambda::bind(with_result_type(), 1)(), 1);
BOOST_TEST_EQ(boost::lambda::bind(with_result_type(), 1, 2)(), 2);
BOOST_TEST_EQ(boost::lambda::bind(with_result_type(), 1, 2, 3)(), 3);
BOOST_TEST_EQ(boost::lambda::bind(with_result_type(), 1, 2, 3, 4)(), 4);
BOOST_TEST_EQ(boost::lambda::bind(with_result_type(), 1, 2, 3, 4, 5)(), 5);
BOOST_TEST_EQ(boost::lambda::bind(with_result_type(), 1, 2, 3, 4, 5, 6)(), 6);
BOOST_TEST_EQ(boost::lambda::bind(with_result_type(), 1, 2, 3, 4, 5, 6, 7)(), 7);
BOOST_TEST_EQ(boost::lambda::bind(with_result_type(), 1, 2, 3, 4, 5, 6, 7, 8)(), 8);
BOOST_TEST_EQ(boost::lambda::bind(with_result_type(), 1, 2, 3, 4, 5, 6, 7, 8, 9)(), 9);
// Nullary result_of fails
//BOOST_TEST_EQ(boost::lambda::bind(with_result_template_value())(), 0);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_value(), 1)(), 1);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_value(), 1, 2)(), 2);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_value(), 1, 2, 3)(), 3);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4)(), 4);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4, 5)(), 5);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4, 5, 6)(), 6);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4, 5, 6, 7)(), 7);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_value(), 1, 2, 3, 4, 5, 6, 7, 8)(), 8);
BOOST_TEST_EQ(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_TEST_EQ(boost::lambda::bind(with_result_template_reference())(), 0);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_reference(), var(one))(), 1);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_reference(), var(one), var(two))(), 2);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three))(), 3);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three), var(four))(), 4);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three), var(four), var(five))(), 5);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three), var(four), var(five), var(six))(), 6);
BOOST_TEST_EQ(boost::lambda::bind(with_result_template_reference(), var(one), var(two), var(three), var(four), var(five), var(six), var(seven))(), 7);
BOOST_TEST_EQ(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_TEST_EQ(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_TEST_EQ(apply0(constant(0)), 0);
BOOST_TEST_EQ(apply1<int>(_1, one), 1);
BOOST_TEST_EQ(apply1<int&>(_1, one), 1);
BOOST_TEST_EQ(apply1<const int&>(_1, one), 1);
BOOST_TEST_EQ((apply2<int, int>(_1 + _2, one, two)), 3);
BOOST_TEST_EQ((apply2<int&, int&>(_1 + _2, one, two)), 3);
BOOST_TEST_EQ((apply2<const int&, const int&>(_1 + _2, one, two)), 3);
BOOST_TEST_EQ((apply3<int, int, int>(_1 + _2 + _3, one, two, three)), 6);
BOOST_TEST_EQ((apply3<int&, int&, int&>(_1 + _2 + _3, one, two, three)), 6);
BOOST_TEST_EQ((apply3<const int&, const int&, const int&>(_1 + _2 + _3, one, two, three)), 6);
return boost::report_errors();
}

View File

@@ -0,0 +1,54 @@
// 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/core/lightweight_test.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_TEST(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_TEST(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 main()
{
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 boost::report_errors();
}

View 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();
}

View File

@@ -0,0 +1,390 @@
// switch_test.cpp -- The Boost Lambda Library --------------------------
//
// 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
// 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/core/lightweight_test.hpp>
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/if.hpp"
#include "boost/lambda/switch.hpp"
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
// Check that elements 0 -- index are 1, and the rest are 0
bool check(const std::vector<int>& v, int index) {
using namespace boost::lambda;
int counter = 0;
std::vector<int>::const_iterator
result = std::find_if(v.begin(), v.end(),
! if_then_else_return(
var(counter)++ <= index,
_1 == 1,
_1 == 0)
);
return result == v.end();
}
void do_switch_no_defaults_tests() {
using namespace boost::lambda;
int i = 0;
std::vector<int> v,w;
// elements from 0 to 9
std::generate_n(std::back_inserter(v),
10,
var(i)++);
std::fill_n(std::back_inserter(w), 10, 0);
// ---
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0]))
)
);
BOOST_TEST(check(w, 0));
std::fill_n(w.begin(), 10, 0);
// ---
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1]))
)
);
BOOST_TEST(check(w, 1));
std::fill_n(w.begin(), 10, 0);
// ---
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2]))
)
);
BOOST_TEST(check(w, 2));
std::fill_n(w.begin(), 10, 0);
// ---
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3]))
)
);
BOOST_TEST(check(w, 3));
std::fill_n(w.begin(), 10, 0);
// ---
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3])),
case_statement<4>(++var(w[4]))
)
);
BOOST_TEST(check(w, 4));
std::fill_n(w.begin(), 10, 0);
// ---
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3])),
case_statement<4>(++var(w[4])),
case_statement<5>(++var(w[5]))
)
);
BOOST_TEST(check(w, 5));
std::fill_n(w.begin(), 10, 0);
// ---
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3])),
case_statement<4>(++var(w[4])),
case_statement<5>(++var(w[5])),
case_statement<6>(++var(w[6]))
)
);
BOOST_TEST(check(w, 6));
std::fill_n(w.begin(), 10, 0);
// ---
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3])),
case_statement<4>(++var(w[4])),
case_statement<5>(++var(w[5])),
case_statement<6>(++var(w[6])),
case_statement<7>(++var(w[7]))
)
);
BOOST_TEST(check(w, 7));
std::fill_n(w.begin(), 10, 0);
// ---
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3])),
case_statement<4>(++var(w[4])),
case_statement<5>(++var(w[5])),
case_statement<6>(++var(w[6])),
case_statement<7>(++var(w[7])),
case_statement<8>(++var(w[8]))
)
);
BOOST_TEST(check(w, 8));
std::fill_n(w.begin(), 10, 0);
}
void do_switch_yes_defaults_tests() {
using namespace boost::lambda;
int i = 0;
std::vector<int> v,w;
// elements from 0 to 9
std::generate_n(std::back_inserter(v),
10,
var(i)++);
std::fill_n(std::back_inserter(w), 10, 0);
int default_count;
// ---
default_count = 0;
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
default_statement(++var(default_count))
)
);
BOOST_TEST(check(w, -1));
BOOST_TEST_EQ(default_count, 10);
std::fill_n(w.begin(), 10, 0);
// ---
default_count = 0;
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
default_statement(++var(default_count))
)
);
BOOST_TEST(check(w, 0));
BOOST_TEST_EQ(default_count, 9);
std::fill_n(w.begin(), 10, 0);
// ---
default_count = 0;
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
default_statement(++var(default_count))
)
);
BOOST_TEST(check(w, 1));
BOOST_TEST_EQ(default_count, 8);
std::fill_n(w.begin(), 10, 0);
// ---
default_count = 0;
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
default_statement(++var(default_count))
)
);
BOOST_TEST(check(w, 2));
BOOST_TEST_EQ(default_count, 7);
std::fill_n(w.begin(), 10, 0);
// ---
default_count = 0;
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3])),
default_statement(++var(default_count))
)
);
BOOST_TEST(check(w, 3));
BOOST_TEST_EQ(default_count, 6);
std::fill_n(w.begin(), 10, 0);
// ---
default_count = 0;
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3])),
case_statement<4>(++var(w[4])),
default_statement(++var(default_count))
)
);
BOOST_TEST(check(w, 4));
BOOST_TEST_EQ(default_count, 5);
std::fill_n(w.begin(), 10, 0);
// ---
default_count = 0;
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3])),
case_statement<4>(++var(w[4])),
case_statement<5>(++var(w[5])),
default_statement(++var(default_count))
)
);
BOOST_TEST(check(w, 5));
BOOST_TEST_EQ(default_count, 4);
std::fill_n(w.begin(), 10, 0);
// ---
default_count = 0;
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3])),
case_statement<4>(++var(w[4])),
case_statement<5>(++var(w[5])),
case_statement<6>(++var(w[6])),
default_statement(++var(default_count))
)
);
BOOST_TEST(check(w, 6));
BOOST_TEST_EQ(default_count, 3);
std::fill_n(w.begin(), 10, 0);
// ---
default_count = 0;
std::for_each(v.begin(), v.end(),
switch_statement(
_1,
case_statement<0>(++var(w[0])),
case_statement<1>(++var(w[1])),
case_statement<2>(++var(w[2])),
case_statement<3>(++var(w[3])),
case_statement<4>(++var(w[4])),
case_statement<5>(++var(w[5])),
case_statement<6>(++var(w[6])),
case_statement<7>(++var(w[7])),
default_statement(++var(default_count))
)
);
BOOST_TEST(check(w, 7));
BOOST_TEST_EQ(default_count, 2);
std::fill_n(w.begin(), 10, 0);
}
void test_empty_cases() {
using namespace boost::lambda;
// ---
switch_statement(
_1,
default_statement()
)(make_const(1));
switch_statement(
_1,
case_statement<1>()
)(make_const(1));
}
int main()
{
do_switch_no_defaults_tests();
do_switch_yes_defaults_tests();
test_empty_cases();
return boost::report_errors();
}

View File

@@ -0,0 +1,77 @@
/*==============================================================================
Copyright (c) 2008 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/phoenix/operator.hpp>
#include <iostream>
#include <boost/detail/lightweight_test.hpp>
bool
f(bool x)
{
return x;
}
bool
g(bool x)
{
return !x;
}
bool
h()
{
BOOST_ERROR("Short-circuit evaluation failure");
return false;
}
template <typename F, typename A1, typename A2, typename R>
void
tester(F f, A1 a1, A2 a2, R r)
{
BOOST_TEST(f(a1, a2) == r);
}
int main()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
using boost::phoenix::placeholders::_2;
// &&
tester(bind(f, true) && bind(g, true), false, false, f(true) && g(true));
tester(bind(f, true) && bind(g, false), false, false, f(true) && g(false));
tester(bind(f, false) && bind(h), false, false, f(false) && h());
tester(bind(f, _1) && bind(g, _2), true, true, f(true) && g(true));
tester(bind(f, _1) && bind(g, _2), true, false, f(true) && g(false));
tester(bind(f, _1) && bind(h), false, false, f(false) && h());
// ||
tester(bind(f, false) || bind(g, true), false, false, f(false) || g(true));
tester(bind(f, false) || bind(g, false), false, false, f(false) || g(false));
tester(bind(f, true) || bind(h), false, false, f(true) || h());
tester(bind(f, _1) || bind(g, _2), false, true, f(false) || g(true));
tester(bind(f, _1) || bind(g, _2), false, false, f(false) || g(false));
tester(bind(f, _1) || bind(h), true, false, f(true) || h());
//
return boost::report_errors();
}

View File

@@ -0,0 +1,146 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/ref.hpp>
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int __cdecl f0() { f1(17); return 0; }
int __cdecl g0() const { g1(17); return 0; }
int __cdecl f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int __cdecl g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int __cdecl f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int __cdecl f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int __cdecl f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int __cdecl g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int __cdecl f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int __cdecl g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int __cdecl f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int __cdecl g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
int __cdecl f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
int __cdecl g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
int __cdecl f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
int __cdecl g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
};
void member_function_test()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
X x;
// 0
bind(&X::f0, &x)();
bind(&X::f0, ref(x))();
bind(&X::g0, &x)();
bind(&X::g0, x)();
bind(&X::g0, ref(x))();
// 1
bind(&X::f1, &x, 1)();
bind(&X::f1, ref(x), 1)();
bind(&X::g1, &x, 1)();
bind(&X::g1, x, 1)();
bind(&X::g1, ref(x), 1)();
// 2
bind(&X::f2, &x, 1, 2)();
bind(&X::f2, ref(x), 1, 2)();
bind(&X::g2, &x, 1, 2)();
bind(&X::g2, x, 1, 2)();
bind(&X::g2, ref(x), 1, 2)();
// 3
bind(&X::f3, &x, 1, 2, 3)();
bind(&X::f3, ref(x), 1, 2, 3)();
bind(&X::g3, &x, 1, 2, 3)();
bind(&X::g3, x, 1, 2, 3)();
bind(&X::g3, ref(x), 1, 2, 3)();
// 4
bind(&X::f4, &x, 1, 2, 3, 4)();
bind(&X::f4, ref(x), 1, 2, 3, 4)();
bind(&X::g4, &x, 1, 2, 3, 4)();
bind(&X::g4, x, 1, 2, 3, 4)();
bind(&X::g4, ref(x), 1, 2, 3, 4)();
// 5
bind(&X::f5, &x, 1, 2, 3, 4, 5)();
bind(&X::f5, ref(x), 1, 2, 3, 4, 5)();
bind(&X::g5, &x, 1, 2, 3, 4, 5)();
bind(&X::g5, x, 1, 2, 3, 4, 5)();
bind(&X::g5, ref(x), 1, 2, 3, 4, 5)();
// 6
bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
// 7
bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,184 @@
/*==============================================================================
Copyright (c) 2001-2004 Peter Dimov and Multi Media Ltd.
Copyright (c) 2001 David Abrahams
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
long f_0()
{
return 17041L;
}
long f_1(long a)
{
return a;
}
long f_2(long a, long b)
{
return a + 10 * b;
}
long f_3(long a, long b, long c)
{
return a + 10 * b + 100 * c;
}
long f_4(long a, long b, long c, long d)
{
return a + 10 * b + 100 * c + 1000 * d;
}
long f_5(long a, long b, long c, long d, long e)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
long f_6(long a, long b, long c, long d, long e, long f)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
long f_7(long a, long b, long c, long d, long e, long f, long g)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
long global_result;
void fv_0()
{
global_result = 17041L;
}
void fv_1(long a)
{
global_result = a;
}
void fv_2(long a, long b)
{
global_result = a + 10 * b;
}
void fv_3(long a, long b, long c)
{
global_result = a + 10 * b + 100 * c;
}
void fv_4(long a, long b, long c, long d)
{
global_result = a + 10 * b + 100 * c + 1000 * d;
}
void fv_5(long a, long b, long c, long d, long e)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
void fv_6(long a, long b, long c, long d, long e, long f)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
void fv_7(long a, long b, long c, long d, long e, long f, long g)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
void fv_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
void fv_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
template<class F, class A> long tester(F const & f, A const & a)
{
return f(a);
}
template<class F, class A> long testerv(F const & f, A const & a)
{
f(a);
return global_result;
}
void function_test()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
int const i = 1;
BOOST_TEST( tester( bind(f_0), i ) == 17041L );
BOOST_TEST( tester( bind(f_1, _1), i ) == 1L );
BOOST_TEST( tester( bind(f_2, _1, 2), i ) == 21L );
BOOST_TEST( tester( bind(f_3, _1, 2, 3), i ) == 321L );
BOOST_TEST( tester( bind(f_4, _1, 2, 3, 4), i ) == 4321L );
BOOST_TEST( tester( bind(f_5, _1, 2, 3, 4, 5), i ) == 54321L );
BOOST_TEST( tester( bind(f_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
BOOST_TEST( tester( bind(f_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
BOOST_TEST( tester( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
BOOST_TEST( tester( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
BOOST_TEST( testerv( bind(fv_0), i ) == 17041L );
BOOST_TEST( testerv( bind(fv_1, _1), i ) == 1L );
BOOST_TEST( testerv( bind(fv_2, _1, 2), i ) == 21L );
BOOST_TEST( testerv( bind(fv_3, _1, 2, 3), i ) == 321L );
BOOST_TEST( testerv( bind(fv_4, _1, 2, 3, 4), i ) == 4321L );
BOOST_TEST( testerv( bind(fv_5, _1, 2, 3, 4, 5), i ) == 54321L );
BOOST_TEST( testerv( bind(fv_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
BOOST_TEST( testerv( bind(fv_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
BOOST_TEST( testerv( bind(fv_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
BOOST_TEST( testerv( bind(fv_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
}
int main()
{
function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,165 @@
/*==============================================================================
Copyright (c) 2004 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
typedef int result_type;
int operator()()
{
return 17041;
}
int operator()() const
{
return -17041;
}
int operator()(int x1)
{
return x1;
}
int operator()(int x1) const
{
return -x1;
}
int operator()(int x1, int x2)
{
return x1+x2;
}
int operator()(int x1, int x2) const
{
return -(x1+x2);
}
int operator()(int x1, int x2, int x3)
{
return x1+x2+x3;
}
int operator()(int x1, int x2, int x3) const
{
return -(x1+x2+x3);
}
int operator()(int x1, int x2, int x3, int x4)
{
return x1+x2+x3+x4;
}
int operator()(int x1, int x2, int x3, int x4) const
{
return -(x1+x2+x3+x4);
}
int operator()(int x1, int x2, int x3, int x4, int x5)
{
return x1+x2+x3+x4+x5;
}
int operator()(int x1, int x2, int x3, int x4, int x5) const
{
return -(x1+x2+x3+x4+x5);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
{
return x1+x2+x3+x4+x5+x6;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6) const
{
return -(x1+x2+x3+x4+x5+x6);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
{
return x1+x2+x3+x4+x5+x6+x7;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) const
{
return -(x1+x2+x3+x4+x5+x6+x7);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
{
return x1+x2+x3+x4+x5+x6+x7+x8;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) const
{
return -(x1+x2+x3+x4+x5+x6+x7+x8);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
{
return x1+x2+x3+x4+x5+x6+x7+x8+x9;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const
{
return -(x1+x2+x3+x4+x5+x6+x7+x8+x9);
}
};
template<class F> void test(F f, int r)
{
F const & cf = f;
BOOST_TEST( cf() == -r );
BOOST_TEST( f() == r );
}
int main()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
using boost::phoenix::cref;
test( bind(X()), 17041);
test( bind(X(), 1), 1);
test( bind(X(), 1, 2), 1+2);
test( bind(X(), 1, 2, 3), 1+2+3);
test( bind(X(), 1, 2, 3, 4), 1+2+3+4);
test( bind(X(), 1, 2, 3, 4, 5), 1+2+3+4+5);
test( bind(X(), 1, 2, 3, 4, 5, 6), 1+2+3+4+5+6);
test( bind(X(), 1, 2, 3, 4, 5, 6, 7), 1+2+3+4+5+6+7);
test( bind(X(), 1, 2, 3, 4, 5, 6, 7, 8), 1+2+3+4+5+6+7+8);
test( bind(X(), 1, 2, 3, 4, 5, 6, 7, 8, 9), 1+2+3+4+5+6+7+8+9);
return boost::report_errors();
}

View File

@@ -0,0 +1,77 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
int m;
};
X f( int v )
{
X r = { v };
return r;
}
int main()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
using boost::phoenix::placeholders::_1;
X x = { 17041 };
X * px = &x;
BOOST_TEST( bind( &X::m, _1 )( x ) == 17041 );
BOOST_TEST( bind( &X::m, _1 )( px ) == 17041 );
BOOST_TEST( bind( &X::m, x )() == 17041 );
BOOST_TEST( bind( &X::m, px )() == 17041 );
BOOST_TEST( bind( &X::m, ref(x) )() == 17041 );
X const cx = x;
X const * pcx = &cx;
BOOST_TEST( bind( &X::m, _1 )( cx ) == 17041 );
BOOST_TEST( bind( &X::m, _1 )( pcx ) == 17041 );
BOOST_TEST( bind( &X::m, cx )() == 17041 );
BOOST_TEST( bind( &X::m, pcx )() == 17041 );
BOOST_TEST( bind( &X::m, ref(cx) )() == 17041 );
int const v = 42;
// Change bind_dm_test.cpp to bind to _1 twice.
BOOST_TEST( bind( &X::m, _1)( bind( f, _1 )( v ) ) == v );
return boost::report_errors();
}

View File

@@ -0,0 +1,74 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#include <string>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
int m;
};
struct Y
{
char m[ 64 ];
};
int main()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
using boost::phoenix::placeholders::_1;
X x = { 0 };
X * px = &x;
bind( &X::m, _1 )( px ) = 42;
BOOST_TEST( x.m == 42 );
bind( &X::m, ref(x) )() = 17041;
BOOST_TEST( x.m == 17041 );
X const * pcx = &x;
BOOST_TEST( bind( &X::m, _1 )( pcx ) == 17041L );
BOOST_TEST( bind( &X::m, pcx )() == 17041L );
Y y = { "test" };
std::string v( "test" );
BOOST_TEST( bind( &Y::m, &y )() == v );
BOOST_TEST( bind( &Y::m, &y )() == v );
return boost::report_errors();
}

View File

@@ -0,0 +1,55 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
#include <utility>
int main()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
typedef std::pair<int, int> pair_type;
pair_type pair( 10, 20 );
#if defined(BOOST_MSVC) && (BOOST_MSVC >= 1600) && (BOOST_MSVC < 1700)
// bind is being confused with 'std::tr1::_Bind' to be found here
// C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxbind1(485)
int const & x = boost::phoenix::bind( &pair_type::first, _1 )( pair );
#else
int const & x = bind( &pair_type::first, _1 )( pair );
#endif
BOOST_TEST( &pair.first == &x );
return boost::report_errors();
}

View File

@@ -0,0 +1,88 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
Copyright (c) 2015 John Fletcher
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
int m;
};
X f( int v )
{
X r = { v };
return r;
}
int main()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
using boost::phoenix::placeholders::_1;
X x = { 17041 };
X * px = &x;
BOOST_TEST( bind( &X::m, _1 )( x ) == 17041 );
BOOST_TEST( bind( &X::m, _1 )( px ) == 17041 );
BOOST_TEST( bind( &X::m, x )() == 17041 );
BOOST_TEST( bind( &X::m, px )() == 17041 );
BOOST_TEST( bind( &X::m, ref(x) )() == 17041 );
X const cx = x;
X const * pcx = &cx;
BOOST_TEST( bind( &X::m, _1 )( cx ) == 17041 );
BOOST_TEST( bind( &X::m, _1 )( pcx ) == 17041 );
BOOST_TEST( bind( &X::m, cx )() == 17041 );
BOOST_TEST( bind( &X::m, pcx )() == 17041 );
BOOST_TEST( bind( &X::m, ref(cx) )() == 17041 );
int const v = 42;
// NOTE: The second case does not work with compiler optimization.
// This is a bug which has not yet been fixed.
// The current test for gcc 4.7.3 does use -O2 but does not
// satisfy this first part of the test for some unknown reason.
// So this is set to run the first case for all gcc 4.7
#if (defined(__OPTIMIZE__) && __OPTIMIZE__) || \
defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 40700) && (BOOST_GCC_VERSION < 40800)
// Change bind_dm_test.cpp to bind to _1 twice.
BOOST_TEST( bind( &X::m, _1)( bind( f, _1 )( v ) ) == v );
#else
BOOST_TEST( bind( &X::m, bind( f, _1 ) )( v ) == v );
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,52 @@
/*==============================================================================
Copyright (c) 2004, 2005, 2009 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/function_equal.hpp>
#include <boost/detail/lightweight_test.hpp>
void f( int )
{
}
int g( int i )
{
return i + 5;
}
template< class F > void test_self_equal( F f )
{
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
using boost::function_equal;
#endif
BOOST_TEST( function_equal( f, f ) );
}
int main()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
test_self_equal( bind( f, _1 ) );
test_self_equal( bind( g, _1 ) );
test_self_equal( bind( f, bind( g, _1 ) ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,48 @@
/*==============================================================================
Copyright (c) 2004, 2005, 2009 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/function_equal.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
int f( boost::weak_ptr<void> wp )
{
return wp.use_count();
}
template< class F > void test_self_equal( F f )
{
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
using boost::function_equal;
#endif
BOOST_TEST( function_equal( f, f ) );
}
int main()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
test_self_equal( bind( f, _1 ) );
test_self_equal( bind( f, boost::weak_ptr<void>() ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,438 @@
/*==============================================================================
Copyright (c) 2004, 2005, 2009 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
# include <boost/function_equal.hpp>
#endif
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
int i_;
explicit X(int i): i_(i)
{
}
bool operator==(X const & rhs) const
{
return i_ == rhs.i_;
}
};
// f_*
int f_0()
{
return 0;
}
int f_1(X)
{
return 0;
}
int f_2(X, X)
{
return 0;
}
int f_3(X, X, X)
{
return 0;
}
int f_4(X, X, X, X)
{
return 0;
}
int f_5(X, X, X, X, X)
{
return 0;
}
int f_6(X, X, X, X, X, X)
{
return 0;
}
int f_7(X, X, X, X, X, X, X)
{
return 0;
}
int f_8(X, X, X, X, X, X, X, X)
{
return 0;
}
int f_9(X, X, X, X, X, X, X, X, X)
{
return 0;
}
// fv_*
void fv_0()
{
}
void fv_1(X)
{
}
void fv_2(X, X)
{
}
void fv_3(X, X, X)
{
}
void fv_4(X, X, X, X)
{
}
void fv_5(X, X, X, X, X)
{
}
void fv_6(X, X, X, X, X, X)
{
}
void fv_7(X, X, X, X, X, X, X)
{
}
void fv_8(X, X, X, X, X, X, X, X)
{
}
void fv_9(X, X, X, X, X, X, X, X, X)
{
}
template<class F> void test_eq(F f1, F f2)
{
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
using boost::function_equal;
#endif
BOOST_TEST( function_equal( f1, f2 ) );
}
template<class F> void test_ne(F f1, F f2)
{
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
using boost::function_equal;
#endif
BOOST_TEST( !function_equal( f1, f2 ) );
}
using boost::phoenix::bind;
using boost::phoenix::ref;
using boost::phoenix::placeholders::_1;
using boost::phoenix::placeholders::_2;
using boost::phoenix::placeholders::_3;
using boost::phoenix::placeholders::_4;
using boost::phoenix::placeholders::_5;
using boost::phoenix::placeholders::_6;
using boost::phoenix::placeholders::_7;
using boost::phoenix::placeholders::_8;
using boost::phoenix::placeholders::_9;
// 0
template<class F> void test_0(F f)
{
test_eq( bind(f), bind(f) );
}
// 1
template<class F, class V> void test_1_(F f, V v1, V v2)
{
test_eq( bind(f, v1), bind(f, v1) );
test_ne( bind(f, v1), bind(f, v2) );
}
template<class F> void test_1(F f)
{
test_eq( bind(f, _1), bind(f, _1) );
test_1_( f, X(1), X(2) );
X a(0), b(0);
test_1_( f, ref(a), ref(b) );
}
// 2
template<class F, class V> void test_2_(F f, V v1, V v2)
{
test_eq( bind(f, v1, v1), bind(f, v1, v1) );
test_ne( bind(f, v1, v1), bind(f, v1, v2) );
test_ne( bind(f, v1, v1), bind(f, v2, v1) );
}
template<class F> void test_2(F f)
{
test_eq( bind(f, _1, _2), bind(f, _1, _2) );
test_2_( f, X(1), X(2) );
X a(0), b(0);
test_2_( f, ref(a), ref(b) );
}
// 3
template<class F, class V> void test_3_(F f, V v1, V v2)
{
test_eq( bind(f, v1, v1, v1), bind(f, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1), bind(f, v1, v1, v2) );
test_ne( bind(f, v1, v1, v1), bind(f, v1, v2, v1) );
test_ne( bind(f, v1, v1, v1), bind(f, v2, v1, v1) );
}
template<class F> void test_3(F f)
{
test_eq( bind(f, _1, _2, _3), bind(f, _1, _2, _3) );
test_3_( f, X(1), X(2) );
X a(0), b(0);
test_3_( f, ref(a), ref(b) );
}
// 4
template<class F, class V> void test_4_(F f, V v1, V v2)
{
test_eq( bind(f, v1, v1, v1, v1), bind(f, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1), bind(f, v1, v1, v1, v2) );
test_ne( bind(f, v1, v1, v1, v1), bind(f, v1, v1, v2, v1) );
test_ne( bind(f, v1, v1, v1, v1), bind(f, v1, v2, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1), bind(f, v2, v1, v1, v1) );
}
template<class F> void test_4(F f)
{
test_eq( bind(f, _1, _2, _3, _4), bind(f, _1, _2, _3, _4) );
test_4_( f, X(1), X(2) );
X a(0), b(0);
test_4_( f, ref(a), ref(b) );
}
// 5
template<class F, class V> void test_5_(F f, V v1, V v2)
{
test_eq( bind(f, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v2) );
test_ne( bind(f, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v2, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1), bind(f, v1, v1, v2, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1), bind(f, v1, v2, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1), bind(f, v2, v1, v1, v1, v1) );
}
template<class F> void test_5(F f)
{
test_eq( bind(f, _1, _2, _3, _4, _5), bind(f, _1, _2, _3, _4, _5) );
test_5_( f, X(1), X(2) );
X a(0), b(0);
test_5_( f, ref(a), ref(b) );
}
// 6
template<class F, class V> void test_6_(F f, V v1, V v2)
{
test_eq( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v2) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v2, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v2, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v2, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v2, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v2, v1, v1, v1, v1, v1) );
}
template<class F> void test_6(F f)
{
test_eq( bind(f, _1, _2, _3, _4, _5, _6), bind(f, _1, _2, _3, _4, _5, _6) );
test_6_( f, X(1), X(2) );
X a(0), b(0);
test_6_( f, ref(a), ref(b) );
}
// 7
template<class F, class V> void test_7_(F f, V v1, V v2)
{
test_eq( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v2) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v2, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v2, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v2, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v2, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v2, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v2, v1, v1, v1, v1, v1, v1) );
}
template<class F> void test_7(F f)
{
test_eq( bind(f, _1, _2, _3, _4, _5, _6, _7), bind(f, _1, _2, _3, _4, _5, _6, _7) );
test_7_( f, X(1), X(2) );
X a(0), b(0);
test_7_( f, ref(a), ref(b) );
}
// 8
template<class F, class V> void test_8_(F f, V v1, V v2)
{
test_eq( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1, v2) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v2, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v2, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v2, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v2, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v2, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v2, v1, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v2, v1, v1, v1, v1, v1, v1, v1) );
}
template<class F> void test_8(F f)
{
test_eq( bind(f, _1, _2, _3, _4, _5, _6, _7, _8), bind(f, _1, _2, _3, _4, _5, _6, _7, _8) );
test_8_( f, X(1), X(2) );
X a(0), b(0);
test_8_( f, ref(a), ref(b) );
}
// 9
template<class F, class V> void test_9_(F f, V v1, V v2)
{
test_eq( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v2) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1, v2, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v2, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v2, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v2, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v2, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v2, v1, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v2, v1, v1, v1, v1, v1, v1, v1) );
test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v2, v1, v1, v1, v1, v1, v1, v1, v1) );
}
template<class F> void test_9(F f)
{
test_eq( bind(f, _1, _2, _3, _4, _5, _6, _7, _8, _9), bind(f, _1, _2, _3, _4, _5, _6, _7, _8, _9) );
test_9_( f, X(1), X(2) );
X a(0), b(0);
test_9_( f, ref(a), ref(b) );
}
int main()
{
// 0
test_0( f_0 );
test_0( fv_0 );
// 1
test_1( f_1 );
test_1( fv_1 );
// 2
test_2( f_2 );
test_2( fv_2 );
// 3
test_3( f_3 );
test_3( fv_3 );
// 4
test_4( f_4 );
test_4( fv_4 );
// 5
test_5( f_5 );
test_5( fv_5 );
// 6
test_6( f_6 );
test_6( fv_6 );
// 7
test_7( f_7 );
test_7( fv_7 );
// 8
test_8( f_8 );
test_8( fv_8 );
// 9
test_9( f_9 );
test_9( fv_9 );
return boost::report_errors();
}

View File

@@ -0,0 +1,165 @@
/*==============================================================================
Copyright (c) 2001 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#define BOOST_MEM_FN_ENABLE_FASTCALL
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
void __fastcall f0() { f1(17); }
void __fastcall g0() const { g1(17); }
void __fastcall f1(int a1) { hash = (hash * 17041 + a1) % 32768; }
void __fastcall g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; }
void __fastcall f2(int a1, int a2) { f1(a1); f1(a2); }
void __fastcall g2(int a1, int a2) const { g1(a1); g1(a2); }
void __fastcall f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); }
void __fastcall g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); }
void __fastcall f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); }
void __fastcall g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); }
void __fastcall f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); }
void __fastcall g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); }
void __fastcall f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); }
void __fastcall g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); }
void __fastcall f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); }
void __fastcall g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); }
void __fastcall f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); }
void __fastcall g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); }
};
void member_function_test()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
X x;
// 0
bind(&X::f0, &x)();
bind(&X::f0, ref(x))();
bind(&X::g0, &x)();
bind(&X::g0, x)();
bind(&X::g0, ref(x))();
// 1
bind(&X::f1, &x, 1)();
bind(&X::f1, ref(x), 1)();
bind(&X::g1, &x, 1)();
bind(&X::g1, x, 1)();
bind(&X::g1, ref(x), 1)();
// 2
bind(&X::f2, &x, 1, 2)();
bind(&X::f2, ref(x), 1, 2)();
bind(&X::g2, &x, 1, 2)();
bind(&X::g2, x, 1, 2)();
bind(&X::g2, ref(x), 1, 2)();
// 3
bind(&X::f3, &x, 1, 2, 3)();
bind(&X::f3, ref(x), 1, 2, 3)();
bind(&X::g3, &x, 1, 2, 3)();
bind(&X::g3, x, 1, 2, 3)();
bind(&X::g3, ref(x), 1, 2, 3)();
// 4
bind(&X::f4, &x, 1, 2, 3, 4)();
bind(&X::f4, ref(x), 1, 2, 3, 4)();
bind(&X::g4, &x, 1, 2, 3, 4)();
bind(&X::g4, x, 1, 2, 3, 4)();
bind(&X::g4, ref(x), 1, 2, 3, 4)();
// 5
bind(&X::f5, &x, 1, 2, 3, 4, 5)();
bind(&X::f5, ref(x), 1, 2, 3, 4, 5)();
bind(&X::g5, &x, 1, 2, 3, 4, 5)();
bind(&X::g5, x, 1, 2, 3, 4, 5)();
bind(&X::g5, ref(x), 1, 2, 3, 4, 5)();
// 6
bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
// 7
bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,110 @@
/*==============================================================================
Copyright (c) 2002 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#define BOOST_BIND_ENABLE_FASTCALL
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
long __fastcall f_0()
{
return 17041L;
}
long __fastcall f_1(long a)
{
return a;
}
long __fastcall f_2(long a, long b)
{
return a + 10 * b;
}
long __fastcall f_3(long a, long b, long c)
{
return a + 10 * b + 100 * c;
}
long __fastcall f_4(long a, long b, long c, long d)
{
return a + 10 * b + 100 * c + 1000 * d;
}
long __fastcall f_5(long a, long b, long c, long d, long e)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
long __fastcall f_6(long a, long b, long c, long d, long e, long f)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
long __fastcall f_7(long a, long b, long c, long d, long e, long f, long g)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
long __fastcall f_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
long __fastcall f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
void function_test()
{
using boost::phoenix::bind;
int const i = 1;
BOOST_TEST( bind(f_0)(i) == 17041L );
BOOST_TEST( bind(f_1, _1)(i) == 1L );
BOOST_TEST( bind(f_2, _1, 2)(i) == 21L );
BOOST_TEST( bind(f_3, _1, 2, 3)(i) == 321L );
BOOST_TEST( bind(f_4, _1, 2, 3, 4)(i) == 4321L );
BOOST_TEST( bind(f_5, _1, 2, 3, 4, 5)(i) == 54321L );
BOOST_TEST( bind(f_6, _1, 2, 3, 4, 5, 6)(i) == 654321L );
BOOST_TEST( bind(f_7, _1, 2, 3, 4, 5, 6, 7)(i) == 7654321L );
BOOST_TEST( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i) == 87654321L );
BOOST_TEST( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L );
}
int main()
{
function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,171 @@
/*==============================================================================
Copyright (c) 2005, 2008 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
long global_result;
// long
long f_0()
{
return global_result = 17041L;
}
long f_1(long a)
{
return global_result = a;
}
long f_2(long a, long b)
{
return global_result = a + 10 * b;
}
long f_3(long a, long b, long c)
{
return global_result = a + 10 * b + 100 * c;
}
long f_4(long a, long b, long c, long d)
{
return global_result = a + 10 * b + 100 * c + 1000 * d;
}
long f_5(long a, long b, long c, long d, long e)
{
return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
long f_6(long a, long b, long c, long d, long e, long f)
{
return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
long f_7(long a, long b, long c, long d, long e, long f, long g)
{
return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
// void
void fv_0()
{
global_result = 17041L;
}
void fv_1(long a)
{
global_result = a;
}
void fv_2(long a, long b)
{
global_result = a + 10 * b;
}
void fv_3(long a, long b, long c)
{
global_result = a + 10 * b + 100 * c;
}
void fv_4(long a, long b, long c, long d)
{
global_result = a + 10 * b + 100 * c + 1000 * d;
}
void fv_5(long a, long b, long c, long d, long e)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
void fv_6(long a, long b, long c, long d, long e, long f)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
void fv_7(long a, long b, long c, long d, long e, long f, long g)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
void fv_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
void fv_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
void function_test()
{
using boost::phoenix::bind;
bind( f_0 )(); BOOST_TEST( global_result == 17041L );
bind( f_1, 1 )(); BOOST_TEST( global_result == 1L );
bind( f_2, 1, 2 )(); BOOST_TEST( global_result == 21L );
bind( f_3, 1, 2, 3 )(); BOOST_TEST( global_result == 321L );
bind( f_4, 1, 2, 3, 4 )(); BOOST_TEST( global_result == 4321L );
bind( f_5, 1, 2, 3, 4, 5 )(); BOOST_TEST( global_result == 54321L );
bind( f_6, 1, 2, 3, 4, 5, 6 )(); BOOST_TEST( global_result == 654321L );
bind( f_7, 1, 2, 3, 4, 5, 6, 7 )(); BOOST_TEST( global_result == 7654321L );
bind( f_8, 1, 2, 3, 4, 5, 6, 7, 8 )(); BOOST_TEST( global_result == 87654321L );
bind( f_9, 1, 2, 3, 4, 5, 6, 7, 8, 9 )(); BOOST_TEST( global_result == 987654321L );
bind( fv_0 )(); BOOST_TEST( global_result == 17041L );
bind( fv_1, 1 )(); BOOST_TEST( global_result == 1L );
bind( fv_2, 1, 2 )(); BOOST_TEST( global_result == 21L );
bind( fv_3, 1, 2, 3 )(); BOOST_TEST( global_result == 321L );
bind( fv_4, 1, 2, 3, 4 )(); BOOST_TEST( global_result == 4321L );
bind( fv_5, 1, 2, 3, 4, 5 )(); BOOST_TEST( global_result == 54321L );
bind( fv_6, 1, 2, 3, 4, 5, 6 )(); BOOST_TEST( global_result == 654321L );
bind( fv_7, 1, 2, 3, 4, 5, 6, 7 )(); BOOST_TEST( global_result == 7654321L );
bind( fv_8, 1, 2, 3, 4, 5, 6, 7, 8 )(); BOOST_TEST( global_result == 87654321L );
bind( fv_9, 1, 2, 3, 4, 5, 6, 7, 8, 9 )(); BOOST_TEST( global_result == 987654321L );
}
int main()
{
function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,79 @@
/*==============================================================================
Copyright (c) 2005, 2008 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
mutable unsigned int hash;
typedef int result_type;
X(): hash(0) {}
int operator()() const { operator()(17); return 0; }
int operator()(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int operator()(int a1, int a2) const { operator()(a1); operator()(a2); return 0; }
int operator()(int a1, int a2, int a3) const { operator()(a1, a2); operator()(a3); return 0; }
int operator()(int a1, int a2, int a3, int a4) const { operator()(a1, a2, a3); operator()(a4); return 0; }
int operator()(int a1, int a2, int a3, int a4, int a5) const { operator()(a1, a2, a3, a4); operator()(a5); return 0; }
int operator()(int a1, int a2, int a3, int a4, int a5, int a6) const { operator()(a1, a2, a3, a4, a5); operator()(a6); return 0; }
int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { operator()(a1, a2, a3, a4, a5, a6); operator()(a7); return 0; }
int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { operator()(a1, a2, a3, a4, a5, a6, a7); operator()(a8); return 0; }
int operator()(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9) const { operator()(a1, a2, a3, a4, a5, a6, a7, a8); operator()(a9); return 0; }
};
void function_object_test()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
X x;
bind(ref(x) )();
bind(ref(x), 1 )();
bind(ref(x), 1, 2 )();
bind(ref(x), 1, 2, 3 )();
bind(ref(x), 1, 2, 3, 4 )();
bind(ref(x), 1, 2, 3, 4, 5 )();
bind(ref(x), 1, 2, 3, 4, 5, 6 )();
bind(ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind(ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
bind(ref(x), 1, 2, 3, 4, 5, 6, 7, 8, 9 )();
BOOST_TEST( x.hash == 9932 );
}
int main()
{
function_object_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,79 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#include <boost/function.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
int f( int x )
{
return x;
}
int g( int x )
{
return x + 1;
}
int main()
{
using boost::phoenix::bind;
boost::function0<int> fn;
BOOST_TEST( !fn.contains( bind( f, 1 ) ) );
BOOST_TEST( !fn.contains( bind( f, 2 ) ) );
BOOST_TEST( !fn.contains( bind( g, 1 ) ) );
fn = bind( f, 1 );
BOOST_TEST( fn() == 1 );
BOOST_TEST( fn.contains( bind( f, 1 ) ) );
BOOST_TEST( !fn.contains( bind( f, 2 ) ) );
BOOST_TEST( !fn.contains( bind( g, 1 ) ) );
fn = bind( f, 2 );
BOOST_TEST( fn() == 2 );
BOOST_TEST( !fn.contains( bind( f, 1 ) ) );
BOOST_TEST( fn.contains( bind( f, 2 ) ) );
BOOST_TEST( !fn.contains( bind( g, 1 ) ) );
fn = bind( g, 1 );
BOOST_TEST( fn() == 2 );
BOOST_TEST( !fn.contains( bind( f, 1 ) ) );
BOOST_TEST( !fn.contains( bind( f, 2 ) ) );
BOOST_TEST( fn.contains( bind( g, 1 ) ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,142 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
Copyright (c) 2015 John Fletcher
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/detail/lightweight_test.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#include <boost/function.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
int f1( int x )
{
return x;
}
int f2( int x, int y )
{
return x + y;
}
struct X
{
mutable int n;
X() : n(0) {}
int f0() { n += f1(17); return n; }
int g0() const { n += g1(17); return n; }
int f1(int a1) { return a1; }
int g1(int a1) const { return a1; }
};
struct Y
{
int m;
};
namespace phx = boost::phoenix;
using phx::placeholders::arg1;
using phx::placeholders::arg2;
using boost::phoenix::ref;
void member_test()
{
Y y = { 17041 };
Y * py = &y;
BOOST_TEST( boost::bind( &Y::m, _1 )( y ) == 17041 );
BOOST_TEST( boost::bind( &Y::m, _1 )( py ) == 17041 );
BOOST_TEST( phx::bind( &Y::m, _1 )( y ) == 17041 );
BOOST_TEST( phx::bind( &Y::m, _1 )( py ) == 17041 );
BOOST_TEST( phx::bind( &Y::m, arg1 )( y ) == 17041 );
BOOST_TEST( phx::bind( &Y::m, arg1 )( py ) == 17041 );
BOOST_TEST( boost::bind( &Y::m, y )() == 17041 );
BOOST_TEST( boost::bind( &Y::m, py )() == 17041 );
//BOOST_TEST( boost::bind( &Y::m, ref(y) )() == 17041 );
BOOST_TEST( phx::bind( &Y::m, y )() == 17041 );
BOOST_TEST( phx::bind( &Y::m, py )() == 17041 );
BOOST_TEST( phx::bind( &Y::m, ref(y) )() == 17041 );
return;
}
void member_function_test()
{
X x;
// 0
BOOST_TEST(boost::bind(&X::f0, &x )() == 17);
//boost::bind(&X::f0, ref(x) )(); boost::bind does not work with phx::ref.
BOOST_TEST(boost::bind(&X::g0, &x )() == 34);
BOOST_TEST(boost::bind(&X::g0, x )() == 51);
//boost::bind(&X::g0, ref(x) )();
BOOST_TEST(phx::bind(&X::f0, &x )() == 51);
BOOST_TEST(phx::bind(&X::f0, ref(x) )() == 68);
BOOST_TEST(phx::bind(&X::g0, &x )() == 85);
BOOST_TEST(phx::bind(&X::g0, x )() == 102);
BOOST_TEST(phx::bind(&X::g0, ref(x) )() == 102);
return;
}
int main()
{
boost::function<int (int)> fun1_f1(boost::bind ( &f1, _1) );
boost::function<int (int)> fun2_f1( phx::bind ( &f1, _1) );
boost::function<int (int)> fun3_f1( phx::bind ( &f1, arg1) );
BOOST_TEST( fun1_f1(1) == 1 );
BOOST_TEST( fun2_f1(2) == 2 );
BOOST_TEST( fun3_f1(3) == 3 );
boost::function<int (int, int)> fun1_f2(boost::bind ( &f2, _1, _2) );
boost::function<int (int, int)> fun2_f2( phx::bind ( &f2, _1, _2) );
boost::function<int (int, int)> fun3_f2( phx::bind ( &f2, arg1, arg2) );
BOOST_TEST( fun1_f2(1,2) == 3 );
BOOST_TEST( fun2_f2(2,3) == 5 );
BOOST_TEST( fun3_f2(3,4) == 7 );
member_function_test();
member_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,42 @@
/*==============================================================================
Copyright (c) 2005 Markus Schoepflin
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
template<class T> void value();
void f0() { }
void f1(int) { }
void f2(int, int) { }
void f3(int, int, int) { }
void f4(int, int, int, int) { }
void f5(int, int, int, int, int) { }
void f6(int, int, int, int, int, int) { }
void f7(int, int, int, int, int, int, int) { }
void f8(int, int, int, int, int, int, int, int) { }
void f9(int, int, int, int, int, int, int, int, int) { }
int main()
{
using boost::phoenix::bind;
bind(f0);
bind(f1, 0);
bind(f2, 0, 0);
bind(f3, 0, 0, 0);
bind(f4, 0, 0, 0, 0);
bind(f5, 0, 0, 0, 0, 0);
bind(f6, 0, 0, 0, 0, 0, 0);
bind(f7, 0, 0, 0, 0, 0, 0, 0);
bind(f8, 0, 0, 0, 0, 0, 0, 0, 0);
bind(f9, 0, 0, 0, 0, 0, 0, 0, 0, 0);
return 0;
}

View File

@@ -0,0 +1,163 @@
/*==============================================================================
Copyright (c) 2005, 2008 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int f0() { f1(17); return 0; }
int g0() const { g1(17); return 0; }
int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
int f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
int g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
int f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
int g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
};
void member_function_test()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
X x;
// 0
bind(&X::f0, &x )();
bind(&X::f0, ref(x) )();
bind(&X::g0, &x )();
bind(&X::g0, x )();
bind(&X::g0, ref(x) )();
// 1
bind(&X::f1, &x, 1 )();
bind(&X::f1, ref(x), 1 )();
bind(&X::g1, &x, 1 )();
bind(&X::g1, x, 1 )();
bind(&X::g1, ref(x), 1 )();
// 2
bind(&X::f2, &x, 1, 2 )();
bind(&X::f2, ref(x), 1, 2 )();
bind(&X::g2, &x, 1, 2 )();
bind(&X::g2, x, 1, 2 )();
bind(&X::g2, ref(x), 1, 2 )();
// 3
bind(&X::f3, &x, 1, 2, 3 )();
bind(&X::f3, ref(x), 1, 2, 3 )();
bind(&X::g3, &x, 1, 2, 3 )();
bind(&X::g3, x, 1, 2, 3 )();
bind(&X::g3, ref(x), 1, 2, 3 )();
// 4
bind(&X::f4, &x, 1, 2, 3, 4 )();
bind(&X::f4, ref(x), 1, 2, 3, 4 )();
bind(&X::g4, &x, 1, 2, 3, 4 )();
bind(&X::g4, x, 1, 2, 3, 4 )();
bind(&X::g4, ref(x), 1, 2, 3, 4 )();
// 5
bind(&X::f5, &x, 1, 2, 3, 4, 5 )();
bind(&X::f5, ref(x), 1, 2, 3, 4, 5 )();
bind(&X::g5, &x, 1, 2, 3, 4, 5 )();
bind(&X::g5, x, 1, 2, 3, 4, 5 )();
bind(&X::g5, ref(x), 1, 2, 3, 4, 5 )();
// 6
bind(&X::f6, &x, 1, 2, 3, 4, 5, 6 )();
bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6 )();
bind(&X::g6, &x, 1, 2, 3, 4, 5, 6 )();
bind(&X::g6, x, 1, 2, 3, 4, 5, 6 )();
bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6 )();
// 7
bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8 )();
bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8 )();
bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8 )();
bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,61 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/phoenix/operator.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
template<class F, class A1, class R> void tester( F f, A1 a1, R r )
{
BOOST_TEST( f(a1) == r );
}
bool f( bool v )
{
return v;
}
int g( int v )
{
return v;
}
int main()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
tester( !bind( f, true ), 0, !f( true ) );
tester( !bind( g, _1 ), 5, !g( 5 ) );
tester( bind( f, !bind( f, true ) ), 0, f( !f( true ) ) );
tester( bind( f, !bind( f, _1 ) ), true, f( !f( true ) ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,87 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined( BOOST_MSVC )
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
long f( long a, long b, long c, long d, long e, long f, long g, long h, long i )
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
template< int I > struct custom_placeholder
: boost::mpl::int_<I>
{
};
namespace boost
{
template< int I > struct is_placeholder< custom_placeholder< I > >
{
enum { value = I + 1};
};
} // namespace boost
int main()
{
using boost::phoenix::bind;
int const x1 = 1;
int const x2 = 2;
int const x3 = 3;
int const x4 = 4;
int const x5 = 5;
int const x6 = 6;
int const x7 = 7;
int const x8 = 8;
int const x9 = 9;
custom_placeholder<0> p1;
custom_placeholder<1> p2;
custom_placeholder<2> p3;
custom_placeholder<3> p4;
custom_placeholder<4> p5;
custom_placeholder<5> p6;
custom_placeholder<6> p7;
custom_placeholder<7> p8;
custom_placeholder<8> p9;
BOOST_TEST(
bind( f, p1, p2, p3, p4, p5, p6, p7, p8, p9 )
( x1, x2, x3, x4, x5, x6, x7, x8, x9 ) == 987654321L );
return boost::report_errors();
}

View File

@@ -0,0 +1,38 @@
/*==============================================================================
Copyright (c) 2009 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/ref.hpp>
#include <boost/detail/lightweight_test.hpp>
struct X
{
int f( int x )
{
return x;
}
int g( int x ) const
{
return -x;
}
};
int main()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
X x;
BOOST_TEST( bind( &X::f, _1, 1 )( boost::ref( x ) ) == 1 );
BOOST_TEST( bind( &X::g, _1, 2 )( boost::cref( x ) ) == -2 );
return boost::report_errors();
}

View File

@@ -0,0 +1,102 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/phoenix/operator.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
int f( int x )
{
return x + x;
}
int g( int x )
{
return 2 * x;
}
int main()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
using boost::phoenix::placeholders::_1;
using boost::phoenix::placeholders::_2;
int x = 4;
int y = x + x;
// bind op value
BOOST_TEST( ( bind( f, _1 ) == y )( x ) );
BOOST_TEST( !( ( bind( f, _1 ) != y )( x ) ) );
BOOST_TEST( !( ( bind( f, _1 ) < y )( x ) ) );
BOOST_TEST( ( bind( f, _1 ) < y + 1 )( x ) );
BOOST_TEST( !( ( bind( f, _1 ) > y )( x ) ) );
BOOST_TEST( ( bind( f, _1 ) > y - 1 )( x ) );
BOOST_TEST( !( ( bind( f, _1 ) <= y - 1 )( x ) ) );
BOOST_TEST( ( bind( f, _1 ) <= y )( x ) );
BOOST_TEST( ( bind( f, _1 ) <= y + 1 )( x ) );
BOOST_TEST( !( ( bind( f, _1 ) >= y + 1 )( x ) ) );
BOOST_TEST( ( bind( f, _1 ) >= y )( x ) );
BOOST_TEST( ( bind( f, _1 ) >= y - 1 )( x ) );
// bind op ref
BOOST_TEST( ( bind( f, _1 ) == ref( y ) )( x ) );
BOOST_TEST( !( ( bind( f, _1 ) != ref( y ) )( x ) ) );
BOOST_TEST( !( ( bind( f, _1 ) < ref( y ) )( x ) ) );
BOOST_TEST( !( ( bind( f, _1 ) > ref( y ) )( x ) ) );
BOOST_TEST( ( bind( f, _1 ) <= ref( y ) )( x ) );
BOOST_TEST( ( bind( f, _1 ) >= ref( y ) )( x ) );
// bind op placeholder
BOOST_TEST( ( bind( f, _1 ) == _2 )( x, y ) );
BOOST_TEST( !( ( bind( f, _1 ) != _2 )( x, y ) ) );
BOOST_TEST( !( ( bind( f, _1 ) < _2 )( x, y ) ) );
BOOST_TEST( !( ( bind( f, _1 ) > _2 )( x, y ) ) );
BOOST_TEST( ( bind( f, _1 ) <= _2 )( x, y ) );
BOOST_TEST( ( bind( f, _1 ) >= _2 )( x, y ) );
// bind op bind
BOOST_TEST( ( bind( f, _1 ) == bind( g, _1 ) )( x ) );
BOOST_TEST( !( ( bind( f, _1 ) != bind( g, _1 ) )( x ) ) );
BOOST_TEST( !( ( bind( f, _1 ) < bind( g, _1 ) )( x ) ) );
BOOST_TEST( ( bind( f, _1 ) <= bind( g, _1 ) )( x ) );
BOOST_TEST( !( ( bind( f, _1 ) > bind( g, _1 ) )( x ) ) );
BOOST_TEST( ( bind( f, _1 ) >= bind( g, _1 ) )( x ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,68 @@
/*==============================================================================
Copyright (c) 2006 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/shared_ptr.hpp>
struct X
{
int v_;
X( int v ): v_( v )
{
}
int f()
{
return v_;
}
};
struct Y
{
boost::shared_ptr<X> f()
{
return boost::shared_ptr<X>( new X( 42 ) );
}
};
int main()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
Y y;
// Change bind_rv_sp_test.cpp to bind to _1.
BOOST_TEST( bind( &X::f, _1) ( bind( &Y::f, &y )()) == 42 );
return boost::report_errors();
}

View File

@@ -0,0 +1,68 @@
/*==============================================================================
Copyright (c) 2006 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/shared_ptr.hpp>
struct X
{
int v_;
X( int v ): v_( v )
{
}
int f()
{
return v_;
}
};
struct Y
{
boost::shared_ptr<X> f()
{
return boost::shared_ptr<X>( new X( 42 ) );
}
};
int main()
{
using boost::phoenix::bind;
//using boost::phoenix::placeholders::_1;
Y y;
// Simplify Change bind_rv_sp_test.cpp to bind to _1.
BOOST_TEST( (*bind( &Y::f, &y )()).f() == 42 );
return boost::report_errors();
}

View File

@@ -0,0 +1,68 @@
/*==============================================================================
Copyright (c) 2006 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/shared_ptr.hpp>
struct X
{
int v_;
X( int v ): v_( v )
{
}
int f()
{
return v_;
}
};
struct Y
{
boost::shared_ptr<X> g()
{
return boost::shared_ptr<X>( new X( 42 ) );
}
};
int main()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
Y y;
// Change bind_rv_sp_test.cpp to bind to _1. Renamed f to g in y
BOOST_TEST( bind( &X::f, _1) ( bind( &Y::g, &y )()) == 42 );
return boost::report_errors();
}

View File

@@ -0,0 +1,70 @@
/*==============================================================================
Copyright (c) 2006 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/shared_ptr.hpp>
struct X
{
int v_;
X( int v ): v_( v )
{
}
int f()
{
return v_;
}
};
struct Y
{
boost::shared_ptr<X> f()
{
return boost::shared_ptr<X>( new X( 42 ) );
}
};
int main()
{
using boost::phoenix::bind;
//using boost::phoenix::placeholders::_1;
Y y;
// Change bind_rv_sp_test.cpp to bind to _1. Renamed f to g in y
//BOOST_TEST( bind( &X::f, _1) ( bind( &Y::g, &y )()) == 42 );
boost::shared_ptr<X> xp = bind( &Y::f, &y )();
BOOST_TEST( bind( &X::f, xp)() == 42 );
return boost::report_errors();
}

View File

@@ -0,0 +1,70 @@
/*==============================================================================
Copyright (c) 2006 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/shared_ptr.hpp>
struct X
{
int v_;
X( int v ): v_( v )
{
}
int f()
{
return v_;
}
};
struct Y
{
boost::shared_ptr<X> f()
{
return boost::shared_ptr<X>( new X( 42 ) );
}
};
int main()
{
using boost::phoenix::bind;
//using boost::phoenix::placeholders::_1;
Y y;
// Change bind_rv_sp_test.cpp to bind to _1. Renamed f to g in y
//BOOST_TEST( bind( &X::f, _1) ( bind( &Y::g, &y )()) == 42 );
boost::shared_ptr<X> xp = bind( &Y::f, &y )();
//BOOST_TEST( bind( &X::f, xp)() == 42 );
BOOST_TEST( (*xp).f() == 42 );
return boost::report_errors();
}

View File

@@ -0,0 +1,71 @@
/*==============================================================================
Copyright (c) 2006 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/shared_ptr.hpp>
struct X
{
int v_;
X( int v ): v_( v )
{
}
int f()
{
return v_;
}
};
struct Y
{
boost::shared_ptr<X> f()
{
return boost::shared_ptr<X>( new X( 42 ) );
}
};
int main()
{
using boost::phoenix::bind;
//using boost::phoenix::placeholders::_1;
Y y;
// Change bind_rv_sp_test.cpp to bind to _1. Renamed f to g in y
//BOOST_TEST( bind( &X::f, _1) ( bind( &Y::g, &y )()) == 42 );
//boost::shared_ptr<X> xp = bind( &Y::f, &y )();
boost::shared_ptr<X> xp = y.f();
BOOST_TEST( bind( &X::f, xp)() == 42 );
//BOOST_TEST( (*xp).f() == 42 );
return boost::report_errors();
}

View File

@@ -0,0 +1,71 @@
/*==============================================================================
Copyright (c) 2006 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/shared_ptr.hpp>
struct X
{
int v_;
X( int v ): v_( v )
{
}
int f()
{
return v_;
}
};
struct Y
{
boost::shared_ptr<X> f()
{
return boost::shared_ptr<X>( new X( 42 ) );
}
};
int main()
{
using boost::phoenix::bind;
//using boost::phoenix::placeholders::_1;
Y y;
// Change bind_rv_sp_test.cpp to bind to _1. Renamed f to g in y
//BOOST_TEST( bind( &X::f, _1) ( bind( &Y::g, &y )()) == 42 );
//boost::shared_ptr<X> xp = bind( &Y::f, &y )();
boost::shared_ptr<X> xp = y.f();
// BOOST_TEST( bind( &X::f, xp)() == 42 );
BOOST_TEST( (*xp).f() == 42 );
return boost::report_errors();
}

View File

@@ -0,0 +1,75 @@
/*==============================================================================
Copyright (c) 2006 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
Copyright (c) 2015 John Fletcher
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
#include <boost/shared_ptr.hpp>
struct X
{
int v_;
X( int v ): v_( v )
{
}
int f()
{
return v_;
}
};
struct Y
{
boost::shared_ptr<X> f()
{
return boost::shared_ptr<X>( new X( 42 ) );
}
};
int main()
{
using boost::phoenix::bind;
Y y;
// MSVC 10,9 and 8 all give a COMDAT error with the full test.
// This also fails:
//boost::shared_ptr<X> xp = bind( &Y::f, &y )();
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1700)
boost::shared_ptr<X> xp = y.f();
BOOST_TEST( bind( &X::f, xp)() == 42 );
#else
BOOST_TEST( bind( &X::f, bind( &Y::f, &y ) )() == 42 );
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,93 @@
/*==============================================================================
Copyright (c) 2006 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined( BOOST_MSVC )
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
int f( int x )
{
return x;
}
int main()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
using boost::phoenix::placeholders::_2;
using boost::phoenix::placeholders::_3;
using boost::phoenix::placeholders::_4;
using boost::phoenix::placeholders::_5;
using boost::phoenix::placeholders::_6;
using boost::phoenix::placeholders::_7;
using boost::phoenix::placeholders::_8;
using boost::phoenix::placeholders::_9;
BOOST_TEST(
bind( f, _1 )
( 1 ) == 1 );
BOOST_TEST(
bind( f, _2 )
( 1, 2 ) == 2 );
BOOST_TEST(
bind( f, _3 )
( 1, 2, 3 ) == 3 );
BOOST_TEST(
bind( f, _4 )
( 1, 2, 3, 4 ) == 4 );
BOOST_TEST(
bind( f, _5 )
( 1, 2, 3, 4, 5 ) == 5 );
BOOST_TEST(
bind( f, _6 )
( 1, 2, 3, 4, 5, 6 ) == 6 );
BOOST_TEST(
bind( f, _7 )
( 1, 2, 3, 4, 5, 6, 7 ) == 7 );
BOOST_TEST(
bind( f, _8 )
( 1, 2, 3, 4, 5, 6, 7, 8 ) == 8 );
BOOST_TEST(
bind( f, _9 )
( 1, 2, 3, 4, 5, 6, 7, 8, 9 ) == 9 );
return boost::report_errors();
}

View File

@@ -0,0 +1,301 @@
/*==============================================================================
Copyright (c) 2004 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
class X
{
private:
mutable int state_;
public:
X(): state_(0)
{
}
int state() const
{
return state_;
}
typedef int result_type;
int operator()() const
{
return state_ += 17041;
}
int operator()(int x1) const
{
return state_ += x1;
}
int operator()(int x1, int x2) const
{
return state_ += x1+x2;
}
int operator()(int x1, int x2, int x3) const
{
return state_ += x1+x2+x3;
}
int operator()(int x1, int x2, int x3, int x4) const
{
return state_ += x1+x2+x3+x4;
}
int operator()(int x1, int x2, int x3, int x4, int x5) const
{
return state_ += x1+x2+x3+x4+x5;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6) const
{
return state_ += x1+x2+x3+x4+x5+x6;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) const
{
return state_ += x1+x2+x3+x4+x5+x6+x7;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) const
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8+x9;
}
};
class Y
{
private:
int state_;
public:
Y(): state_(0)
{
}
int state() const
{
return state_;
}
typedef int result_type;
int operator()()
{
return state_ += 17041;
}
int operator()(int x1)
{
return state_ += x1;
}
int operator()(int x1, int x2)
{
return state_ += x1+x2;
}
int operator()(int x1, int x2, int x3)
{
return state_ += x1+x2+x3;
}
int operator()(int x1, int x2, int x3, int x4)
{
return state_ += x1+x2+x3+x4;
}
int operator()(int x1, int x2, int x3, int x4, int x5)
{
return state_ += x1+x2+x3+x4+x5;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
{
return state_ += x1+x2+x3+x4+x5+x6;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
{
return state_ += x1+x2+x3+x4+x5+x6+x7;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8+x9;
}
};
int f0(int & state_)
{
return state_ += 17041;
}
int f1(int & state_, int x1)
{
return state_ += x1;
}
int f2(int & state_, int x1, int x2)
{
return state_ += x1+x2;
}
int f3(int & state_, int x1, int x2, int x3)
{
return state_ += x1+x2+x3;
}
int f4(int & state_, int x1, int x2, int x3, int x4)
{
return state_ += x1+x2+x3+x4;
}
int f5(int & state_, int x1, int x2, int x3, int x4, int x5)
{
return state_ += x1+x2+x3+x4+x5;
}
int f6(int & state_, int x1, int x2, int x3, int x4, int x5, int x6)
{
return state_ += x1+x2+x3+x4+x5+x6;
}
int f7(int & state_, int x1, int x2, int x3, int x4, int x5, int x6, int x7)
{
return state_ += x1+x2+x3+x4+x5+x6+x7;
}
int f8(int & state_, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8;
}
template <typename> struct wrap {};
template<class F> void test(F f, int a, int b)
{
BOOST_TEST( f() == a + b );
BOOST_TEST( f() == a + 2*b );
BOOST_TEST( f() == a + 3*b );
}
using boost::phoenix::bind;
using boost::phoenix::ref;
void stateful_function_object_test()
{
::test( bind( X() ), 0, 17041 );
::test( bind( X(), 1 ), 0, 1 );
::test( bind( X(), 1, 2 ), 0, 1+2 );
::test( bind( X(), 1, 2, 3 ), 0, 1+2+3 );
::test( bind( X(), 1, 2, 3, 4 ), 0, 1+2+3+4 );
::test( bind( X(), 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 );
::test( bind( X(), 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 );
::test( bind( X(), 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 );
::test( bind( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 );
::test( bind( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 0, 1+2+3+4+5+6+7+8+9 );
Y y;
int n = y.state();
::test( bind( ref(y) ), n, 17041 );
n += 3 * 17041;
::test( bind( ref(y), 1 ), n, 1 );
n += 3*1;
::test( bind( ref(y), 1, 2 ), n, 1+2 );
n += 3*(1+2);
::test( bind( ref(y), 1, 2, 3 ), n, 1+2+3 );
n += 3*(1+2+3);
::test( bind( ref(y), 1, 2, 3, 4 ), n, 1+2+3+4 );
n += 3*(1+2+3+4);
::test( bind( ref(y), 1, 2, 3, 4, 5 ), n, 1+2+3+4+5 );
n += 3*(1+2+3+4+5);
::test( bind( ref(y), 1, 2, 3, 4, 5, 6 ), n, 1+2+3+4+5+6 );
n += 3*(1+2+3+4+5+6);
::test( bind( ref(y), 1, 2, 3, 4, 5, 6, 7 ), n, 1+2+3+4+5+6+7 );
n += 3*(1+2+3+4+5+6+7);
::test( bind( ref(y), 1, 2, 3, 4, 5, 6, 7, 8 ), n, 1+2+3+4+5+6+7+8 );
n += 3*(1+2+3+4+5+6+7+8);
::test( bind( ref(y), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), n, 1+2+3+4+5+6+7+8+9 );
n += 3*(1+2+3+4+5+6+7+8+9);
BOOST_TEST( y.state() == n );
}
void stateful_function_test()
{
using boost::phoenix::ref;
::test( bind( f0, 0), 0, 17041 );
::test( bind( f1, 0, 1 ), 0, 1 );
::test( bind( f2, 0, 1, 2 ), 0, 1+2 );
::test( bind( f3, 0, 1, 2, 3 ), 0, 1+2+3 );
::test( bind( f4, 0, 1, 2, 3, 4 ), 0, 1+2+3+4 );
::test( bind( f5, 0, 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 );
::test( bind( f6, 0, 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 );
::test( bind( f7, 0, 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 );
::test( bind( f8, 0, 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 );
}
int main()
{
stateful_function_object_test();
stateful_function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,167 @@
/*==============================================================================
Copyright (c) 2001 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#define BOOST_MEM_FN_ENABLE_STDCALL
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int __stdcall f0() { f1(17); return 0; }
int __stdcall g0() const { g1(17); return 0; }
int __stdcall f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int __stdcall g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int __stdcall f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int __stdcall g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int __stdcall f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int __stdcall g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int __stdcall f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int __stdcall g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int __stdcall f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int __stdcall g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int __stdcall f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int __stdcall g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
int __stdcall f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
int __stdcall g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
int __stdcall f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
int __stdcall g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
};
void member_function_test()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
X x;
// 0
std::cout << typeid(typename boost::result_of<X::f0()>::type).name() << "\n";
bind(&X::f0, &x)();
bind(&X::f0, ref(x))();
bind(&X::g0, &x)();
bind(&X::g0, x)();
bind(&X::g0, ref(x))();
// 1
bind(&X::f1, &x, 1)();
bind(&X::f1, ref(x), 1)();
bind(&X::g1, &x, 1)();
bind(&X::g1, x, 1)();
bind(&X::g1, ref(x), 1)();
// 2
bind(&X::f2, &x, 1, 2)();
bind(&X::f2, ref(x), 1, 2)();
bind(&X::g2, &x, 1, 2)();
bind(&X::g2, x, 1, 2)();
bind(&X::g2, ref(x), 1, 2)();
// 3
bind(&X::f3, &x, 1, 2, 3)();
bind(&X::f3, ref(x), 1, 2, 3)();
bind(&X::g3, &x, 1, 2, 3)();
bind(&X::g3, x, 1, 2, 3)();
bind(&X::g3, ref(x), 1, 2, 3)();
// 4
bind(&X::f4, &x, 1, 2, 3, 4)();
bind(&X::f4, ref(x), 1, 2, 3, 4)();
bind(&X::g4, &x, 1, 2, 3, 4)();
bind(&X::g4, x, 1, 2, 3, 4)();
bind(&X::g4, ref(x), 1, 2, 3, 4)();
// 5
bind(&X::f5, &x, 1, 2, 3, 4, 5)();
bind(&X::f5, ref(x), 1, 2, 3, 4, 5)();
bind(&X::g5, &x, 1, 2, 3, 4, 5)();
bind(&X::g5, x, 1, 2, 3, 4, 5)();
bind(&X::g5, ref(x), 1, 2, 3, 4, 5)();
// 6
bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
// 7
bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,111 @@
/*==============================================================================
Copyright (c) 2001 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#define BOOST_BIND_ENABLE_STDCALL
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
long __stdcall f_0()
{
return 17041L;
}
long __stdcall f_1(long a)
{
return a;
}
long __stdcall f_2(long a, long b)
{
return a + 10 * b;
}
long __stdcall f_3(long a, long b, long c)
{
return a + 10 * b + 100 * c;
}
long __stdcall f_4(long a, long b, long c, long d)
{
return a + 10 * b + 100 * c + 1000 * d;
}
long __stdcall f_5(long a, long b, long c, long d, long e)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
long __stdcall f_6(long a, long b, long c, long d, long e, long f)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
long __stdcall f_7(long a, long b, long c, long d, long e, long f, long g)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
long __stdcall f_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
long __stdcall f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
void function_test()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
int const i = 1;
BOOST_TEST( bind(f_0)(i) == 17041L );
BOOST_TEST( bind(f_1, _1)(i) == 1L );
BOOST_TEST( bind(f_2, _1, 2)(i) == 21L );
BOOST_TEST( bind(f_3, _1, 2, 3)(i) == 321L );
BOOST_TEST( bind(f_4, _1, 2, 3, 4)(i) == 4321L );
BOOST_TEST( bind(f_5, _1, 2, 3, 4, 5)(i) == 54321L );
BOOST_TEST( bind(f_6, _1, 2, 3, 4, 5, 6)(i) == 654321L );
BOOST_TEST( bind(f_7, _1, 2, 3, 4, 5, 6, 7)(i) == 7654321L );
BOOST_TEST( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i) == 87654321L );
BOOST_TEST( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L );
}
int main()
{
function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,542 @@
/*==============================================================================
Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
Copyright (c) 2001 David Abrahams
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
long f_0()
{
return 17041L;
}
long f_1(long a)
{
return a;
}
long f_2(long a, long b)
{
return a + 10 * b;
}
long f_3(long a, long b, long c)
{
return a + 10 * b + 100 * c;
}
long f_4(long a, long b, long c, long d)
{
return a + 10 * b + 100 * c + 1000 * d;
}
long f_5(long a, long b, long c, long d, long e)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
long f_6(long a, long b, long c, long d, long e, long f)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
long f_7(long a, long b, long c, long d, long e, long f, long g)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
long global_result;
void fv_0()
{
global_result = 17041L;
}
void fv_1(long a)
{
global_result = a;
}
void fv_2(long a, long b)
{
global_result = a + 10 * b;
}
void fv_3(long a, long b, long c)
{
global_result = a + 10 * b + 100 * c;
}
void fv_4(long a, long b, long c, long d)
{
global_result = a + 10 * b + 100 * c + 1000 * d;
}
void fv_5(long a, long b, long c, long d, long e)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
void fv_6(long a, long b, long c, long d, long e, long f)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
void fv_7(long a, long b, long c, long d, long e, long f, long g)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
void fv_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
void fv_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
void function_test()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
int const i = 1;
BOOST_TEST( bind(f_0)(i) == 17041L );
BOOST_TEST( bind(f_1, _1)(i) == 1L );
BOOST_TEST( bind(f_2, _1, 2)(i) == 21L );
BOOST_TEST( bind(f_3, _1, 2, 3)(i) == 321L );
BOOST_TEST( bind(f_4, _1, 2, 3, 4)(i) == 4321L );
BOOST_TEST( bind(f_5, _1, 2, 3, 4, 5)(i) == 54321L );
BOOST_TEST( bind(f_6, _1, 2, 3, 4, 5, 6)(i) == 654321L );
BOOST_TEST( bind(f_7, _1, 2, 3, 4, 5, 6, 7)(i) == 7654321L );
BOOST_TEST( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i) == 87654321L );
BOOST_TEST( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L );
BOOST_TEST( (bind(fv_0)(i), (global_result == 17041L)) );
BOOST_TEST( (bind(fv_1, _1)(i), (global_result == 1L)) );
BOOST_TEST( (bind(fv_2, _1, 2)(i), (global_result == 21L)) );
BOOST_TEST( (bind(fv_3, _1, 2, 3)(i), (global_result == 321L)) );
BOOST_TEST( (bind(fv_4, _1, 2, 3, 4)(i), (global_result == 4321L)) );
BOOST_TEST( (bind(fv_5, _1, 2, 3, 4, 5)(i), (global_result == 54321L)) );
BOOST_TEST( (bind(fv_6, _1, 2, 3, 4, 5, 6)(i), (global_result == 654321L)) );
BOOST_TEST( (bind(fv_7, _1, 2, 3, 4, 5, 6, 7)(i), (global_result == 7654321L)) );
BOOST_TEST( (bind(fv_8, _1, 2, 3, 4, 5, 6, 7, 8)(i), (global_result == 87654321L)) );
BOOST_TEST( (bind(fv_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i), (global_result == 987654321L)) );
}
//
struct Y
{
template <typename Sig>
struct result;
template <typename This, typename A0>
struct result<This(A0 &)> { typedef short type; };
template <typename This, typename A0, typename A1>
struct result<This(A0, A1)> { typedef int type; };
template <typename This, typename A0, typename A1, typename A2>
struct result<This(A0, A1, A2)> { typedef long type; };
template <typename This, typename A0, typename A1, typename A2, typename A3>
struct result<This(A0, A1, A2, A3)> { typedef void type; };
short operator()(short & r) const { return ++r; }
int operator()(int a, int b) const { return a + 10 * b; }
long operator() (long a, long b, long c) const { return a + 10 * b + 100 * c; }
void operator() (long a, long b, long c, long d) const { global_result = a + 10 * b + 100 * c + 1000 * d; }
};
void function_object_test()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
using boost::phoenix::placeholders::_1;
short i(6);
int const k = 3;
BOOST_TEST( bind(Y(), ref(i))() == 7 );
BOOST_TEST( bind(Y(), ref(i))() == 8 );
BOOST_TEST( bind(Y(), i, _1)(k) == 38 );
BOOST_TEST( bind(Y(), i, _1, 9)(k) == 938 );
#if !defined(__MWERKS__) || (__MWERKS__ > 0x2407) // Fails for this version of the compiler.
global_result = 0;
bind(Y(), i, _1, 9, 4)(k);
BOOST_TEST( global_result == 4938 );
#endif
}
void function_object_test2()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
using boost::phoenix::placeholders::_1;
short i(6);
int const k = 3;
BOOST_TEST( bind(Y(), ref(i))() == 7 );
BOOST_TEST( bind(Y(), ref(i))() == 8 );
BOOST_TEST( bind(Y(), i, _1)(k) == 38 );
BOOST_TEST( bind(Y(), i, _1, 9)(k) == 938 );
global_result = 0;
bind(Y(), i, _1, 9, 4)(k);
BOOST_TEST( global_result == 4938 );
}
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
struct Z
{
typedef int result_type;
int operator()(int a, int b) const { return a + 10 * b; }
};
void adaptable_function_object_test()
{
using boost::phoenix::bind;
BOOST_TEST( bind(Z(), 7, 4)() == 47 );
}
#endif
//
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int f0() { f1(17); return 0; }
int g0() const { g1(17); return 0; }
int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
int f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
int g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
int f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
int g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
};
struct V
{
mutable unsigned int hash;
V(): hash(0) {}
void f0() { f1(17); }
void g0() const { g1(17); }
void f1(int a1) { hash = (hash * 17041 + a1) % 32768; }
void g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; }
void f2(int a1, int a2) { f1(a1); f1(a2); }
void g2(int a1, int a2) const { g1(a1); g1(a2); }
void f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); }
void g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); }
void f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); }
void g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); }
void f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); }
void g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); }
void f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); }
void g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); }
void f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); }
void g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); }
void f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); }
void g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); }
};
void member_function_test()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
X x;
// 0
bind(&X::f0, &x)();
bind(&X::f0, ref(x))();
bind(&X::g0, &x)();
bind(&X::g0, x)();
bind(&X::g0, ref(x))();
// 1
bind(&X::f1, &x, 1)();
bind(&X::f1, ref(x), 1)();
bind(&X::g1, &x, 1)();
bind(&X::g1, x, 1)();
bind(&X::g1, ref(x), 1)();
// 2
bind(&X::f2, &x, 1, 2)();
bind(&X::f2, ref(x), 1, 2)();
bind(&X::g2, &x, 1, 2)();
bind(&X::g2, x, 1, 2)();
bind(&X::g2, ref(x), 1, 2)();
// 3
bind(&X::f3, &x, 1, 2, 3)();
bind(&X::f3, ref(x), 1, 2, 3)();
bind(&X::g3, &x, 1, 2, 3)();
bind(&X::g3, x, 1, 2, 3)();
bind(&X::g3, ref(x), 1, 2, 3)();
// 4
bind(&X::f4, &x, 1, 2, 3, 4)();
bind(&X::f4, ref(x), 1, 2, 3, 4)();
bind(&X::g4, &x, 1, 2, 3, 4)();
bind(&X::g4, x, 1, 2, 3, 4)();
bind(&X::g4, ref(x), 1, 2, 3, 4)();
// 5
bind(&X::f5, &x, 1, 2, 3, 4, 5)();
bind(&X::f5, ref(x), 1, 2, 3, 4, 5)();
bind(&X::g5, &x, 1, 2, 3, 4, 5)();
bind(&X::g5, x, 1, 2, 3, 4, 5)();
bind(&X::g5, ref(x), 1, 2, 3, 4, 5)();
// 6
bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
// 7
bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
void member_function_void_test()
{
using boost::phoenix::bind;
using boost::phoenix::ref;
using boost::phoenix::placeholders::_1;
V v;
// 0
bind(&V::f0, &v)();
bind(&V::f0, ref(v))();
bind(&V::g0, &v)();
bind(&V::g0, v)();
bind(&V::g0, ref(v))();
// 1
bind(&V::f1, &v, 1)();
bind(&V::f1, ref(v), 1)();
bind(&V::g1, &v, 1)();
bind(&V::g1, v, 1)();
bind(&V::g1, ref(v), 1)();
// 2
bind(&V::f2, &v, 1, 2)();
bind(&V::f2, ref(v), 1, 2)();
bind(&V::g2, &v, 1, 2)();
bind(&V::g2, v, 1, 2)();
bind(&V::g2, ref(v), 1, 2)();
// 3
bind(&V::f3, &v, 1, 2, 3)();
bind(&V::f3, ref(v), 1, 2, 3)();
bind(&V::g3, &v, 1, 2, 3)();
bind(&V::g3, v, 1, 2, 3)();
bind(&V::g3, ref(v), 1, 2, 3)();
// 4
bind(&V::f4, &v, 1, 2, 3, 4)();
bind(&V::f4, ref(v), 1, 2, 3, 4)();
bind(&V::g4, &v, 1, 2, 3, 4)();
bind(&V::g4, v, 1, 2, 3, 4)();
bind(&V::g4, ref(v), 1, 2, 3, 4)();
// 5
bind(&V::f5, &v, 1, 2, 3, 4, 5)();
bind(&V::f5, ref(v), 1, 2, 3, 4, 5)();
bind(&V::g5, &v, 1, 2, 3, 4, 5)();
bind(&V::g5, v, 1, 2, 3, 4, 5)();
bind(&V::g5, ref(v), 1, 2, 3, 4, 5)();
// 6
bind(&V::f6, &v, 1, 2, 3, 4, 5, 6)();
bind(&V::f6, ref(v), 1, 2, 3, 4, 5, 6)();
bind(&V::g6, &v, 1, 2, 3, 4, 5, 6)();
bind(&V::g6, v, 1, 2, 3, 4, 5, 6)();
bind(&V::g6, ref(v), 1, 2, 3, 4, 5, 6)();
// 7
bind(&V::f7, &v, 1, 2, 3, 4, 5, 6, 7)();
bind(&V::f7, ref(v), 1, 2, 3, 4, 5, 6, 7)();
bind(&V::g7, &v, 1, 2, 3, 4, 5, 6, 7)();
bind(&V::g7, v, 1, 2, 3, 4, 5, 6, 7)();
bind(&V::g7, ref(v), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind(&V::f8, &v, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&V::f8, ref(v), 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&V::g8, &v, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&V::g8, v, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&V::g8, ref(v), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( v.hash == 23558 );
}
void nested_bind_test()
{
using boost::phoenix::bind;
using boost::phoenix::placeholders::_1;
using boost::phoenix::placeholders::_2;
int const x = 1;
int const y = 2;
BOOST_TEST( bind(f_1, bind(f_1, _1))(x) == 1L );
BOOST_TEST( bind(f_1, bind(f_2, _1, _2))(x, y) == 21L );
BOOST_TEST( bind(f_2, bind(f_1, _1), bind(f_1, _1))(x) == 11L );
BOOST_TEST( bind(f_2, bind(f_1, _1), bind(f_1, _2))(x, y) == 21L );
BOOST_TEST( bind(f_1, bind(f_0))() == 17041L );
BOOST_TEST( (bind(fv_1, bind(f_1, _1))(x), (global_result == 1L)) );
BOOST_TEST( (bind(fv_1, bind(f_2, _1, _2))(x, y), (global_result == 21L)) );
BOOST_TEST( (bind(fv_2, bind(f_1, _1), bind(f_1, _1))(x), (global_result == 11L)) );
BOOST_TEST( (bind(fv_2, bind(f_1, _1), bind(f_1, _2))(x, y), (global_result == 21L)) );
BOOST_TEST( (bind(fv_1, bind(f_0))(), (global_result == 17041L)) );
}
int main()
{
function_test();
function_object_test();
function_object_test2();
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
adaptable_function_object_test();
#endif
member_function_test();
member_function_void_test();
nested_bind_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,151 @@
/*==============================================================================
Copyright (c) 2005 Peter Dimov
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2010 Thomas Heller
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
class X
{
private:
void operator& ();
void operator& () const;
public:
typedef void result_type;
void operator()()
{
}
void operator()() const
{
}
void operator()(int)
{
}
void operator()(int) const
{
}
void operator()(int, int)
{
}
void operator()(int, int) const
{
}
void operator()(int, int, int)
{
}
void operator()(int, int, int) const
{
}
void operator()(int, int, int, int)
{
}
void operator()(int, int, int, int) const
{
}
void operator()(int, int, int, int, int)
{
}
void operator()(int, int, int, int, int) const
{
}
void operator()(int, int, int, int, int, int)
{
}
void operator()(int, int, int, int, int, int) const
{
}
void operator()(int, int, int, int, int, int, int)
{
}
void operator()(int, int, int, int, int, int, int) const
{
}
void operator()(int, int, int, int, int, int, int, int)
{
}
void operator()(int, int, int, int, int, int, int, int) const
{
}
void operator()(int, int, int, int, int, int, int, int, int)
{
}
void operator()(int, int, int, int, int, int, int, int, int) const
{
}
};
template<class F> void test_const( F const & f )
{
f();
}
template<class F> void test( F f )
{
f();
test_const( f );
}
int main()
{
using boost::phoenix::bind;
test( bind( X() ) );
test( bind( X(), 1 ) );
test( bind( X(), 1, 2 ) );
test( bind( X(), 1, 2, 3 ) );
test( bind( X(), 1, 2, 3, 4 ) );
test( bind( X(), 1, 2, 3, 4, 5 ) );
test( bind( X(), 1, 2, 3, 4, 5, 6 ) );
test( bind( X(), 1, 2, 3, 4, 5, 6, 7 ) );
test( bind( X(), 1, 2, 3, 4, 5, 6, 7, 8 ) );
test( bind( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ) );
return 0;
}

View File

@@ -0,0 +1,73 @@
/*==============================================================================
Copyright (c) 2006 Peter Dimov
Copyright (c) 2014 Agustin Berge
Copyright (c) 2015 John Fletcher
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/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/bind.hpp>
#include <boost/ref.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
struct Z
{
int m;
};
void member_data_test()
{
using boost::phoenix::bind;
Z z = { 17041 };
Z * pz = &z;
bind<void>( &Z::m, _1 )( z );
bind<void>( &Z::m, _1 )( pz );
bind<void>( &Z::m, z )();
bind<void>( &Z::m, pz )();
bind<void>( &Z::m, boost::ref(z) )();
Z const cz = z;
Z const * pcz = &cz;
bind<void>( &Z::m, _1 )( cz );
bind<void>( &Z::m, _1 )( pcz );
bind<void>( &Z::m, cz )();
bind<void>( &Z::m, pcz )();
bind<void>( &Z::m, boost::ref(cz) )();
}
int main()
{
member_data_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,171 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_void_mf_test.cpp - test for bind<void> with member functions
//
// Copyright (c) 2008 Peter Dimov
// Copyright (c) 2014 Agustin Berge
//
// 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/bind.hpp>
#include <boost/ref.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
long global_result;
//
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int f0() { f1(17); return 0; }
int g0() const { g1(17); return 0; }
int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
int f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
int g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
int f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
int g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
};
void member_function_test()
{
using namespace boost;
X x;
// 0
bind<void>(&X::f0, &x)();
bind<void>(&X::f0, ref(x))();
bind<void>(&X::g0, &x)();
bind<void>(&X::g0, x)();
bind<void>(&X::g0, ref(x))();
// 1
bind<void>(&X::f1, &x, 1)();
bind<void>(&X::f1, ref(x), 1)();
bind<void>(&X::g1, &x, 1)();
bind<void>(&X::g1, x, 1)();
bind<void>(&X::g1, ref(x), 1)();
// 2
bind<void>(&X::f2, &x, 1, 2)();
bind<void>(&X::f2, ref(x), 1, 2)();
bind<void>(&X::g2, &x, 1, 2)();
bind<void>(&X::g2, x, 1, 2)();
bind<void>(&X::g2, ref(x), 1, 2)();
// 3
bind<void>(&X::f3, &x, 1, 2, 3)();
bind<void>(&X::f3, ref(x), 1, 2, 3)();
bind<void>(&X::g3, &x, 1, 2, 3)();
bind<void>(&X::g3, x, 1, 2, 3)();
bind<void>(&X::g3, ref(x), 1, 2, 3)();
// 4
bind<void>(&X::f4, &x, 1, 2, 3, 4)();
bind<void>(&X::f4, ref(x), 1, 2, 3, 4)();
bind<void>(&X::g4, &x, 1, 2, 3, 4)();
bind<void>(&X::g4, x, 1, 2, 3, 4)();
bind<void>(&X::g4, ref(x), 1, 2, 3, 4)();
// 5
bind<void>(&X::f5, &x, 1, 2, 3, 4, 5)();
bind<void>(&X::f5, ref(x), 1, 2, 3, 4, 5)();
bind<void>(&X::g5, &x, 1, 2, 3, 4, 5)();
bind<void>(&X::g5, x, 1, 2, 3, 4, 5)();
bind<void>(&X::g5, ref(x), 1, 2, 3, 4, 5)();
// 6
bind<void>(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
bind<void>(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
bind<void>(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
bind<void>(&X::g6, x, 1, 2, 3, 4, 5, 6)();
bind<void>(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
// 7
bind<void>(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind<void>(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind<void>(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind<void>(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
bind<void>(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind<void>(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind<void>(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
bind<void>(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind<void>(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind<void>(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,139 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_void_test.cpp - test for bind<void>
//
// Copyright (c) 2008 Peter Dimov
// Copyright (c) 2014 Agustin Berge
//
// 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/bind.hpp>
#include <boost/ref.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
long global_result;
long f_0()
{
return global_result = 17041L;
}
long f_1(long a)
{
return global_result = a;
}
long f_2(long a, long b)
{
return global_result = a + 10 * b;
}
long f_3(long a, long b, long c)
{
return global_result = a + 10 * b + 100 * c;
}
long f_4(long a, long b, long c, long d)
{
return global_result = a + 10 * b + 100 * c + 1000 * d;
}
long f_5(long a, long b, long c, long d, long e)
{
return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
long f_6(long a, long b, long c, long d, long e, long f)
{
return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
long f_7(long a, long b, long c, long d, long e, long f, long g)
{
return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
void function_test()
{
using namespace boost;
int const i = 1;
BOOST_TEST( (bind<void>(f_0)(i), (global_result == 17041L)) );
BOOST_TEST( (bind<void>(f_1, _1)(i), (global_result == 1L)) );
BOOST_TEST( (bind<void>(f_2, _1, 2)(i), (global_result == 21L)) );
BOOST_TEST( (bind<void>(f_3, _1, 2, 3)(i), (global_result == 321L)) );
BOOST_TEST( (bind<void>(f_4, _1, 2, 3, 4)(i), (global_result == 4321L)) );
BOOST_TEST( (bind<void>(f_5, _1, 2, 3, 4, 5)(i), (global_result == 54321L)) );
BOOST_TEST( (bind<void>(f_6, _1, 2, 3, 4, 5, 6)(i), (global_result == 654321L)) );
BOOST_TEST( (bind<void>(f_7, _1, 2, 3, 4, 5, 6, 7)(i), (global_result == 7654321L)) );
BOOST_TEST( (bind<void>(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i), (global_result == 87654321L)) );
BOOST_TEST( (bind<void>(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i), (global_result == 987654321L)) );
}
//
struct Y
{
short operator()(short & r) const { return global_result = ++r; }
int operator()(int a, int b) const { return global_result = a + 10 * b; }
long operator() (long a, long b, long c) const { return global_result = a + 10 * b + 100 * c; }
void operator() (long a, long b, long c, long d) const { global_result = a + 10 * b + 100 * c + 1000 * d; }
};
void function_object_test()
{
using namespace boost;
short i(6);
int const k = 3;
BOOST_TEST( (bind<void>(Y(), ref(i))(), (global_result == 7)) );
BOOST_TEST( (bind<void>(Y(), ref(i))(), (global_result == 8)) );
BOOST_TEST( (bind<void>(Y(), i, _1)(k), (global_result == 38)) );
BOOST_TEST( (bind<void>(Y(), i, _1, 9)(k), (global_result == 938)) );
BOOST_TEST( (bind<void>(Y(), i, _1, 9, 4)(k), (global_result == 4938)) );
}
int main()
{
function_test();
function_object_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,947 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
Copyright (c) 2017 Kohei Takahashi
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)
==============================================================================*/
#if !defined(CONTAINER_TESTS_HPP)
#define CONTAINER_TESTS_HPP
#include <boost/detail/lightweight_test.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/stl/container/container.hpp>
#include <iostream>
#include <typeinfo>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP
#include <unordered_map>
#endif
#ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET
#include <unordered_set>
#endif
#ifdef BOOST_MSVC
#pragma warning(disable : 4800)
#endif
using std::cerr;
namespace phx = boost::phoenix;
template <typename T> inline T const build_assoc();
std::deque<int> const build_deque();
std::list<int> const build_list();
std::map<int, int> const build_map();
std::multimap<int, int> const build_multimap();
std::vector<int> const build_vector();
std::set<int> const build_set();
std::multiset<int> const build_multiset();
template <> inline std::map<int, int> const build_assoc() { return build_map(); }
template <> inline std::multimap<int, int> const build_assoc() { return build_multimap(); }
template <> inline std::set<int> const build_assoc() { return build_set(); }
template <> inline std::multiset<int> const build_assoc() { return build_multiset(); }
#ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP
std::unordered_map<int, int> const build_unordered_map();
std::unordered_multimap<int, int> const build_unordered_multimap();
template <> inline std::unordered_map<int, int> const build_assoc() { return build_unordered_map(); }
template <> inline std::unordered_multimap<int, int> const build_assoc() { return build_unordered_multimap(); }
#endif
#ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET
std::unordered_set<int> const build_unordered_set();
std::unordered_multiset<int> const build_unordered_multiset();
template <> inline std::unordered_set<int> const build_assoc() { return build_unordered_set(); }
template <> inline std::unordered_multiset<int> const build_assoc() { return build_unordered_multiset(); }
#endif
inline bool
test(bool fail)
{
BOOST_TEST(!fail);
return fail;
}
template <typename Container>
void test_assign(Container c)
{
using phx::arg_names::arg1;
typename Container::size_type count = 2;
typename Container::const_iterator first = c.begin();
typename Container::const_iterator second = first;
typename Container::value_type value = *first;
phx::assign(arg1, count, value)(c);
// iterators may be invalidated!
first = c.begin();
second = first;
std::advance(second, 1);
if (test(*first != *second)) {
cerr << "Failed " << typeid(Container).name() << " test_assign 1\n";
return;
}
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
// Should not --- does not, Yay! --- compile.
Container const const_c = c;
phx::assign(const_c, count, value);
#endif
}
template <typename Container>
void test_assign2(Container c)
{
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::arg_names::arg3;
Container c2 = c;
typename Container::const_iterator first = c2.begin();
typename Container::const_iterator last = c2.end();
typename Container::size_type size = c2.size();
c.clear();
phx::assign(arg1, arg2, arg3)(c, first, last);
if (test(c.size() != size)) {
cerr << "Failed " << typeid(Container).name()
<< " test_assign2 1\n"
<< "size == " << c.size() << '\n';
return;
}
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
// Should not --- does not, Yay! --- compile.
Container const const_c = c;
phx::assign(const_c, first, second);
#endif
}
template <typename Container>
void test_at(Container c)
{
using phx::arg_names::arg1;
using phx::at;
typename Container::reference r1 = at(arg1, 0)(c);
if (test(r1 != c.at(0))) {
cerr << "Failed " << typeid(Container).name() << " test_at 1\n";
return;
}
typename Container::const_reference r2 = at(arg1, 0)(c);
if (test(r2 != c.at(0))) {
cerr << "Failed " << typeid(Container).name() << " test_at 2\n";
return;
}
Container const const_c = c;
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
// Should not --- does not, Yay! --- compile.
typename Container::reference r3 = at(arg1, 0)(const_c);
#endif
typename Container::const_reference r4 = at(arg1, 0)(const_c);
if (test(r4 != c.at(0))) {
cerr << "Failed " << typeid(Container).name() << " test_at 4\n";
return;
}
}
template <typename Container>
void test_back(Container c)
{
using phx::arg_names::arg1;
using phx::back;
typename Container::reference r1 = back(arg1)(c);
if (test(r1 != c.back())) {
cerr << "Failed " << typeid(Container).name() << " test_back 1\n";
return;
}
typename Container::const_reference r2 = back(arg1)(c);
if (test(r2 != c.back())) {
cerr << "Failed " << typeid(Container).name() << " test_back 2\n";
return;
}
Container const const_c = c;
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
// Should not --- does not, Yay! --- compile.
typename Container::reference r3 = back(arg1)(const_c);
#endif
typename Container::const_reference r4 = back(arg1)(const_c);
if (test(r4 != c.back())) {
cerr << "Failed " << typeid(Container).name() << " test_back 4\n";
return;
}
}
template <typename Container>
void test_begin(Container c)
{
using phx::arg_names::arg1;
using phx::begin;
typename Container::iterator it1 = begin(arg1)(c);
if (test(it1 != c.begin())) {
cerr << "Failed " << typeid(Container).name() << " test_begin 1\n";
return;
}
typename Container::const_iterator it2 = begin(arg1)(c);
if (test(it2 != c.begin())) {
cerr << "Failed " << typeid(Container).name() << " test_begin 2\n";
return;
}
Container const const_c = c;
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
// Should not --- does not, Yay! --- compile.
typename Container::iterator it3 = begin(arg1)(const_c);
#endif
typename Container::const_iterator it4 = begin(arg1)(const_c);
if (test(it4 != const_c.begin())) {
cerr << "Failed " << typeid(Container).name() << " test_begin 4\n";
return;
}
}
template <typename Container>
void test_capacity(Container c)
{
using phx::arg_names::arg1;
using phx::capacity;
typename Container::size_type s1 = capacity(arg1)(c);
if (test(s1 != c.capacity())) {
cerr << "Failed " << typeid(Container).name() << " test_capacity 1\n";
return;
}
Container const const_c = c;
typename Container::size_type s2 = capacity(arg1)(const_c);
if (test(s2 != const_c.capacity())) {
cerr << "Failed " << typeid(Container).name() << " test_capacity 2\n";
return;
}
}
template <typename Container>
void test_clear(Container c)
{
using phx::arg_names::arg1;
using phx::clear;
clear(arg1)(c);
if (test(!c.empty())) {
cerr << "Failed " << typeid(Container).name() << " test_clear 1\n";
return;
}
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
Container const const_c = c;
clear(arg1)(const_c);
#endif
}
template <typename Container>
void test_empty(Container c)
{
using phx::arg_names::arg1;
using phx::empty;
typename Container::size_type s1 = empty(arg1)(c);
if (test(bool(s1) != c.empty())) {
cerr << "Failed " << typeid(Container).name() << " test_empty 1\n";
return;
}
Container const const_c = c;
typename Container::size_type s2 = empty(arg1)(const_c);
if (test(bool(s2) != const_c.empty())) {
cerr << "Failed " << typeid(Container).name() << " test_empty 2\n";
return;
}
}
template <typename Container>
void test_end(Container c)
{
using phx::arg_names::arg1;
using phx::end;
typename Container::iterator it1 = end(arg1)(c);
if (test(it1 != c.end())) {
cerr << "Failed " << typeid(Container).name() << " test_end 1\n";
return;
}
typename Container::const_iterator it2 = end(arg1)(c);
if (test(it2 != c.end())) {
cerr << "Failed " << typeid(Container).name() << " test_end 2\n";
return;
}
Container const const_c = c;
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
// Should not --- does not, Yay! --- compile.
typename Container::iterator it3 = end(arg1)(const_c);
#endif
typename Container::const_iterator it4 = end(arg1)(const_c);
if (test(it4 != const_c.end())) {
cerr << "Failed " << typeid(Container).name() << " test_end 4\n";
return;
}
}
template <typename Container>
void test_erase(Container c)
{
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::arg_names::arg3;
using phx::erase;
Container const const_c = c;
typename Container::size_type size = c.size();
typename Container::iterator c_begin = c.begin();
erase(arg1, arg2)(c, c_begin);
if (test(c.size() + 1 != size)) {
cerr << "Failed " << typeid(Container).name() << " test_erase 1\n";
return;
}
c_begin = c.begin();
typename Container::iterator c_end = c.end();
erase(arg1, arg2, arg3)(c, c_begin, c_end);
if (test(!c.empty())) {
cerr << "Failed " << typeid(Container).name() << " test_erase 2\n";
return;
}
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
erase(arg1, const_c.begin())(const_c);
erase(arg1, const_c.begin(), const_c.end())(const_c);
#endif
}
template <typename Container>
void test_map_erase(Container c)
{
test_erase(c);
if (boost::report_errors() != 0)
return;
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::erase;
typename Container::value_type const value = *c.begin();
typename Container::key_type const key = value.first;
typename Container::size_type const removed =
erase(arg1, arg2)(c, key);
if (test(removed != 1)) {
cerr << "Failed " << typeid(Container).name() << " test_map_erase 1\n";
return;
}
}
template <typename Container>
void test_set_erase(Container c)
{
test_erase(c);
if (boost::report_errors() != 0)
return;
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::erase;
typename Container::value_type const value = *c.begin();
typename Container::key_type const key = value;
typename Container::size_type const removed =
erase(arg1, arg2)(c, key);
if (test(removed != 1)) {
cerr << "Failed " << typeid(Container).name() << " test_set_erase 1\n";
return;
}
}
template <typename Container>
void test_front(Container c)
{
using phx::arg_names::arg1;
using phx::front;
typename Container::reference r1 = front(arg1)(c);
if (test(r1 != c.front())) {
cerr << "Failed " << typeid(Container).name() << " test_front 1\n";
return;
}
typename Container::const_reference r2 = front(arg1)(c);
if (test(r2 != c.front())) {
cerr << "Failed " << typeid(Container).name() << " test_front 2\n";
return;
}
Container const const_c = c;
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
// Should not --- does not, Yay! --- compile.
typename Container::reference r3 = front(arg1)(const_c);
#endif
typename Container::const_reference r4 = front(arg1)(const_c);
if (test(r4 != c.front())) {
cerr << "Failed " << typeid(Container).name() << " test_front 4\n";
return;
}
}
template <typename Container>
void test_get_allocator(Container c)
{
using phx::arg_names::arg1;
using phx::get_allocator;
Container const const_c = c;
typename Container::allocator_type a1 = get_allocator(arg1)(c);
if (test(a1 != c.get_allocator())) {
cerr << "Failed " << typeid(Container).name() << " test_get_allocator 1\n";
return;
}
typename Container::allocator_type a2 = get_allocator(arg1)(const_c);
if (test(a2 != const_c.get_allocator())) {
cerr << "Failed " << typeid(Container).name() << " test_get_allocator 2\n";
return;
}
}
template <typename Container>
void test_insert(Container c)
{
using phx::arg_names::arg1;
using phx::insert;
typename Container::value_type const value = *c.begin();
typename Container::iterator it = insert(arg1, c.begin(), value)(c);
if (test(it != c.begin() || *it != *(++it))) {
cerr << "Failed " << typeid(Container).name() << " test_insert 1\n";
return;
}
typename Container::size_type size = c.size();
insert(arg1, c.begin(), 3, value)(c);
if (test(c.size() != size + 3)) {
cerr << "Failed " << typeid(Container).name() << " test_insert 2\n";
return;
}
Container const const_c = c;
size = c.size();
insert(arg1, c.begin(), const_c.begin(), const_c.end())(c);
if (test(c.size() != 2 * size)) {
cerr << "Failed " << typeid(Container).name() << " test_insert 3\n";
return;
}
}
template <typename Map>
inline void test_map_insert(Map c)
{
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::arg_names::arg3;
typename Map::value_type const value = *c.begin();
typename Map::iterator c_begin = c.begin();
// wrapper for
// iterator insert(iterator where, const value_type& val);
typename Map::iterator it =
phx::insert(arg1, arg2, arg3)(c, c_begin, value);
if (test(it != c.begin() /*|| *it != *(++it)*/)) {
cerr << "Failed " << typeid(Map).name() << " test_map_insert 1\n";
return;
}
// wrapper for
// pair<iterator, bool> insert(const value_type& val);
typename Map::value_type const value2(1400, 2200);
std::pair<typename Map::iterator, bool> result =
phx::insert(arg1, arg2)(c, value2);
if (test(!result.second)) {
cerr << "Failed " << typeid(Map).name() << " test_map_insert 2\n";
return;
}
// wrapper for
// template<class InIt>
// void insert(InIt first, InIt last);
Map const const_c = build_assoc<Map>();
typename Map::size_type size = c.size();
phx::insert(arg1, const_c.begin(), const_c.end())(c);
if (test(c.size() != size + const_c.size())) {
cerr << "Failed " << typeid(Map).name() << " test_map_insert 3\n";
return;
}
}
template <typename Multimap>
inline void test_multimap_insert(Multimap c)
{
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::arg_names::arg3;
typename Multimap::value_type const value = *c.begin();
typename Multimap::iterator c_begin = c.begin();
std::size_t old_size = c.size();
// wrapper for
// iterator insert(iterator where, const value_type& val);
typename Multimap::iterator it =
phx::insert(arg1, arg2, arg3)(c, c_begin, value);
if (test(*it != value || c.size() != old_size + 1)) {
cerr << "Failed " << typeid(Multimap).name()
<< " test_multimap_insert 1\n";
return;
}
// wrapper for
// iterator insert(const value_type& val);
typename Multimap::value_type const value2(1400, 2200);
it = phx::insert(arg1, arg2)(c, value2);
if (test(it == c.end())) {
cerr << "Failed " << typeid(Multimap).name()
<< " test_multimap_insert 2\n";
return;
}
// wrapper for
// template<class InIt>
// void insert(InIt first, InIt last);
Multimap const const_c = build_assoc<Multimap>();
typename Multimap::size_type size = c.size();
phx::insert(arg1, const_c.begin(), const_c.end())(c);
if (test(c.size() != size + const_c.size())) {
cerr << "Failed " << typeid(Multimap).name()
<< " test_multimap_insert 3\n";
return;
}
}
template <typename Set>
inline void test_set_insert(Set c)
{
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::arg_names::arg3;
typename Set::value_type const value = *c.begin();
typename Set::iterator c_begin = c.begin();
// wrapper for
// iterator insert(iterator where, const value_type& val);
typename Set::iterator it =
phx::insert(arg1, arg2, arg3)(c, c_begin, value);
if (test(it != c.begin() /*|| *it != *(++it)*/)) {
cerr << "Failed " << typeid(Set).name() << " test_set_insert 1\n";
return;
}
// wrapper for
// pair<iterator, bool> insert(const value_type& val);
typename Set::value_type const value2(1400);
std::pair<typename Set::iterator, bool> result =
phx::insert(arg1, arg2)(c, value2);
if (test(!result.second)) {
cerr << "Failed " << typeid(Set).name() << " test_set_insert 2\n";
return;
}
// wrapper for
// template<class InIt>
// void insert(InIt first, InIt last);
Set const const_c = build_assoc<Set>();
typename Set::size_type size = c.size();
phx::insert(arg1, const_c.begin(), const_c.end())(c);
if (test(c.size() != size + const_c.size())) {
cerr << "Failed " << typeid(Set).name() << " test_set_insert 3\n";
return;
}
}
template <typename Multiset>
inline void test_multiset_insert(Multiset c)
{
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::arg_names::arg3;
typename Multiset::value_type const value = *c.begin();
typename Multiset::iterator c_begin = c.begin();
std::size_t old_size = c.size();
// wrapper for
// iterator insert(iterator where, const value_type& val);
typename Multiset::iterator it =
phx::insert(arg1, arg2, arg3)(c, c_begin, value);
if (test(*it != value || c.size() != old_size + 1)) {
cerr << "Failed " << typeid(Multiset).name()
<< " test_multiset_insert 1\n";
return;
}
// wrapper for
// iterator insert(const value_type& val);
typename Multiset::value_type const value2(1400);
it = phx::insert(arg1, arg2)(c, value2);
if (test(it == c.end())) {
cerr << "Failed " << typeid(Multiset).name()
<< " test_multiset_insert 2\n";
return;
}
// wrapper for
// template<class InIt>
// void insert(InIt first, InIt last);
Multiset const const_c = build_assoc<Multiset>();
typename Multiset::size_type size = c.size();
phx::insert(arg1, const_c.begin(), const_c.end())(c);
if (test(c.size() != size + const_c.size())) {
cerr << "Failed " << typeid(Multiset).name()
<< " test_multiset_insert 3\n";
return;
}
}
template <typename Container>
void test_key_comp(Container c)
{
using phx::arg_names::arg1;
using phx::key_comp;
typename Container::key_compare comp = key_comp(arg1)(c);
Container const const_c = c;
comp = key_comp(arg1)(const_c);
}
template <typename Container>
void test_max_size(Container c)
{
using phx::arg_names::arg1;
using phx::max_size;
Container const const_c = c;
typename Container::size_type s1 = max_size(arg1)(c);
if (test(s1 != c.max_size())) {
cerr << "Failed " << typeid(Container).name() << " test_max_size 1\n";
return;
}
typename Container::size_type s2 = max_size(arg1)(const_c);
if (test(s2 != const_c.max_size())) {
cerr << "Failed " << typeid(Container).name() << " test_max_size 2\n";
return;
}
}
template <typename Container>
void test_pop_back(Container c)
{
using phx::arg_names::arg1;
using phx::pop_back;
Container const const_c = c;
typename Container::size_type size = c.size();
pop_back(arg1)(c);
if (test(c.size() + 1 != size)) {
cerr << "Failed " << typeid(Container).name() << " test_pop_back 1\n";
return;
}
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
pop_back(arg1)(const_c);
#endif
}
template <typename Container>
void test_pop_front(Container c)
{
using phx::arg_names::arg1;
using phx::pop_front;
Container const const_c = c;
typename Container::size_type size = c.size();
pop_front(arg1)(c);
if (test(c.size() + 1 != size)) {
cerr << "Failed " << typeid(Container).name() << " test_pop_front 1\n";
return;
}
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
pop_front(arg1)(const_c);
#endif
}
template <typename Container>
void test_push_back(Container c)
{
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::push_back;
Container const const_c = c;
typename Container::value_type data = *c.begin();
typename Container::size_type size = c.size();
push_back(arg1, arg2)(c, data);
if (test(c.size() != size + 1)) {
cerr << "Failed " << typeid(Container).name() << " test_push_back 1\n";
return;
}
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
push_back(arg1, arg2)(const_c, data);
#endif
}
template <typename Container>
void test_push_front(Container c)
{
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::push_front;
Container const const_c = c;
typename Container::value_type data = *c.begin();
typename Container::size_type size = c.size();
push_front(arg1, arg2)(c, data);
if (test(c.size() != size + 1)) {
cerr << "Failed " << typeid(Container).name() << " test_push_front 1\n";
return;
}
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
push_front(arg1, arg2)(const_c, data);
#endif
}
template <typename Container>
void test_rbegin(Container c)
{
using phx::arg_names::arg1;
using phx::rbegin;
typename Container::reverse_iterator it1 = rbegin(arg1)(c);
typename Container::reverse_iterator it1_test = c.rbegin();
if (test(it1 != it1_test)) {
cerr << "Failed " << typeid(Container).name() << " test_rbegin 1\n";
return;
}
typename Container::const_reverse_iterator it2 = rbegin(arg1)(c);
typename Container::const_reverse_iterator it2_test = c.rbegin();
if (test(it2 != it2_test)) {
cerr << "Failed " << typeid(Container).name() << " test_rbegin 2\n";
return;
}
Container const const_c = c;
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
// Should not --- does not, Yay! --- compile.
typename Container::reverse_iterator it3 = rbegin(arg1)(const_c);
#endif
typename Container::const_reverse_iterator it4 = rbegin(arg1)(const_c);
it2_test = const_c.rbegin();
if (test(it4 != it2_test)) {
cerr << "Failed " << typeid(Container).name() << " test_rbegin 4\n";
return;
}
}
template <typename Container>
void test_rend(Container c)
{
using phx::arg_names::arg1;
using phx::rend;
typename Container::reverse_iterator it1 = rend(arg1)(c);
typename Container::reverse_iterator it1_test = c.rend();
if (test(it1 != it1_test)) {
cerr << "Failed " << typeid(Container).name() << " test_rend 1\n";
return;
}
typename Container::const_reverse_iterator it2 = rend(arg1)(c);
typename Container::const_reverse_iterator it2_test = c.rend();
if (test(it2 != it2_test)) {
cerr << "Failed " << typeid(Container).name() << " test_rend 2\n";
return;
}
Container const const_c = c;
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
// Should not --- does not, Yay! --- compile.
typename Container::reverse_iterator it3 = rend(arg1)(const_c);
#endif
typename Container::const_reverse_iterator it4 = rend(arg1)(const_c);
it2_test = const_c.rend();
if (test(it4 != it2_test)) {
cerr << "Failed " << typeid(Container).name() << " test_rend 4\n";
return;
}
}
template <typename Container>
void test_reserve(Container c)
{
using phx::arg_names::arg1;
using phx::reserve;
Container const const_c = c;
typename Container::size_type count = 2 * c.size();
reserve(arg1, count)(c);
if (test(c.capacity() < count)) {
cerr << "Failed " << typeid(Container).name() << " test_reserve 1\n";
return;
}
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
reserve(arg1, count)(const_c)(const_c);
#endif
}
template <typename Container>
void test_resize(Container c)
{
using phx::arg_names::arg1;
using phx::resize;
Container const const_c = c;
typename Container::size_type new_size = 2 * c.size();
resize(arg1, new_size)(c);
if (test(c.size() != new_size)) {
cerr << "Failed " << typeid(Container).name() << " test_resize 1\n";
return;
}
new_size = 2 * c.size();
typename Container::value_type value = *c.begin();
resize(arg1, new_size, value)(c);
if (test(c.size() != new_size)) {
cerr << "Failed " << typeid(Container).name() << " test_resize 2\n";
return;
}
#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
new_size = 2 * const_c.size();
resize(arg1, new_size)(const_c);
new_size = 2 * const_c.size();
resize(arg1, new_size, value)(const_c);
#endif
}
template <typename Container>
void test_size(Container c)
{
using phx::arg_names::arg1;
using phx::size;
Container const const_c = c;
typename Container::size_type s1 = size(arg1)(c);
if (test(s1 != c.size())) {
cerr << "Failed " << typeid(Container).name() << " test_size 1\n";
return;
}
typename Container::size_type s2 = size(arg1)(const_c);
if (test(s2 != const_c.size())) {
cerr << "Failed " << typeid(Container).name() << " test_size 2\n";
return;
}
}
template <typename Container>
void test_splice(Container c)
{
using phx::arg_names::arg1;
using phx::arg_names::arg2;
using phx::arg_names::arg3;
using phx::arg_names::arg4;
using phx::arg_names::arg5;
using phx::splice;
typename Container::iterator c_end;
typename Container::iterator c2_begin;
typename Container::iterator c2_end;
typename Container::size_type size = c.size();
Container const copy = c;
Container const copy2 = build_list();
Container c2 = copy2;
size = c.size();
c_end = c.end();
splice(arg1, arg2, arg3)(c, c_end, c2);
if (test(c.size() != 2 * size)) {
cerr << "Failed " << typeid(Container).name() << " test_splice 1\n";
return;
}
c = copy;
c_end = c.end();
c2 = copy2;
c2_begin = c2.begin();
size = c.size() + 1;
splice(arg1, arg2, arg3, arg4)(c, c_end, c2, c2_begin);
if (test(c.size() != size)) {
cerr << "Failed " << typeid(Container).name() << " test_splice 2\n";
return;
}
c = copy;
c_end = c.end();
c2 = copy2;
c2_begin = c2.begin();
c2_end = c2.end();
size = c.size() + c2.size();
/*
splice(arg1, arg2, arg3, arg4, arg5)(c, c_end, c2, c2_begin, c2_end);
if (test(c.size() != size)) {
cerr << "Failed " << typeid(Container).name() << " test_splice 3\n";
return;
}
*/
}
template <typename Container>
void test_value_comp(Container c)
{
using phx::arg_names::arg1;
using phx::value_comp;
typename Container::value_compare comp = value_comp(arg1)(c);
Container const const_c = c;
comp = value_comp(arg1)(const_c);
}
#endif

View File

@@ -0,0 +1,73 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
Copyright (c) 2017 Kohei Takahashi
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::unordered_map<int, int> const build_unordered_map()
{
typedef std::unordered_map<int, int> int_map;
typedef std::vector<int> int_vector;
int_map result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
for (; it != end; ++it) {
int const value = *it;
result[value] = 100 * value;
}
return result;
}
std::unordered_multimap<int, int> const build_unordered_multimap()
{
typedef std::unordered_map<int, int> int_map;
typedef std::unordered_multimap<int, int> int_multimap;
int_map const data = build_unordered_map();
return int_multimap(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((phx::stl::has_mapped_type<std::unordered_multimap<int, int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::unordered_multimap<int, int> >::value));
std::unordered_multimap<int, int> const data = build_unordered_multimap();
test_begin(data);
test_clear(data);
test_empty(data);
test_end(data);
test_map_erase(data);
test_get_allocator(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,74 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
Copyright (c) 2017 Kohei Takahashi
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::unordered_map<int, int> const build_unordered_map()
{
typedef std::unordered_map<int, int> int_map;
typedef std::vector<int> int_vector;
int_map result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
for (; it != end; ++it) {
int const value = *it;
result[value] = 100 * value;
}
return result;
}
std::unordered_multimap<int, int> const build_unordered_multimap()
{
typedef std::unordered_map<int, int> int_map;
typedef std::unordered_multimap<int, int> int_multimap;
int_map const data = build_unordered_map();
return int_multimap(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((phx::stl::has_mapped_type<std::unordered_multimap<int, int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::unordered_multimap<int, int> >::value));
std::unordered_multimap<int, int> const data = build_unordered_multimap();
test_multimap_insert(data);
//test_key_comp(data);
test_max_size(data);
//test_rbegin(data);
//test_rend(data);
test_size(data);
//test_value_comp(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,59 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
Copyright (c) 2017 Kohei Takahashi
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::unordered_set<int> const build_unordered_set()
{
typedef std::unordered_set<int> int_set;
typedef std::vector<int> int_vector;
int_set result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
result.insert(it, end);
return result;
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::unordered_set<int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::unordered_set<int> >::value));
std::unordered_set<int> const data = build_unordered_set();
test_begin(data);
test_clear(data);
test_empty(data);
test_end(data);
test_set_erase(data);
test_get_allocator(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,60 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
Copyright (c) 2017 Kohei Takahashi
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::unordered_set<int> const build_unordered_set()
{
typedef std::unordered_set<int> int_set;
typedef std::vector<int> int_vector;
int_set result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
result.insert(it, end);
return result;
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::unordered_set<int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::unordered_set<int> >::value));
std::unordered_set<int> const data = build_unordered_set();
test_set_insert(data);
//test_key_comp(data);
test_max_size(data);
//test_rbegin(data);
//test_rend(data);
test_size(data);
//test_value_comp(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,70 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
Copyright (c) 2017 Kohei Takahashi
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::unordered_set<int> const build_unordered_set()
{
typedef std::unordered_set<int> int_set;
typedef std::vector<int> int_vector;
int_set result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
result.insert(it, end);
return result;
}
std::unordered_multiset<int> const build_unordered_multiset()
{
typedef std::unordered_set<int> int_set;
typedef std::unordered_multiset<int> int_multiset;
int_set const data = build_unordered_set();
return int_multiset(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::unordered_multiset<int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::unordered_multiset<int> >::value));
std::unordered_multiset<int> const data = build_unordered_multiset();
test_begin(data);
test_clear(data);
test_empty(data);
test_end(data);
test_set_erase(data);
test_get_allocator(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,71 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
Copyright (c) 2017 Kohei Takahashi
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::unordered_set<int> const build_unordered_set()
{
typedef std::unordered_set<int> int_set;
typedef std::vector<int> int_vector;
int_set result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
result.insert(it, end);
return result;
}
std::unordered_multiset<int> const build_unordered_multiset()
{
typedef std::unordered_set<int> int_set;
typedef std::unordered_multiset<int> int_multiset;
int_set const data = build_unordered_set();
return int_multiset(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::unordered_multiset<int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::unordered_multiset<int> >::value));
std::unordered_multiset<int> const data = build_unordered_multiset();
test_multiset_insert(data);
//test_key_comp(data);
test_max_size(data);
//test_rbegin(data);
//test_rend(data);
test_size(data);
//test_value_comp(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,49 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
std::list<int> const build_list()
{
std::vector<int> const data = build_vector();
return std::list<int>(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::list<int> >::value));
BOOST_STATIC_ASSERT((!phx::stl::has_key_type<std::list<int> >::value));
std::list<int> const data = build_list();
test_assign(data);
test_assign2(data);
test_back(data);
test_begin(data);
test_clear(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,51 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
std::list<int> const build_list()
{
std::vector<int> const data = build_vector();
return std::list<int>(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::list<int> >::value));
BOOST_STATIC_ASSERT((!phx::stl::has_key_type<std::list<int> >::value));
std::list<int> const data = build_list();
test_empty(data);
test_end(data);
test_erase(data);
test_front(data);
test_get_allocator(data);
test_insert(data);
test_max_size(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,49 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
std::list<int> const build_list()
{
std::vector<int> const data = build_vector();
return std::list<int>(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::list<int> >::value));
BOOST_STATIC_ASSERT((!phx::stl::has_key_type<std::list<int> >::value));
std::list<int> const data = build_list();
test_pop_back(data);
test_pop_front(data);
test_push_back(data);
test_push_front(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,50 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
std::list<int> const build_list()
{
std::vector<int> const data = build_vector();
return std::list<int>(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::list<int> >::value));
BOOST_STATIC_ASSERT((!phx::stl::has_key_type<std::list<int> >::value));
std::list<int> const data = build_list();
test_rbegin(data);
test_rend(data);
test_resize(data);
test_size(data);
test_splice(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,61 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::map<int, int> const build_map()
{
typedef std::map<int, int> int_map;
typedef std::vector<int> int_vector;
int_map result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
for (; it != end; ++it) {
int const value = *it;
result[value] = 100 * value;
}
return result;
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((phx::stl::has_mapped_type<std::map<int, int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::map<int, int> >::value));
std::map<int, int> const data = build_map();
test_begin(data);
test_clear(data);
test_empty(data);
test_end(data);
test_map_erase(data);
test_get_allocator(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,62 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::map<int, int> const build_map()
{
typedef std::map<int, int> int_map;
typedef std::vector<int> int_vector;
int_map result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
for (; it != end; ++it) {
int const value = *it;
result[value] = 100 * value;
}
return result;
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((phx::stl::has_mapped_type<std::map<int, int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::map<int, int> >::value));
std::map<int, int> const data = build_map();
test_map_insert(data);
test_key_comp(data);
test_max_size(data);
test_rbegin(data);
test_rend(data);
test_size(data);
test_value_comp(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,50 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::vector<int> >::value));
BOOST_STATIC_ASSERT((!phx::stl::has_key_type<std::vector<int> >::value));
std::vector<int> const data = build_vector();
test_assign(data);
test_assign2(data);
test_at(data);
test_back(data);
test_begin(data);
test_capacity(data);
test_clear(data);
test_end(data);
test_empty(data);
test_erase(data);
test_front(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,49 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::vector<int> >::value));
BOOST_STATIC_ASSERT((!phx::stl::has_key_type<std::vector<int> >::value));
std::vector<int> const data = build_vector();
test_get_allocator(data);
test_insert(data);
test_max_size(data);
test_pop_back(data);
test_push_back(data);
test_rbegin(data);
test_rend(data);
test_reserve(data);
test_resize(data);
test_size(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,56 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
std::deque<int> const build_deque()
{
std::vector<int> const data = build_vector();
return std::deque<int>(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::deque<int> >::value));
BOOST_STATIC_ASSERT((!phx::stl::has_key_type<std::deque<int> >::value));
std::deque<int> const data = build_deque();
test_assign(data);
test_assign2(data);
test_at(data);
test_back(data);
test_begin(data);
test_clear(data);
test_front(data);
test_empty(data);
test_end(data);
test_erase(data);
test_get_allocator(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,55 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
std::deque<int> const build_deque()
{
std::vector<int> const data = build_vector();
return std::deque<int>(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::deque<int> >::value));
BOOST_STATIC_ASSERT((!phx::stl::has_key_type<std::deque<int> >::value));
std::deque<int> const data = build_deque();
test_insert(data);
test_max_size(data);
test_pop_back(data);
test_pop_front(data);
test_push_back(data);
test_push_front(data);
test_rbegin(data);
test_rend(data);
test_resize(data);
test_size(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,72 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::map<int, int> const build_map()
{
typedef std::map<int, int> int_map;
typedef std::vector<int> int_vector;
int_map result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
for (; it != end; ++it) {
int const value = *it;
result[value] = 100 * value;
}
return result;
}
std::multimap<int, int> const build_multimap()
{
typedef std::map<int, int> int_map;
typedef std::multimap<int, int> int_multimap;
int_map const data = build_map();
return int_multimap(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((phx::stl::has_mapped_type<std::multimap<int, int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::multimap<int, int> >::value));
std::multimap<int, int> const data = build_multimap();
test_begin(data);
test_clear(data);
test_empty(data);
test_end(data);
test_map_erase(data);
test_get_allocator(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,73 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::map<int, int> const build_map()
{
typedef std::map<int, int> int_map;
typedef std::vector<int> int_vector;
int_map result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
for (; it != end; ++it) {
int const value = *it;
result[value] = 100 * value;
}
return result;
}
std::multimap<int, int> const build_multimap()
{
typedef std::map<int, int> int_map;
typedef std::multimap<int, int> int_multimap;
int_map const data = build_map();
return int_multimap(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((phx::stl::has_mapped_type<std::multimap<int, int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::multimap<int, int> >::value));
std::multimap<int, int> const data = build_multimap();
test_multimap_insert(data);
test_key_comp(data);
test_max_size(data);
test_rbegin(data);
test_rend(data);
test_size(data);
test_value_comp(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,59 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
Copyright (c) 2017 Kohei Takahashi
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::set<int> const build_set()
{
typedef std::set<int> int_set;
typedef std::vector<int> int_vector;
int_set result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
result.insert(it, end);
return result;
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::set<int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::set<int> >::value));
std::set<int> const data = build_set();
test_begin(data);
test_clear(data);
test_empty(data);
test_end(data);
test_set_erase(data);
test_get_allocator(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,60 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
Copyright (c) 2017 Kohei Takahashi
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::set<int> const build_set()
{
typedef std::set<int> int_set;
typedef std::vector<int> int_vector;
int_set result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
result.insert(it, end);
return result;
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::set<int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::set<int> >::value));
std::set<int> const data = build_set();
test_set_insert(data);
test_key_comp(data);
test_max_size(data);
test_rbegin(data);
test_rend(data);
test_size(data);
test_value_comp(data);
return boost::report_errors();
}

View File

@@ -0,0 +1,70 @@
/*=============================================================================
Copyright (c) 2004 Angus Leeming
Copyright (c) 2017 Kohei Takahashi
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 "container_tests.hpp"
#include <boost/static_assert.hpp>
std::set<int> const build_set()
{
typedef std::set<int> int_set;
typedef std::vector<int> int_vector;
int_set result;
int_vector const data = build_vector();
int_vector::const_iterator it = data.begin();
int_vector::const_iterator const end = data.end();
result.insert(it, end);
return result;
}
std::multiset<int> const build_multiset()
{
typedef std::set<int> int_set;
typedef std::multiset<int> int_multiset;
int_set const data = build_set();
return int_multiset(data.begin(), data.end());
}
std::vector<int> const init_vector()
{
typedef std::vector<int> int_vector;
int const data[] = { -4, -3, -2, -1, 0 };
int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
return int_vector(data, data + data_size);
}
std::vector<int> const build_vector()
{
typedef std::vector<int> int_vector;
static int_vector data = init_vector();
int_vector::size_type const size = data.size();
int_vector::iterator it = data.begin();
int_vector::iterator const end = data.end();
for (; it != end; ++it)
*it += size;
return data;
}
int
main()
{
BOOST_STATIC_ASSERT((!phx::stl::has_mapped_type<std::multiset<int> >::value));
BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::multiset<int> >::value));
std::multiset<int> const data = build_multiset();
test_begin(data);
test_clear(data);
test_empty(data);
test_end(data);
test_set_erase(data);
test_get_allocator(data);
return boost::report_errors();
}

Some files were not shown because too many files have changed in this diff Show More