From b84f29c03028f13128627ea59397dd05a00a242b Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Mon, 20 Feb 2012 20:07:29 +0000 Subject: [PATCH] Added test for sequence syntax (to run with and without variadic macro support) and disabled variadic syntax test when variadic macros are not supported. Updated docs. [SVN r77078] --- doc/html/BOOST_LOCAL_FUNCTION.html | 2 +- ...BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX.html | 2 +- .../BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.html | 2 +- doc/html/BOOST_LOCAL_FUNCTION_NAME.html | 2 +- doc/html/BOOST_LOCAL_FUNCTION_TPL.html | 2 +- doc/html/BOOST_LOCAL_FUNCTION_TYPEOF.html | 2 +- doc/html/index.html | 2 +- example/Jamfile.v2 | 2 +- example/add_global_functor.cpp | 4 +- example/add_local_functor.cpp | 4 +- example/add_phoenix.cpp | 4 +- example/expensive_copy_lambda.cpp | 2 +- example/gcc_access.cpp | 8 +- example/gcc_lambda.cpp | 12 +- example/gcc_lambda_cpp11.cpp | 10 +- example/gcc_square.cpp | 8 +- example/gcc_store.cpp | 8 +- example/impl_pp_keyword.cpp | 6 +- example/impl_tparam_tricks.cpp | 6 +- example/n2529_this.cpp | 8 +- example/n2550_find_if.cpp | 8 +- example/phoenix_factorial.cpp | 6 +- example/phoenix_factorial_local.cpp | 6 +- example/scope_exit.cpp | 8 +- test/Jamfile.v2 | 82 +++++---- test/add.cpp | 13 +- test/add_classifiers.cpp | 10 +- test/add_classifiers_seq.cpp | 28 +++ test/add_default.cpp | 14 +- test/add_default_seq.cpp | 19 ++ test/add_except.cpp | 15 +- test/add_except_seq.cpp | 25 +++ test/add_inline.cpp | 14 +- test/add_inline_seq.cpp | 28 +++ test/add_lambda.cpp | 6 +- test/add_params.cpp | 14 +- test/add_params_seq.cpp | 19 ++ test/add_seq.cpp | 29 --- test/add_template.cpp | 13 +- test/add_template_seq.cpp | 31 ++++ test/add_this.cpp | 16 +- test/add_this_seq.cpp | 38 ++++ test/add_typed.cpp | 16 +- test/add_typed_seq.cpp | 37 ++++ test/add_with_default.cpp | 14 +- test/add_with_default_seq.cpp | 21 +++ test/addable.hpp | 2 + test/all_decl.cpp | 174 ++++++++++++++++++ test/{seq.cpp => all_decl_seq.cpp} | 5 +- test/factorial.cpp | 17 +- test/factorial_seq.cpp | 43 +++++ test/goto.cpp | 11 +- test/goto_error.cpp | 14 +- test/goto_error_seq.cpp | 28 +++ test/goto_seq.cpp | 26 +++ test/macro_commas.cpp | 11 +- test/macro_commas_seq.cpp | 40 ++++ test/nesting.cpp | 14 +- test/nesting_seq.cpp | 28 +++ test/operator.cpp | 13 +- test/operator_error.cpp | 15 +- test/operator_error_seq.cpp | 26 +++ test/operator_seq.cpp | 26 +++ test/overload.cpp | 19 +- test/overload_seq.cpp | 42 +++++ test/return_assign.cpp | 19 +- test/return_assign_seq.cpp | 40 ++++ test/return_derivative.cpp | 15 +- test/return_derivative_seq.cpp | 31 ++++ test/return_inc.cpp | 19 +- test/return_inc_seq.cpp | 31 ++++ test/return_setget.cpp | 15 +- test/return_setget_seq.cpp | 38 ++++ test/return_this.cpp | 19 +- test/return_this_seq.cpp | 38 ++++ test/ten_void.cpp | 4 +- test/transform.cpp | 17 +- test/transform_seq.cpp | 38 ++++ test/typeof.cpp | 17 +- test/typeof_seq.cpp | 30 +++ test/typeof_template.cpp | 13 +- test/typeof_template_seq.cpp | 33 ++++ 82 files changed, 1381 insertions(+), 216 deletions(-) create mode 100644 test/add_classifiers_seq.cpp create mode 100644 test/add_default_seq.cpp create mode 100644 test/add_except_seq.cpp create mode 100644 test/add_inline_seq.cpp create mode 100644 test/add_params_seq.cpp delete mode 100644 test/add_seq.cpp create mode 100644 test/add_template_seq.cpp create mode 100644 test/add_this_seq.cpp create mode 100644 test/add_typed_seq.cpp create mode 100644 test/add_with_default_seq.cpp create mode 100644 test/all_decl.cpp rename test/{seq.cpp => all_decl_seq.cpp} (99%) create mode 100644 test/factorial_seq.cpp create mode 100644 test/goto_error_seq.cpp create mode 100644 test/goto_seq.cpp create mode 100644 test/macro_commas_seq.cpp create mode 100644 test/nesting_seq.cpp create mode 100644 test/operator_error_seq.cpp create mode 100644 test/operator_seq.cpp create mode 100644 test/overload_seq.cpp create mode 100644 test/return_assign_seq.cpp create mode 100644 test/return_derivative_seq.cpp create mode 100644 test/return_inc_seq.cpp create mode 100644 test/return_setget_seq.cpp create mode 100644 test/return_this_seq.cpp create mode 100644 test/transform_seq.cpp create mode 100644 test/typeof_seq.cpp create mode 100644 test/typeof_template_seq.cpp diff --git a/doc/html/BOOST_LOCAL_FUNCTION.html b/doc/html/BOOST_LOCAL_FUNCTION.html index cdfa932..aabdaca 100644 --- a/doc/html/BOOST_LOCAL_FUNCTION.html +++ b/doc/html/BOOST_LOCAL_FUNCTION.html @@ -33,7 +33,7 @@ BOOST_LOCAL_FUNCTION(declarations)
-

Description

+

Description

This macro must be used within a declarative context, it must follow the local function result type, it must be followed by the local function body code, and then by the BOOST_LOCAL_FUNCTION_NAME macro (see the Tutorial and Advanced Topics sections):

{ // Some declarative context.
     ...
diff --git a/doc/html/BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX.html b/doc/html/BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX.html
index 7b28dcb..7f49e77 100644
--- a/doc/html/BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX.html
+++ b/doc/html/BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX.html
@@ -33,7 +33,7 @@
 
 BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX
-

Description

+

Description

If programmers leave this configuration macro undefined, its default value is 5 (increasing this number might increase compilation time). When defined by programmers, this macro must be a non-negative integer number.

Note: This macro specifies the maximum number of local function parameters excluding bound variables (which are instead specified by BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX).

See: Tutorial section, Getting Started section, BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.

diff --git a/doc/html/BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.html b/doc/html/BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.html index 38d8c42..85ab9a9 100644 --- a/doc/html/BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.html +++ b/doc/html/BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.html @@ -33,7 +33,7 @@ BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX
-

Description

+

Description

If programmers leave this configuration macro undefined, its default value is 10 (increasing this number might increase compilation time). When defined by programmers, this macro must be a non-negative integer number.

Note: This macro specifies the maximum number of bound variables excluding local function parameters (which are instead specified by BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX).

See: Tutorial section, Getting Started section, BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX.

diff --git a/doc/html/BOOST_LOCAL_FUNCTION_NAME.html b/doc/html/BOOST_LOCAL_FUNCTION_NAME.html index 32a31df..1357c76 100644 --- a/doc/html/BOOST_LOCAL_FUNCTION_NAME.html +++ b/doc/html/BOOST_LOCAL_FUNCTION_NAME.html @@ -33,7 +33,7 @@ BOOST_LOCAL_FUNCTION_NAME(qualified_function_name)
-

Description

+

Description

This macro must follow the local function body code block { ... }:

{ // Some declarative context.
     ...
diff --git a/doc/html/BOOST_LOCAL_FUNCTION_TPL.html b/doc/html/BOOST_LOCAL_FUNCTION_TPL.html
index 9ec4cd0..24e2056 100644
--- a/doc/html/BOOST_LOCAL_FUNCTION_TPL.html
+++ b/doc/html/BOOST_LOCAL_FUNCTION_TPL.html
@@ -33,7 +33,7 @@
 
 BOOST_LOCAL_FUNCTION_TPL(declarations)
-

Description

+

Description

This macro must be used instead of BOOST_LOCAL_FUNCTION when declaring a local function within a template. A part from that, this macro has the exact same syntax as BOOST_LOCAL_FUNCTION (see BOOST_LOCAL_FUNCTION for more information):

{ // Some declarative context with a template.
     ...
diff --git a/doc/html/BOOST_LOCAL_FUNCTION_TYPEOF.html b/doc/html/BOOST_LOCAL_FUNCTION_TYPEOF.html
index 1c413a3..adb7675 100644
--- a/doc/html/BOOST_LOCAL_FUNCTION_TYPEOF.html
+++ b/doc/html/BOOST_LOCAL_FUNCTION_TYPEOF.html
@@ -33,7 +33,7 @@
 
 BOOST_LOCAL_FUNCTION_TYPEOF(bound_variable_name)
-

Description

+

Description

This macro can be used within the local functions body to refer to the bound variable types so to declare local variables, check concepts (using Boost.ConceptCheck), etc (see the Advanced Topics section). This way the local function can be programmed entirely without explicitly specifying the bound variable types thus facilitating maintenance (e.g., if the type of a bound variable changes in the enclosing scope, the local function code does not have to change).

Parameters:

diff --git a/doc/html/index.html b/doc/html/index.html index b99bd82..6c8fbe2 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -222,7 +222,7 @@
- +

Last revised: February 17, 2012 at 19:11:44 GMT

Last revised: February 17, 2012 at 22:11:08 GMT


diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index f4af32f..3d38f77 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -38,7 +38,7 @@ run noncopyable_local_function.cpp ; run phoenix_factorial.cpp ; run phoenix_factorial_local.cpp ; -# Only compile and do not run these programs (they take a long time to run). +# Only compile but do not run profiling programs (they take a long time to run). exe profile_global_functor : profile_global_functor.cpp : /boost/chrono//boost_chrono /boost/system//boost_system diff --git a/example/add_global_functor.cpp b/example/add_global_functor.cpp index 479c1d3..00773a8 100644 --- a/example/add_global_functor.cpp +++ b/example/add_global_functor.cpp @@ -22,7 +22,7 @@ private: // Unfortunately, cannot bind so repeat variable types. const int factor; // Make `factor` constant. }; -BOOST_AUTO_TEST_CASE( test_add_global_functor ) { +BOOST_AUTO_TEST_CASE(test_add_global_functor) { int sum = 0, factor = 10; global_add add(sum, factor); @@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE( test_add_global_functor ) { int nums[] = {2, 3}; std::for_each(nums, nums + 2, add); // Passed as template parameter. - BOOST_CHECK( sum == 60 ); + BOOST_CHECK(sum == 60); } //] diff --git a/example/add_local_functor.cpp b/example/add_local_functor.cpp index f856d94..cf0d514 100644 --- a/example/add_local_functor.cpp +++ b/example/add_local_functor.cpp @@ -8,7 +8,7 @@ #define BOOST_TEST_MODULE TestAddLocalFunctor #include -BOOST_AUTO_TEST_CASE( test_add_local_functor ) +BOOST_AUTO_TEST_CASE(test_add_local_functor) //[add_local_functor { int sum = 0, factor = 10; @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE( test_add_local_functor ) // Unfortunately, cannot pass as template parameter to `std::for_each`. for(size_t i = 0; i < 2; ++i) add(nums[i]); - BOOST_CHECK( sum == 60 ); + BOOST_CHECK(sum == 60); } //] diff --git a/example/add_phoenix.cpp b/example/add_phoenix.cpp index e3cb829..3c39f01 100644 --- a/example/add_phoenix.cpp +++ b/example/add_phoenix.cpp @@ -11,7 +11,7 @@ #include #include -BOOST_AUTO_TEST_CASE( test_add_phoenix ) +BOOST_AUTO_TEST_CASE(test_add_phoenix) //[add_phoenix { using boost::phoenix::let; @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE( test_add_phoenix ) ref(sum) += _f * _1, _1 // Access `sum` by reference. ]); - BOOST_CHECK( sum == 60 ); + BOOST_CHECK(sum == 60); } //] diff --git a/example/expensive_copy_lambda.cpp b/example/expensive_copy_lambda.cpp index d87cff5..7169ebe 100644 --- a/example/expensive_copy_lambda.cpp +++ b/example/expensive_copy_lambda.cpp @@ -34,7 +34,7 @@ int main(void) { #else // NO_LAMBDAS -int main(void) { return 0; } // Trivial program. +int main(void) { return 0; } // Trivial test. #endif // NO_LAMBDAS diff --git a/example/gcc_access.cpp b/example/gcc_access.cpp index bd7872b..4515d6b 100644 --- a/example/gcc_access.cpp +++ b/example/gcc_access.cpp @@ -9,15 +9,15 @@ #define BOOST_TEST_MODULE TestGccAccess #include -BOOST_AUTO_TEST_CASE( test_gcc_access ) { +BOOST_AUTO_TEST_CASE(test_gcc_access) { int nums[] = {1, 2, 3}; int offset = -1; int BOOST_LOCAL_FUNCTION(const bind offset, int* array, int index) { return array[index + offset]; } BOOST_LOCAL_FUNCTION_NAME(access) - BOOST_CHECK( access(nums, 1) == 1 ); - BOOST_CHECK( access(nums, 2) == 2 ); - BOOST_CHECK( access(nums, 3) == 3 ); + BOOST_CHECK(access(nums, 1) == 1); + BOOST_CHECK(access(nums, 2) == 2); + BOOST_CHECK(access(nums, 3) == 3); } diff --git a/example/gcc_lambda.cpp b/example/gcc_lambda.cpp index 196c5e4..65fac57 100644 --- a/example/gcc_lambda.cpp +++ b/example/gcc_lambda.cpp @@ -13,7 +13,7 @@ #include #include -BOOST_AUTO_TEST_CASE( test_gcc_lambda ) { +BOOST_AUTO_TEST_CASE(test_gcc_lambda) { //[gcc_lambda int val = 2; int nums[] = {1, 2, 3}; @@ -26,13 +26,13 @@ BOOST_AUTO_TEST_CASE( test_gcc_lambda ) { ); //] - BOOST_CHECK( iter != end ); - BOOST_CHECK( *iter == val ); + BOOST_CHECK(iter != end); + BOOST_CHECK(*iter == val); } -#else // GCC || !NO_LAMBDAS +#else -int main(void) { return 0; } +int main(void) { return 0; } // Trivial test. -#endif // GCC || !NO_LAMBDAS +#endif diff --git a/example/gcc_lambda_cpp11.cpp b/example/gcc_lambda_cpp11.cpp index 904bfa9..58ca62c 100644 --- a/example/gcc_lambda_cpp11.cpp +++ b/example/gcc_lambda_cpp11.cpp @@ -12,7 +12,7 @@ #include #include -BOOST_AUTO_TEST_CASE( test_gcc_lambda_cpp11 ) { +BOOST_AUTO_TEST_CASE(test_gcc_lambda_cpp11) { //[gcc_lambda_cpp11 int val = 2; int nums[] = {1, 2, 3}; @@ -25,13 +25,13 @@ BOOST_AUTO_TEST_CASE( test_gcc_lambda_cpp11 ) { ); //] - BOOST_CHECK( iter != end ); - BOOST_CHECK( *iter == val ); + BOOST_CHECK(iter != end); + BOOST_CHECK(*iter == val); } -#else // NO_LAMBDAS +#else int main(void) { return 0; } // Trivial test. -#endif // NO_LAMBDAS +#endif diff --git a/example/gcc_square.cpp b/example/gcc_square.cpp index 9f7bbd7..d525994 100644 --- a/example/gcc_square.cpp +++ b/example/gcc_square.cpp @@ -9,15 +9,15 @@ #define BOOST_TEST_MODULE TestGccSquare #include -double add_square(double a, double b) { - double BOOST_LOCAL_FUNCTION(double z) { +int add_square(int a, int b) { + int BOOST_LOCAL_FUNCTION(int z) { return z * z; } BOOST_LOCAL_FUNCTION_NAME(square) return square(a) + square(b); } -BOOST_AUTO_TEST_CASE( test_gcc_square ) { - BOOST_CHECK( add_square(2.0, 4.0) == 20.0 ); +BOOST_AUTO_TEST_CASE(test_gcc_square) { + BOOST_CHECK(add_square(2, 4) == 20); } diff --git a/example/gcc_store.cpp b/example/gcc_store.cpp index aca8dd9..7c0d757 100644 --- a/example/gcc_store.cpp +++ b/example/gcc_store.cpp @@ -22,12 +22,12 @@ void hack(int* array, int size) { intermediate(store, size); } -BOOST_AUTO_TEST_CASE( test_gcc_store ) { +BOOST_AUTO_TEST_CASE(test_gcc_store) { int nums[] = {1, 2, 3}; hack(nums, 3); - BOOST_CHECK( nums[0] == 1 ); - BOOST_CHECK( nums[1] == 2 ); - BOOST_CHECK( nums[2] == -1 ); + BOOST_CHECK(nums[0] == 1); + BOOST_CHECK(nums[1] == 2); + BOOST_CHECK(nums[2] == -1); } diff --git a/example/impl_pp_keyword.cpp b/example/impl_pp_keyword.cpp index 2598705..3d6f2be 100644 --- a/example/impl_pp_keyword.cpp +++ b/example/impl_pp_keyword.cpp @@ -20,9 +20,9 @@ tokens \ ))) -BOOST_AUTO_TEST_CASE( test_impl_pp_keyword ) { - BOOST_CHECK( IS_THIS_BACK(const bind this_) == 1 ); - BOOST_CHECK( IS_THIS_BACK(const bind& x) == 0 ); +BOOST_AUTO_TEST_CASE(test_impl_pp_keyword) { + BOOST_CHECK(IS_THIS_BACK(const bind this_) == 1); + BOOST_CHECK(IS_THIS_BACK(const bind& x) == 0); } //] diff --git a/example/impl_tparam_tricks.cpp b/example/impl_tparam_tricks.cpp index 924471a..4cbaa38 100644 --- a/example/impl_tparam_tricks.cpp +++ b/example/impl_tparam_tricks.cpp @@ -34,7 +34,7 @@ private: interface* func_; }; -BOOST_AUTO_TEST_CASE( test_impl_tparam_tricks ) { +BOOST_AUTO_TEST_CASE(test_impl_tparam_tricks) { int sum = 0, factor = 10; // Local class for local function. @@ -62,11 +62,11 @@ BOOST_AUTO_TEST_CASE( test_impl_tparam_tricks ) { std::vector v(10); std::fill(v.begin(), v.end(), 1); -// std::for_each(v.begin(), v.end(), add_local); // Error but OK on C++11. + // std::for_each(v.begin(), v.end(), add_local); // Error but OK on C++11. std::for_each(v.begin(), v.end(), add_casting); // OK. std::for_each(v.begin(), v.end(), add_virtual); // OK. - BOOST_CHECK( sum == 200 ); + BOOST_CHECK(sum == 200); } //] diff --git a/example/n2529_this.cpp b/example/n2529_this.cpp index 2388588..f869af5 100644 --- a/example/n2529_this.cpp +++ b/example/n2529_this.cpp @@ -25,7 +25,7 @@ struct v { } }; -BOOST_AUTO_TEST_CASE( test_n2529_this ) { +BOOST_AUTO_TEST_CASE(test_n2529_this) { std::vector n(3); n[0] = 1; n[1] = 2; n[2] = 3; @@ -35,8 +35,8 @@ BOOST_AUTO_TEST_CASE( test_n2529_this ) { v vn(n); vn.change_sign_all(i); - BOOST_CHECK( vn.nums.at(0) == -1 ); - BOOST_CHECK( vn.nums.at(1) == 2 ); - BOOST_CHECK( vn.nums.at(2) == -3 ); + BOOST_CHECK(vn.nums.at(0) == -1); + BOOST_CHECK(vn.nums.at(1) == 2); + BOOST_CHECK(vn.nums.at(2) == -3); } diff --git a/example/n2550_find_if.cpp b/example/n2550_find_if.cpp index 46e3596..4add9cb 100644 --- a/example/n2550_find_if.cpp +++ b/example/n2550_find_if.cpp @@ -16,9 +16,9 @@ struct employee { explicit employee(const int& a_salary): salary(a_salary) {} }; -BOOST_AUTO_TEST_CASE( test_n2550_find_if ) { +BOOST_AUTO_TEST_CASE(test_n2550_find_if) { std::vector employees; - employees.push_back(employee( 85000)); + employees.push_back(employee(85000)); employees.push_back(employee(100000)); employees.push_back(employee(120000)); @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE( test_n2550_find_if ) { std::vector::iterator i = std::find_if( employees.begin(), employees.end(), between); - BOOST_CHECK( i != employees.end() ); - BOOST_CHECK( i->salary >= min_salary && i->salary < u_limit ); + BOOST_CHECK(i != employees.end()); + BOOST_CHECK(i->salary >= min_salary && i->salary < u_limit); } diff --git a/example/phoenix_factorial.cpp b/example/phoenix_factorial.cpp index e3cb92b..b1a89a7 100644 --- a/example/phoenix_factorial.cpp +++ b/example/phoenix_factorial.cpp @@ -27,14 +27,14 @@ struct factorial_impl { // Phoenix function from global functor. } }; -BOOST_AUTO_TEST_CASE( test_phoenix_factorial ) { +BOOST_AUTO_TEST_CASE(test_phoenix_factorial) { using boost::phoenix::arg_names::arg1; boost::phoenix::function factorial; int i = 4; - BOOST_CHECK( factorial(i)() == 24 ); // Call. - BOOST_CHECK( factorial(arg1)(i) == 24 ); // Lazy call. + BOOST_CHECK(factorial(i)() == 24); // Call. + BOOST_CHECK(factorial(arg1)(i) == 24); // Lazy call. } //] diff --git a/example/phoenix_factorial_local.cpp b/example/phoenix_factorial_local.cpp index 94f358f..dade5f0 100644 --- a/example/phoenix_factorial_local.cpp +++ b/example/phoenix_factorial_local.cpp @@ -13,7 +13,7 @@ #include //[phoenix_factorial_local -BOOST_AUTO_TEST_CASE( test_phoenix_factorial_local ) { +BOOST_AUTO_TEST_CASE(test_phoenix_factorial_local) { using boost::phoenix::arg_names::arg1; int BOOST_LOCAL_FUNCTION(int n) { // Unfortunately, monomorphic. @@ -24,8 +24,8 @@ BOOST_AUTO_TEST_CASE( test_phoenix_factorial_local ) { factorial(factorial_impl); // Phoenix function from local function. int i = 4; - BOOST_CHECK( factorial(i)() == 24 ); // Call. - BOOST_CHECK( factorial(arg1)(i) == 24 ); // Lazy call. + BOOST_CHECK(factorial(i)() == 24); // Call. + BOOST_CHECK(factorial(arg1)(i) == 24); // Lazy call. } //] diff --git a/example/scope_exit.cpp b/example/scope_exit.cpp index 438f8ca..1600545 100644 --- a/example/scope_exit.cpp +++ b/example/scope_exit.cpp @@ -87,17 +87,17 @@ void world::add_person(person const& a_person) { checkpoint = ++p.evolution_; } -BOOST_AUTO_TEST_CASE( test_scope_exit ) { +BOOST_AUTO_TEST_CASE(test_scope_exit) { person adam, eva; std::ostringstream oss; oss << adam; std::cout << oss.str() << std::endl; - BOOST_CHECK( oss.str() == "person(0, 0)" ); + BOOST_CHECK(oss.str() == "person(0, 0)"); oss.str(""); oss << eva; std::cout << oss.str() << std::endl; - BOOST_CHECK( oss.str() == "person(0, 0)" ); + BOOST_CHECK(oss.str() == "person(0, 0)"); world w; w.add_person(adam); @@ -105,6 +105,6 @@ BOOST_AUTO_TEST_CASE( test_scope_exit ) { oss.str(""); oss << w; std::cout << oss.str() << std::endl; - BOOST_CHECK( oss.str() == "world(3, { person(1, 2), person(2, 2), })" ); + BOOST_CHECK(oss.str() == "world(3, { person(1, 2), person(2, 2), })"); } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 02b07f6..5812652 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -9,42 +9,52 @@ import testing ; project : requirements /boost//unit_test_framework ; -run add.cpp ; -run add_classifiers.cpp ; -run add_default.cpp ; -run add_except.cpp ; -run add_inline.cpp ; +# Run variadic and sequence syntax (also forcing no variadic macros). +rule run-vaseq ( file_name ) +{ + run $(file_name).cpp ; + run $(file_name)_seq.cpp ; + run $(file_name)_seq.cpp : : : BOOST_NO_VARIADIC_MACROS : + $(file_name)_seq_nova : ; +} + +# Compile-fail variadic and sequence syntax (also forcing no variadic macros). +rule compile-fail-vaseq ( file_name ) +{ + compile-fail $(file_name).cpp ; + compile-fail $(file_name)_seq.cpp ; + compile-fail $(file_name)_seq.cpp : BOOST_NO_VARIADIC_MACROS : + $(file_name)_seq_nova ; +} + +run-vaseq add ; +run-vaseq add_classifiers ; +run-vaseq add_default ; +run-vaseq add_except ; +run-vaseq add_inline ; run add_lambda.cpp ; -run add_params.cpp ; -run add_template.cpp ; -run add_this.cpp ; -run add_typed.cpp ; -run add_with_default.cpp ; - -run factorial.cpp ; -run goto.cpp ; -compile-fail goto_error.cpp ; -run macro_commas.cpp ; -run nesting.cpp ; -run operator.cpp ; -compile-fail operator_error.cpp ; -run overload.cpp ; +run-vaseq add_params ; +run-vaseq add_template ; +run-vaseq add_this ; +run-vaseq add_typed ; +run-vaseq add_with_default ; +run-vaseq all_decl ; +run-vaseq factorial ; +run-vaseq goto ; +compile-fail-vaseq goto_error ; +run-vaseq macro_commas ; +run-vaseq nesting ; +run-vaseq operator ; +compile-fail-vaseq operator_error ; +run-vaseq overload ; +run-vaseq return_assign ; +run-vaseq return_derivative ; +run-vaseq return_inc ; +run-vaseq return_setget ; +run-vaseq return_this ; run ten_void.cpp ; -run transform.cpp ; -run typeof.cpp ; -run typeof_template.cpp ; - -run return_assign.cpp ; -run return_derivative.cpp ; -run return_inc.cpp ; -run return_setget.cpp ; -run return_this.cpp ; - -# Compile sequence syntax also forcing no variadic macros. -run add_seq.cpp ; -run add_seq.cpp : : : BOOST_NO_VARIADIC_MACROS - : add_seq_no_variadics : ; -run seq.cpp ; -run seq.cpp : : : BOOST_NO_VARIADIC_MACROS - : seq_no_variadics : ; +run ten_void.cpp : : : BOOST_NO_VARIADIC_MACROS : ten_void_nova : ; +run-vaseq transform ; +run-vaseq typeof ; +run-vaseq typeof_template ; diff --git a/test/add.cpp b/test/add.cpp index 10994e9..b9c7c4b 100644 --- a/test/add.cpp +++ b/test/add.cpp @@ -5,12 +5,15 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestAdd #include #include -BOOST_AUTO_TEST_CASE( test_add ) +BOOST_AUTO_TEST_CASE(test_add) //[add { // Some local scope. int sum = 0, factor = 10; // Variables in scope to bind. @@ -23,7 +26,13 @@ BOOST_AUTO_TEST_CASE( test_add ) int nums[] = {2, 3}; std::for_each(nums, nums + 2, add); // Pass it to an algorithm. - BOOST_CHECK( sum == 60 ); // Assert final summation value. + BOOST_CHECK(sum == 60); // Assert final summation value. } //] +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/add_classifiers.cpp b/test/add_classifiers.cpp index ed05a02..3f53258 100644 --- a/test/add_classifiers.cpp +++ b/test/add_classifiers.cpp @@ -6,25 +6,25 @@ // Home at http://www.boost.org/libs/local_function #include -#ifdef BOOST_NO_AUTO_DECLARATIONS // No C++11 auto declarations. +#if defined(BOOST_NO_AUTO_DECLARATIONS) && !defined(BOOST_NO_VARIADIC_MACROS) #include #define BOOST_TEST_MODULE TestAddClassifiers #include -BOOST_AUTO_TEST_CASE( test_add_classifiers ) { +BOOST_AUTO_TEST_CASE(test_add_classifiers) { //[add_classifiers int BOOST_LOCAL_FUNCTION(auto int x, register int y) { // Classifiers. return x + y; } BOOST_LOCAL_FUNCTION_NAME(add) //] - BOOST_CHECK( add(1, 2) == 3 ); + BOOST_CHECK(add(1, 2) == 3); } -#else // C++11 auto declarations. +#else -int main(void) { return 0; } // Trivial program. +int main(void) { return 0; } // Trivial test. #endif diff --git a/test/add_classifiers_seq.cpp b/test/add_classifiers_seq.cpp new file mode 100644 index 0000000..ed1fe0f --- /dev/null +++ b/test/add_classifiers_seq.cpp @@ -0,0 +1,28 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#ifdef BOOST_NO_AUTO_DECLARATIONS + +#include +#define BOOST_TEST_MODULE TestAddClassifiersSeq +#include + +BOOST_AUTO_TEST_CASE(test_add_classifiers_seq) { + int BOOST_LOCAL_FUNCTION( (auto int x) (register int y) ) { + return x + y; + } BOOST_LOCAL_FUNCTION_NAME(add) + + BOOST_CHECK(add(1, 2) == 3); +} + +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/add_default.cpp b/test/add_default.cpp index 6247f07..a2962a7 100644 --- a/test/add_default.cpp +++ b/test/add_default.cpp @@ -5,18 +5,26 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestAddDefault #include -BOOST_AUTO_TEST_CASE( test_add_default ) { +BOOST_AUTO_TEST_CASE(test_add_default) { //[add_default int BOOST_LOCAL_FUNCTION(int x, int y, default 2) { // Default. return x + y; } BOOST_LOCAL_FUNCTION_NAME(add) - BOOST_CHECK( add(1) == 3 ); + BOOST_CHECK(add(1) == 3); //] } -//] + +#else + +int main(void) { return 0; } // Trivial test. + +#endif diff --git a/test/add_default_seq.cpp b/test/add_default_seq.cpp new file mode 100644 index 0000000..4b3a2a1 --- /dev/null +++ b/test/add_default_seq.cpp @@ -0,0 +1,19 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestAddDefaultSeq +#include + +BOOST_AUTO_TEST_CASE(test_add_default_seq) { + int BOOST_LOCAL_FUNCTION( (int x) (int y)(default 2) ) { + return x + y; + } BOOST_LOCAL_FUNCTION_NAME(add) + + BOOST_CHECK(add(1) == 3); +} + diff --git a/test/add_except.cpp b/test/add_except.cpp index c2cd08b..3fdd826 100644 --- a/test/add_except.cpp +++ b/test/add_except.cpp @@ -5,11 +5,14 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestAddExcept #include -BOOST_AUTO_TEST_CASE( test_except ) { +BOOST_AUTO_TEST_CASE(test_except) { //[add_except double sum = 0.0; int factor = 10; @@ -21,7 +24,13 @@ BOOST_AUTO_TEST_CASE( test_except ) { add(100); //] - - BOOST_CHECK( sum == 1000 ); + + BOOST_CHECK(sum == 1000); } +#else + +int main(void) { return 0; } + +#endif + diff --git a/test/add_except_seq.cpp b/test/add_except_seq.cpp new file mode 100644 index 0000000..4b9cafb --- /dev/null +++ b/test/add_except_seq.cpp @@ -0,0 +1,25 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestAddExceptSeq +#include + +BOOST_AUTO_TEST_CASE(test_except_seq) { + double sum = 0.0; + int factor = 10; + + void BOOST_LOCAL_FUNCTION( (const bind factor) (bind& sum) + (double num) ) throw() { + sum += factor * num; + } BOOST_LOCAL_FUNCTION_NAME(add) + + add(100); + + BOOST_CHECK(sum == 1000); +} + diff --git a/test/add_inline.cpp b/test/add_inline.cpp index 6045750..bd86f61 100644 --- a/test/add_inline.cpp +++ b/test/add_inline.cpp @@ -5,14 +5,16 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function -//[ add_function_inline_cpp +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestAddInline #include #include #include -BOOST_AUTO_TEST_CASE( test_add_inline ) { +BOOST_AUTO_TEST_CASE(test_add_inline) { //[add_inline int sum = 0, factor = 10; @@ -26,6 +28,12 @@ BOOST_AUTO_TEST_CASE( test_add_inline ) { for(size_t i = 0; i < v.size(); ++i) add(v[i]); // Cannot use for_each. //] - BOOST_CHECK( sum == 1000 ); + BOOST_CHECK(sum == 1000); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/add_inline_seq.cpp b/test/add_inline_seq.cpp new file mode 100644 index 0000000..00f9516 --- /dev/null +++ b/test/add_inline_seq.cpp @@ -0,0 +1,28 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestAddInlineSeq +#include +#include +#include + +BOOST_AUTO_TEST_CASE(test_add_inline_seq) { + int sum = 0, factor = 10; + + void BOOST_LOCAL_FUNCTION( (const bind factor) (bind& sum) (int num) ) { + sum += factor * num; + } BOOST_LOCAL_FUNCTION_NAME(inline add) + + std::vector v(100); + std::fill(v.begin(), v.end(), 1); + + for(size_t i = 0; i < v.size(); ++i) add(v[i]); + + BOOST_CHECK(sum == 1000); +} + diff --git a/test/add_lambda.cpp b/test/add_lambda.cpp index 1e446e4..6e80155 100644 --- a/test/add_lambda.cpp +++ b/test/add_lambda.cpp @@ -29,9 +29,9 @@ BOOST_AUTO_TEST_CASE( test_add_lambda ) } //] -#else // NO_LAMBDAS +#else -int main(void) { return 0; } // Trivial program. +int main(void) { return 0; } // Trivial test. -#endif // NO_LAMBDAS +#endif diff --git a/test/add_params.cpp b/test/add_params.cpp index c9bb138..24578c2 100644 --- a/test/add_params.cpp +++ b/test/add_params.cpp @@ -5,18 +5,26 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestAddParams #include -BOOST_AUTO_TEST_CASE( test_add_params ) { +BOOST_AUTO_TEST_CASE(test_add_params) { //[add_params int BOOST_LOCAL_FUNCTION(int x, int y) { // Local function. return x + y; } BOOST_LOCAL_FUNCTION_NAME(add) - BOOST_CHECK( add(1, 2) == 3 ); // Local function call. + BOOST_CHECK(add(1, 2) == 3); // Local function call. //] } -//] + +#else + +int main(void) { return 0; } // Trivial test. + +#endif diff --git a/test/add_params_seq.cpp b/test/add_params_seq.cpp new file mode 100644 index 0000000..0de2dee --- /dev/null +++ b/test/add_params_seq.cpp @@ -0,0 +1,19 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestAddParamsSeq +#include + +BOOST_AUTO_TEST_CASE(test_add_params_seq) { + int BOOST_LOCAL_FUNCTION( (int x) (int y) ) { + return x + y; + } BOOST_LOCAL_FUNCTION_NAME(add) + + BOOST_CHECK(add(1, 2) == 3); +} + diff --git a/test/add_seq.cpp b/test/add_seq.cpp deleted file mode 100644 index eaf93de..0000000 --- a/test/add_seq.cpp +++ /dev/null @@ -1,29 +0,0 @@ - -// Copyright (C) 2009-2012 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 -// (see accompanying file LICENSE_1_0.txt or a copy at -// http://www.boost.org/LICENSE_1_0.txt) -// Home at http://www.boost.org/libs/local_function - -#include -#define BOOST_TEST_MODULE TestAddSeq -#include -#include - -BOOST_AUTO_TEST_CASE( test_add_seq ) -//[add_seq -{ // Some local scope. - int sum = 0, factor = 10; // Variables in scope to bind. - - void BOOST_LOCAL_FUNCTION( (const bind factor) (bind& sum) (int num) ) { - sum += factor * num; // Parameters as sequence. - } BOOST_LOCAL_FUNCTION_NAME(add) - - add(1); // Call the local function. - int nums[] = {2, 3}; - std::for_each(nums, nums + 2, add); // Pass it to an algorithm. - - BOOST_CHECK( sum == 60 ); // Assert final summation value. -} -//] - diff --git a/test/add_template.cpp b/test/add_template.cpp index 233c26f..db21166 100644 --- a/test/add_template.cpp +++ b/test/add_template.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestAddTemplate #include @@ -28,7 +31,13 @@ T total(const T& x, const T& y, const T& z) { } //] -BOOST_AUTO_TEST_CASE( test_add_template ) { - BOOST_CHECK( total(1, 2, 3) == 60 ); +BOOST_AUTO_TEST_CASE(test_add_template) { + BOOST_CHECK(total(1, 2, 3) == 60); } +#else + +int main(void) { return 0; } + +#endif + diff --git a/test/add_template_seq.cpp b/test/add_template_seq.cpp new file mode 100644 index 0000000..205922c --- /dev/null +++ b/test/add_template_seq.cpp @@ -0,0 +1,31 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestAddTemplateSeq +#include +#include + +template +T total(const T& x, const T& y, const T& z) { + T sum = T(), factor = 10; + + T BOOST_LOCAL_FUNCTION_TPL( (const bind factor) (bind& sum) (T num) ) { + return sum += factor * num; + } BOOST_LOCAL_FUNCTION_NAME(add) + + add(x); + T nums[2]; nums[0] = y; nums[1] = z; + std::for_each(nums, nums + 2, add); + + return sum; +} + +BOOST_AUTO_TEST_CASE(test_add_template_seq) { + BOOST_CHECK(total(1, 2, 3) == 60); +} + diff --git a/test/add_this.cpp b/test/add_this.cpp index c7f4ba6..ed4669c 100644 --- a/test/add_this.cpp +++ b/test/add_this.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestAddThis #include @@ -13,7 +16,7 @@ //[add_this struct adder { - adder(): sum_(0) {} + adder() : sum_(0) {} int sum(const std::vector& nums, const int factor = 10) { @@ -24,15 +27,22 @@ struct adder { std::for_each(nums.begin(), nums.end(), add); return sum_; } + private: int sum_; }; //] -BOOST_AUTO_TEST_CASE( test_add_this ) { +BOOST_AUTO_TEST_CASE(test_add_this) { std::vector v(3); v[0] = 1; v[1] = 2; v[2] = 3; - BOOST_CHECK( adder().sum(v) == 60 ); + BOOST_CHECK(adder().sum(v) == 60); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/add_this_seq.cpp b/test/add_this_seq.cpp new file mode 100644 index 0000000..a141ac0 --- /dev/null +++ b/test/add_this_seq.cpp @@ -0,0 +1,38 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestAddThisSeq +#include +#include +#include + +struct adder { + adder() : sum_(0) {} + + int sum(const std::vector& nums, const int factor = 10) { + + void BOOST_LOCAL_FUNCTION( (const bind factor) (bind this_) + (int num) ) { + this_->sum_ += factor * num; + } BOOST_LOCAL_FUNCTION_NAME(add) + + std::for_each(nums.begin(), nums.end(), add); + return sum_; + } + +private: + int sum_; +}; + +BOOST_AUTO_TEST_CASE(test_add_this_seq) { + std::vector v(3); + v[0] = 1; v[1] = 2; v[2] = 3; + + BOOST_CHECK(adder().sum(v) == 60); +} + diff --git a/test/add_typed.cpp b/test/add_typed.cpp index 57dfabe..303c95f 100644 --- a/test/add_typed.cpp +++ b/test/add_typed.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestAddTyped #include @@ -13,7 +16,7 @@ //[add_typed struct adder { - adder(): sum_(0) {} + adder() : sum_(0) {} int sum(const std::vector& nums, const int& factor = 10) { // Explicitly specify bound variable and result types. @@ -25,15 +28,22 @@ struct adder { std::for_each(nums.begin(), nums.end(), add); return sum_; } + private: int sum_; }; //] -BOOST_AUTO_TEST_CASE( test_add_typed ) { +BOOST_AUTO_TEST_CASE(test_add_typed) { std::vector v(3); v[0] = 1; v[1] = 2; v[2] = 3; - BOOST_CHECK( adder().sum(v) == 60 ); + BOOST_CHECK(adder().sum(v) == 60); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/add_typed_seq.cpp b/test/add_typed_seq.cpp new file mode 100644 index 0000000..51ecea2 --- /dev/null +++ b/test/add_typed_seq.cpp @@ -0,0 +1,37 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestAddTypedSeq +#include +#include +#include + +struct adder { + adder() : sum_(0) {} + + int sum(const std::vector& nums, const int& factor = 10) { + BOOST_LOCAL_FUNCTION( (const bind(const int&) factor) + (bind(adder*) this_) (int num) (return int) ) { + return this_->sum_ += factor * num; + } BOOST_LOCAL_FUNCTION_NAME(add) + + std::for_each(nums.begin(), nums.end(), add); + return sum_; + } + +private: + int sum_; +}; + +BOOST_AUTO_TEST_CASE(test_add_typed_seq) { + std::vector v(3); + v[0] = 1; v[1] = 2; v[2] = 3; + + BOOST_CHECK(adder().sum(v) == 60); +} + diff --git a/test/add_with_default.cpp b/test/add_with_default.cpp index ceab084..9fc354f 100644 --- a/test/add_with_default.cpp +++ b/test/add_with_default.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestAddWithDefault #include @@ -13,14 +16,19 @@ #define WITH_DEFAULT , default //] -BOOST_AUTO_TEST_CASE( test_add_with_default ) { +BOOST_AUTO_TEST_CASE(test_add_with_default) { //[add_with_default int BOOST_LOCAL_FUNCTION(int x, int y WITH_DEFAULT 2) { // Default. return x + y; } BOOST_LOCAL_FUNCTION_NAME(add) - BOOST_CHECK( add(1) == 3 ); + BOOST_CHECK(add(1) == 3); //] } -//] + +#else + +int main(void) { return 0; } // Trivial test. + +#endif diff --git a/test/add_with_default_seq.cpp b/test/add_with_default_seq.cpp new file mode 100644 index 0000000..36fc62b --- /dev/null +++ b/test/add_with_default_seq.cpp @@ -0,0 +1,21 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestAddWithDefaultSeq +#include + +#define WITH_DEFAULT )(default + +BOOST_AUTO_TEST_CASE(test_add_with_default_seq) { + int BOOST_LOCAL_FUNCTION( (int x) (int y WITH_DEFAULT 2) ) { + return x + y; + } BOOST_LOCAL_FUNCTION_NAME(add) + + BOOST_CHECK(add(1) == 3); +} + diff --git a/test/addable.hpp b/test/addable.hpp index d8d51f6..d1ff866 100644 --- a/test/addable.hpp +++ b/test/addable.hpp @@ -15,9 +15,11 @@ struct Addable { // User-defined concept. BOOST_CONCEPT_USAGE(Addable) { return_type(x + y); // Check addition `T operator+(T x, T y)`. } + private: T x; T y; + void return_type(T const&); // Used to check addition returns type `T`. }; diff --git a/test/all_decl.cpp b/test/all_decl.cpp new file mode 100644 index 0000000..98e585c --- /dev/null +++ b/test/all_decl.cpp @@ -0,0 +1,174 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#ifndef BOOST_NO_VARIADIC_MACROS + +#include + +// Compile all local function declaration combinations. +struct s { + void f(double p = 1.23, double q = -1.23) { + { // Only params. + void BOOST_LOCAL_FUNCTION(int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(l) + l(1); + } + { // Only const binds. + int a, b; + + const int& BOOST_LOCAL_FUNCTION(const bind a, + const bind& b, const bind& p, const bind q) { + return b; + } BOOST_LOCAL_FUNCTION_NAME(l) + l(); + + const s& BOOST_LOCAL_FUNCTION(const bind this_) { + return *this_; + } BOOST_LOCAL_FUNCTION_NAME(t) + t(); + + const int BOOST_LOCAL_FUNCTION(const bind a, + const bind& b, const bind& p, const bind q, + const bind this_) { + return a; + } BOOST_LOCAL_FUNCTION_NAME(lt) + lt(); + } + { // Only plain binds. + int c, d; + + int& BOOST_LOCAL_FUNCTION(bind c, bind& d, + bind& p, bind& q) { + return d; + } BOOST_LOCAL_FUNCTION_NAME(l) + l(); + + s& BOOST_LOCAL_FUNCTION(bind this_) { + return *this_; + } BOOST_LOCAL_FUNCTION_NAME(t) + t(); + + int BOOST_LOCAL_FUNCTION(bind c, bind& d, + bind& p, bind& q, bind this_) { + return c; + } BOOST_LOCAL_FUNCTION_NAME(lt) + lt(); + } + + { // Both params and const binds. + int a, b; + + void BOOST_LOCAL_FUNCTION(const bind a, const bind& b, + const bind& p, const bind q, + int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(l) + l(1); + + void BOOST_LOCAL_FUNCTION(const bind this_, + int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(t) + t(1); + + void BOOST_LOCAL_FUNCTION(const bind a, const bind this_, + const bind& b, const bind& p, const bind q, + int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(lt) + lt(1); + } + { // Both params and plain binds. + int c, d; + + void BOOST_LOCAL_FUNCTION(bind c, bind& d, bind& p, bind q, + int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(l) + l(1); + + void BOOST_LOCAL_FUNCTION(bind this_, + int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(t) + t(1); + + void BOOST_LOCAL_FUNCTION(bind c, bind& d, + bind& p, bind this_, bind q, + int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(lt) + lt(1); + } + { // Both const and plain binds. + int a, b, c, d; + + void BOOST_LOCAL_FUNCTION(const bind a, const bind& b, + const bind p, bind c, bind& d, bind q) { + } BOOST_LOCAL_FUNCTION_NAME(l) + l(); + + void BOOST_LOCAL_FUNCTION(const bind this_, + bind c, bind& d, bind q) { + } BOOST_LOCAL_FUNCTION_NAME(ct) + ct(); + void BOOST_LOCAL_FUNCTION(const bind this_, + const bind a, const bind& b, const bind p, + bind c, bind& d, bind q) { + } BOOST_LOCAL_FUNCTION_NAME(lct) + lct(); + + void BOOST_LOCAL_FUNCTION(const bind a, const bind& b, + const bind p, bind this_) { + } BOOST_LOCAL_FUNCTION_NAME(pt) + pt(); + void BOOST_LOCAL_FUNCTION(const bind a, const bind& b, + const bind p, bind c, bind this_, bind& d, bind q) { + } BOOST_LOCAL_FUNCTION_NAME(lpt) + lpt(); + } + + { // All params, const binds, and plain binds. + int a, b, c, d; + + void BOOST_LOCAL_FUNCTION( + const bind a, const bind& b, const bind& p, + bind c, bind& d, bind& q, int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(l) + l(1); + + void BOOST_LOCAL_FUNCTION(const bind this_, + bind c, bind& d, bind& q, + int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(ct) + ct(1); + void BOOST_LOCAL_FUNCTION( + const bind a, const bind& b, const bind& p, + bind this_, int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(pt) + pt(1); + + void BOOST_LOCAL_FUNCTION(const bind a, const bind this_, + const bind& b, const bind& p, bind c, bind& d, + bind& q, int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(lct) + lct(1); + void BOOST_LOCAL_FUNCTION(const bind a, const bind& b, + const bind& p, bind c, bind& d, bind this_, bind& q, + int x, int y, default 0) { + } BOOST_LOCAL_FUNCTION_NAME(lpt) + lpt(1); + } + } +}; + +int main(void) { + s().f(); + return 0; +} + +#else + +int main(void) { return 0; } + +#endif + diff --git a/test/seq.cpp b/test/all_decl_seq.cpp similarity index 99% rename from test/seq.cpp rename to test/all_decl_seq.cpp index cca62a5..2001e34 100644 --- a/test/seq.cpp +++ b/test/all_decl_seq.cpp @@ -7,7 +7,7 @@ #include -//[seq +// Compile all local function declaration combinations. struct s { void f(double p = 1.23, double q = -1.23) { { // Only params. @@ -157,8 +157,7 @@ struct s { } } }; -//] - + int main(void) { s().f(); return 0; diff --git a/test/factorial.cpp b/test/factorial.cpp index 11d837d..2ecc61e 100644 --- a/test/factorial.cpp +++ b/test/factorial.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestFactorial #include @@ -32,14 +35,20 @@ struct calculator { }; //] -BOOST_AUTO_TEST_CASE( test_factorial ) { +BOOST_AUTO_TEST_CASE(test_factorial) { std::vector v(3); v[0] = 1; v[1] = 3; v[2] = 4; calculator calc; calc.factorials(v); - BOOST_CHECK( calc.results[0] == 1 ); - BOOST_CHECK( calc.results[1] == 6 ); - BOOST_CHECK( calc.results[2] == 24 ); + BOOST_CHECK(calc.results[0] == 1); + BOOST_CHECK(calc.results[1] == 6); + BOOST_CHECK(calc.results[2] == 24); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/factorial_seq.cpp b/test/factorial_seq.cpp new file mode 100644 index 0000000..3daaf94 --- /dev/null +++ b/test/factorial_seq.cpp @@ -0,0 +1,43 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestFactorialSeq +#include +#include +#include + +struct calculator { + std::vector results; + + void factorials(const std::vector& nums) { + int BOOST_LOCAL_FUNCTION( (bind this_) (int num) + (bool recursion)(default false) ) { + int result = 0; + + if(num <= 0) result = 1; + else result = num * factorial(num - 1, true); + + if(!recursion) this_->results.push_back(result); + return result; + } BOOST_LOCAL_FUNCTION_NAME(recursive factorial) + + std::for_each(nums.begin(), nums.end(), factorial); + } +}; + +BOOST_AUTO_TEST_CASE(test_factorial_seq) { + std::vector v(3); + v[0] = 1; v[1] = 3; v[2] = 4; + + calculator calc; + calc.factorials(v); + BOOST_CHECK(calc.results[0] == 1); + BOOST_CHECK(calc.results[1] == 6); + BOOST_CHECK(calc.results[2] == 24); +} + diff --git a/test/goto.cpp b/test/goto.cpp index 6356584..ce07c99 100644 --- a/test/goto.cpp +++ b/test/goto.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestGoto #include @@ -22,7 +25,13 @@ int error(int x, int y) { } //] -BOOST_AUTO_TEST_CASE( test_goto ) { +BOOST_AUTO_TEST_CASE(test_goto) { error(1, 2); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/goto_error.cpp b/test/goto_error.cpp index 16266ab..3282ef8 100644 --- a/test/goto_error.cpp +++ b/test/goto_error.cpp @@ -5,8 +5,11 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include -#define BOOST_TEST_MODULE TestGotoErr +#define BOOST_TEST_MODULE TestGotoError #include //[goto_error @@ -14,7 +17,6 @@ int error(int x, int y) { int BOOST_LOCAL_FUNCTION(int x) { if(x <= 0) goto failure; // Error: Cannot jump to enclosing scope. else goto success; // OK: Can jump within local function. - success: return 0; } BOOST_LOCAL_FUNCTION_NAME(validate) @@ -25,7 +27,13 @@ faliure: } //] -BOOST_AUTO_TEST_CASE( test_goto_err ) { +BOOST_AUTO_TEST_CASE(test_goto_error) { error(1, 2); } +#else + +#error "Trivial error." + +#endif + diff --git a/test/goto_error_seq.cpp b/test/goto_error_seq.cpp new file mode 100644 index 0000000..8ca22a2 --- /dev/null +++ b/test/goto_error_seq.cpp @@ -0,0 +1,28 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestGotoErrorSeq +#include + +int error(int x, int y) { + int BOOST_LOCAL_FUNCTION( (int x) ) { + if(x <= 0) goto failure; + else goto success; + success: + return 0; + } BOOST_LOCAL_FUNCTION_NAME(validate) + + return validate(x + y); +faliure: + return -1; +} + +BOOST_AUTO_TEST_CASE(test_goto_error_seq) { + error(1, 2); +} + diff --git a/test/goto_seq.cpp b/test/goto_seq.cpp new file mode 100644 index 0000000..82ee85f --- /dev/null +++ b/test/goto_seq.cpp @@ -0,0 +1,26 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestGotoSeq +#include + +int error(int x, int y) { + int BOOST_LOCAL_FUNCTION( (int x) ) { + if(x > 0) goto success; + return -1; + success: + return 0; + } BOOST_LOCAL_FUNCTION_NAME(validate) + + return validate(x + y); +} + +BOOST_AUTO_TEST_CASE(test_goto_seq) { + error(1, 2); +} + diff --git a/test/macro_commas.cpp b/test/macro_commas.cpp index 8ce6e95..5bd04eb 100644 --- a/test/macro_commas.cpp +++ b/test/macro_commas.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #include #include @@ -22,7 +25,7 @@ struct key_sizeof { typedef int sign_t; -BOOST_AUTO_TEST_CASE( test_macro_commas ) { +BOOST_AUTO_TEST_CASE(test_macro_commas) { //[macro_commas void BOOST_LOCAL_FUNCTION( BOOST_IDENTITY_TYPE((const std::map&)) m, @@ -40,3 +43,9 @@ BOOST_AUTO_TEST_CASE( test_macro_commas ) { f(m, sign); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/macro_commas_seq.cpp b/test/macro_commas_seq.cpp new file mode 100644 index 0000000..2ff4188 --- /dev/null +++ b/test/macro_commas_seq.cpp @@ -0,0 +1,40 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#include +#include +#define BOOST_TEST_MODULE TestMacroCommasSeq +#include +#include +#include + +std::string cat(const std::string& x, const std::string& y) { return x + y; } + +template +struct key_sizeof { + BOOST_STATIC_CONSTANT(int, value = sizeof(K)); +}; + +typedef int sign_t; + +BOOST_AUTO_TEST_CASE(test_macro_commas_seq) { + void BOOST_LOCAL_FUNCTION( + (BOOST_IDENTITY_TYPE((const std::map&)) m) + (BOOST_IDENTITY_TYPE((::sign_t)) sign) + (const size_t& factor) + (default (key_sizeof::value)) + (const std::string& separator)(default cat(":", " ")) + ) { + // Do something... + } BOOST_LOCAL_FUNCTION_NAME(f) + + std::map m; + ::sign_t sign = -1; + f(m, sign); +} + diff --git a/test/nesting.cpp b/test/nesting.cpp index 5b22e8d..0a6d696 100644 --- a/test/nesting.cpp +++ b/test/nesting.cpp @@ -5,11 +5,14 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestNesting #include -BOOST_AUTO_TEST_CASE( test_nesting ) { +BOOST_AUTO_TEST_CASE(test_nesting) { //[nesting int x = 0; @@ -24,6 +27,13 @@ BOOST_AUTO_TEST_CASE( test_nesting ) { f(); //] - BOOST_CHECK( x == 0 ); + + BOOST_CHECK(x == 0); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/nesting_seq.cpp b/test/nesting_seq.cpp new file mode 100644 index 0000000..0110539 --- /dev/null +++ b/test/nesting_seq.cpp @@ -0,0 +1,28 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestNestingSeq +#include + +BOOST_AUTO_TEST_CASE(test_nesting_seq) { + int x = 0; + + void BOOST_LOCAL_FUNCTION( (bind& x) ) { + void BOOST_LOCAL_FUNCTION( (bind& x) ) { + x++; + } BOOST_LOCAL_FUNCTION_NAME(g) + + x--; + g(); + } BOOST_LOCAL_FUNCTION_NAME(f) + + f(); + + BOOST_CHECK(x == 0); +} + diff --git a/test/operator.cpp b/test/operator.cpp index 4899070..a7871e7 100644 --- a/test/operator.cpp +++ b/test/operator.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestOperator #include @@ -15,14 +18,20 @@ struct point { int y; }; -BOOST_AUTO_TEST_CASE( test_operator ) { +BOOST_AUTO_TEST_CASE(test_operator) { bool BOOST_LOCAL_FUNCTION(const point& p, const point& q) { return p.x == q.x && p.y == q.y; } BOOST_LOCAL_FUNCTION_NAME(equal) // OK: not using `operator...`. point a; a.x = 1; a.y = 2; point b = a; - BOOST_CHECK( equal(a, b) ); + BOOST_CHECK(equal(a, b)); } //] +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/operator_error.cpp b/test/operator_error.cpp index b6050a7..e479045 100644 --- a/test/operator_error.cpp +++ b/test/operator_error.cpp @@ -5,8 +5,11 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include -#define BOOST_TEST_MODULE TestOperatorErr +#define BOOST_TEST_MODULE TestOperatorError #include //[operator_error @@ -15,14 +18,20 @@ struct point { int y; }; -BOOST_AUTO_TEST_CASE( test_operator_err ) { +BOOST_AUTO_TEST_CASE(test_operator_error) { bool BOOST_LOCAL_FUNCTION(const point& p, const point& q) { return p.x == q.x && p.y == q.y; } BOOST_LOCAL_FUNCTION_NAME(operator==) // Error: Cannot use `operator...`. point a; a.x = 1; a.y = 2; point b = a; - BOOST_CHECK( a == b ); + BOOST_CHECK(a == b); } //] +#else + +#error "Trivial error." + +#endif + diff --git a/test/operator_error_seq.cpp b/test/operator_error_seq.cpp new file mode 100644 index 0000000..41defbd --- /dev/null +++ b/test/operator_error_seq.cpp @@ -0,0 +1,26 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestOperatorErrorSeq +#include + +struct point { + int x; + int y; +}; + +BOOST_AUTO_TEST_CASE(test_operator_error_seq) { + bool BOOST_LOCAL_FUNCTION( (const point& p) (const point& q) ) { + return p.x == q.x && p.y == q.y; + } BOOST_LOCAL_FUNCTION_NAME(operator==) + + point a; a.x = 1; a.y = 2; + point b = a; + BOOST_CHECK(a == b); +} + diff --git a/test/operator_seq.cpp b/test/operator_seq.cpp new file mode 100644 index 0000000..b4a1642 --- /dev/null +++ b/test/operator_seq.cpp @@ -0,0 +1,26 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestOperatorSeq +#include + +struct point { + int x; + int y; +}; + +BOOST_AUTO_TEST_CASE(test_operator_seq) { + bool BOOST_LOCAL_FUNCTION( (const point& p) (const point& q) ) { + return p.x == q.x && p.y == q.y; + } BOOST_LOCAL_FUNCTION_NAME(equal) + + point a; a.x = 1; a.y = 2; + point b = a; + BOOST_CHECK(equal(a, b)); +} + diff --git a/test/overload.cpp b/test/overload.cpp index 43bdd4d..88bc273 100644 --- a/test/overload.cpp +++ b/test/overload.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #include // For overloading. #define BOOST_TEST_MODULE TestOverload @@ -15,7 +18,7 @@ //[overload int add_i(int x, int y) { return x + y; } -BOOST_AUTO_TEST_CASE( test_overload ) { +BOOST_AUTO_TEST_CASE(test_overload) { std::string s = "abc"; std::string BOOST_LOCAL_FUNCTION( const bind& s, const std::string& x) { @@ -34,10 +37,16 @@ BOOST_AUTO_TEST_CASE( test_overload ) { , int (int, int) > add(add_s, add_d, add_d, add_i); // Overloaded function object. - BOOST_CHECK( add("xyz") == "abcxyz" ); // Call `add_s`. - BOOST_CHECK( fabs(add(3.21) - 4.44) < 0.001 ); // Call `add_d` (no default). - BOOST_CHECK( fabs(add(3.21, 40.0) - 44.44) < 0.001); // Call `add_d`. - BOOST_CHECK( add(1, 2) == 3 ); // Call `add_i`. + BOOST_CHECK(add("xyz") == "abcxyz"); // Call `add_s`. + BOOST_CHECK(fabs(add(3.21) - 4.44) < 0.001); // Call `add_d` (no default). + BOOST_CHECK(fabs(add(3.21, 40.0) - 44.44) < 0.001); // Call `add_d`. + BOOST_CHECK(add(1, 2) == 3); // Call `add_i`. } //] +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/overload_seq.cpp b/test/overload_seq.cpp new file mode 100644 index 0000000..2fb4cad --- /dev/null +++ b/test/overload_seq.cpp @@ -0,0 +1,42 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#include +#define BOOST_TEST_MODULE TestOverloadSeq +#include +#include +#include + +int add_i(int x, int y) { return x + y; } + +BOOST_AUTO_TEST_CASE(test_overload_seq) { + std::string s = "abc"; + std::string BOOST_LOCAL_FUNCTION( + (const bind& s) (const std::string& x) ) { + return s + x; + } BOOST_LOCAL_FUNCTION_NAME(add_s) + + double d = 1.23; + double BOOST_LOCAL_FUNCTION( (const bind d) (double x) + (double y)(default 0) ) { + return d + x + y; + } BOOST_LOCAL_FUNCTION_NAME(add_d) + + boost::overloaded_function< + std::string (const std::string&) + , double (double) + , double (double, double) + , int (int, int) + > add(add_s, add_d, add_d, add_i); + + BOOST_CHECK(add("xyz") == "abcxyz"); + BOOST_CHECK(fabs(add(3.21) - 4.44) < 0.001); + BOOST_CHECK(fabs(add(3.21, 40.0) - 44.44) < 0.001); + BOOST_CHECK(add(1, 2) == 3); +} + diff --git a/test/return_assign.cpp b/test/return_assign.cpp index 9d01067..dc02995 100644 --- a/test/return_assign.cpp +++ b/test/return_assign.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #include #define BOOST_TEST_MODULE TestReturnAssign @@ -12,8 +15,8 @@ #include //[return_assign -void call1(boost::function f) { BOOST_CHECK( f(1) == 5 ); } -void call0(boost::function f) { BOOST_CHECK( f() == 5 ); } +void call1(boost::function f) { BOOST_CHECK(f(1) == 5); } +void call0(boost::function f) { BOOST_CHECK(f() == 5); } boost::function linear(const int& slope) { int BOOST_LOCAL_FUNCTION(const bind& slope, @@ -22,7 +25,7 @@ boost::function linear(const int& slope) { } BOOST_LOCAL_FUNCTION_NAME(lin) boost::function f = lin; // Assign to local variable. - BOOST_CHECK( f(1, 2) == 5 ); + BOOST_CHECK(f(1, 2) == 5); call1(lin); // Pass to other functions. call0(lin); @@ -32,11 +35,17 @@ boost::function linear(const int& slope) { void call(void) { boost::function f = linear(2); - BOOST_CHECK( f(1, 2) == 5 ); + BOOST_CHECK(f(1, 2) == 5); } //] -BOOST_AUTO_TEST_CASE( test_return_assign ) { +BOOST_AUTO_TEST_CASE(test_return_assign) { call(); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/return_assign_seq.cpp b/test/return_assign_seq.cpp new file mode 100644 index 0000000..b456aa3 --- /dev/null +++ b/test/return_assign_seq.cpp @@ -0,0 +1,40 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#include +#define BOOST_TEST_MODULE TestReturnAssignSeq +#include +#include + +void call1(boost::function f) { BOOST_CHECK(f(1) == 5); } +void call0(boost::function f) { BOOST_CHECK(f() == 5); } + +boost::function linear(const int& slope) { + int BOOST_LOCAL_FUNCTION( (const bind& slope) + (int x)(default 1) (int y)(default 2) ) { + return x + slope * y; + } BOOST_LOCAL_FUNCTION_NAME(lin) + + boost::function f = lin; + BOOST_CHECK(f(1, 2) == 5); + + call1(lin); + call0(lin); + + return lin; +} + +void call(void) { + boost::function f = linear(2); + BOOST_CHECK(f(1, 2) == 5); +} + +BOOST_AUTO_TEST_CASE(test_return_assign_seq) { + call(); +} + diff --git a/test/return_derivative.cpp b/test/return_derivative.cpp index 6f7eb26..55c8c73 100644 --- a/test/return_derivative.cpp +++ b/test/return_derivative.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #include #define BOOST_TEST_MODULE TestReturnDerivative @@ -14,16 +17,24 @@ boost::function derivative(boost::function& f, int dx) { int BOOST_LOCAL_FUNCTION(bind& f, const bind dx, int x) { return (f(x + dx) - f(x)) / dx; } BOOST_LOCAL_FUNCTION_NAME(deriv) + return deriv; } -BOOST_AUTO_TEST_CASE( test_return_derivative ) { +BOOST_AUTO_TEST_CASE(test_return_derivative) { int BOOST_LOCAL_FUNCTION(int x) { return x + 4; } BOOST_LOCAL_FUNCTION_NAME(add2) + boost::function a2 = add2; // Reference valid where closure used. boost::function d2 = derivative(a2, 2); - BOOST_CHECK( d2(6) == 1 ); + BOOST_CHECK(d2(6) == 1); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/return_derivative_seq.cpp b/test/return_derivative_seq.cpp new file mode 100644 index 0000000..ecfad7b --- /dev/null +++ b/test/return_derivative_seq.cpp @@ -0,0 +1,31 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#include +#define BOOST_TEST_MODULE TestReturnDerivativeSeq +#include + +boost::function derivative(boost::function& f, int dx) { + int BOOST_LOCAL_FUNCTION( (bind& f) (const bind dx) (int x) ) { + return (f(x + dx) - f(x)) / dx; + } BOOST_LOCAL_FUNCTION_NAME(deriv) + + return deriv; +} + +BOOST_AUTO_TEST_CASE(test_return_derivative_seq) { + int BOOST_LOCAL_FUNCTION( (int x) ) { + return x + 4; + } BOOST_LOCAL_FUNCTION_NAME(add2) + + boost::function a2 = add2; + + boost::function d2 = derivative(a2, 2); + BOOST_CHECK(d2(6) == 1); +} + diff --git a/test/return_inc.cpp b/test/return_inc.cpp index 6216c67..c73393e 100644 --- a/test/return_inc.cpp +++ b/test/return_inc.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #include #define BOOST_TEST_MODULE TestReturnInc @@ -17,15 +20,21 @@ boost::function inc(int& value) { return i; } -BOOST_AUTO_TEST_CASE( test_return_inc ) { +BOOST_AUTO_TEST_CASE(test_return_inc) { int value1 = 0; // Reference valid in scope where closure is used. boost::function inc1 = inc(value1); int value2 = 0; boost::function inc2 = inc(value2); - BOOST_CHECK( inc1() == 1 ); - BOOST_CHECK( inc1() == 2 ); - BOOST_CHECK( inc2() == 1 ); - BOOST_CHECK( inc1() == 3 ); + BOOST_CHECK(inc1() == 1); + BOOST_CHECK(inc1() == 2); + BOOST_CHECK(inc2() == 1); + BOOST_CHECK(inc1() == 3); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/return_inc_seq.cpp b/test/return_inc_seq.cpp new file mode 100644 index 0000000..65ee386 --- /dev/null +++ b/test/return_inc_seq.cpp @@ -0,0 +1,31 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#include +#define BOOST_TEST_MODULE TestReturnIncSeq +#include + +boost::function inc(int& value) { + int BOOST_LOCAL_FUNCTION( (bind& value) ) { + return ++value; + } BOOST_LOCAL_FUNCTION_NAME(i) + return i; +} + +BOOST_AUTO_TEST_CASE(test_return_inc_seq) { + int value1 = 0; + boost::function inc1 = inc(value1); + int value2 = 0; + boost::function inc2 = inc(value2); + + BOOST_CHECK(inc1() == 1); + BOOST_CHECK(inc1() == 2); + BOOST_CHECK(inc2() == 1); + BOOST_CHECK(inc1() == 3); +} + diff --git a/test/return_setget.cpp b/test/return_setget.cpp index 47ac199..ad63c01 100644 --- a/test/return_setget.cpp +++ b/test/return_setget.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #include #define BOOST_TEST_MODULE TestReturnSetGet @@ -16,12 +19,12 @@ boost::function get; void action(void) { // State `message` hidden behind access functions from here. - BOOST_CHECK( get() == "abc" ); + BOOST_CHECK(get() == "abc"); set("xyz"); - BOOST_CHECK( get() == "xyz" ); + BOOST_CHECK(get() == "xyz"); } -BOOST_AUTO_TEST_CASE( test_return_setget ) { +BOOST_AUTO_TEST_CASE(test_return_setget) { std::string message = "abc"; // Reference valid where closure used. void BOOST_LOCAL_FUNCTION(bind& message, const std::string& text) { @@ -37,3 +40,9 @@ BOOST_AUTO_TEST_CASE( test_return_setget ) { action(); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/return_setget_seq.cpp b/test/return_setget_seq.cpp new file mode 100644 index 0000000..c4cd27d --- /dev/null +++ b/test/return_setget_seq.cpp @@ -0,0 +1,38 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#include +#define BOOST_TEST_MODULE TestReturnSetgetSeq +#include +#include + +boost::function set; +boost::function get; + +void action(void) { + BOOST_CHECK(get() == "abc"); + set("xyz"); + BOOST_CHECK(get() == "xyz"); +} + +BOOST_AUTO_TEST_CASE(test_return_setget_seq) { + std::string message = "abc"; + + void BOOST_LOCAL_FUNCTION( (bind& message) (const std::string& text) ) { + message = text; + } BOOST_LOCAL_FUNCTION_NAME(s) + set = s; + + const std::string& BOOST_LOCAL_FUNCTION( (const bind& message) ) { + return message; + } BOOST_LOCAL_FUNCTION_NAME(g) + get = g; + + action(); +} + diff --git a/test/return_this.cpp b/test/return_this.cpp index 99fb220..4666272 100644 --- a/test/return_this.cpp +++ b/test/return_this.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #include #define BOOST_TEST_MODULE TestReturnThis @@ -24,15 +27,21 @@ private: int value_; }; -BOOST_AUTO_TEST_CASE( test_return_this ) { +BOOST_AUTO_TEST_CASE(test_return_this) { number n1 = 0; // Object valid in scope where closure is used. boost::function inc1 = n1.inc(); number n2 = 0; boost::function inc2 = n2.inc(); - BOOST_CHECK( inc1() == 1 ); - BOOST_CHECK( inc1() == 2 ); - BOOST_CHECK( inc2() == 1 ); - BOOST_CHECK( inc1() == 3 ); + BOOST_CHECK(inc1() == 1); + BOOST_CHECK(inc1() == 2); + BOOST_CHECK(inc2() == 1); + BOOST_CHECK(inc1() == 3); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/return_this_seq.cpp b/test/return_this_seq.cpp new file mode 100644 index 0000000..ddc32f6 --- /dev/null +++ b/test/return_this_seq.cpp @@ -0,0 +1,38 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#include +#define BOOST_TEST_MODULE TestReturnThisSeq +#include + +struct number { + number(int value) : value_(value) {} + + boost::function inc(void) { + int BOOST_LOCAL_FUNCTION( (bind this_) ) { + return ++this_->value_; + } BOOST_LOCAL_FUNCTION_NAME(i) + return i; + } + +private: + int value_; +}; + +BOOST_AUTO_TEST_CASE(test_return_this_seq) { + number n1 = 0; // Object valid in scope where closure is used. + boost::function inc1 = n1.inc(); + number n2 = 0; + boost::function inc2 = n2.inc(); + + BOOST_CHECK(inc1() == 1); + BOOST_CHECK(inc1() == 2); + BOOST_CHECK(inc2() == 1); + BOOST_CHECK(inc1() == 3); +} + diff --git a/test/ten_void.cpp b/test/ten_void.cpp index 8235ee8..f71d10a 100644 --- a/test/ten_void.cpp +++ b/test/ten_void.cpp @@ -10,13 +10,13 @@ #include #include -BOOST_AUTO_TEST_CASE( test_ten_void ) { +BOOST_AUTO_TEST_CASE(test_ten_void) { //[ten_void int BOOST_LOCAL_FUNCTION(void) { // No parameter. return 10; } BOOST_LOCAL_FUNCTION_NAME(ten) - BOOST_CHECK( ten() == 10 ); + BOOST_CHECK(ten() == 10); //] } diff --git a/test/transform.cpp b/test/transform.cpp index bf473b5..c2e685b 100644 --- a/test/transform.cpp +++ b/test/transform.cpp @@ -5,20 +5,23 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include #define BOOST_TEST_MODULE TestTranform #include #include #include -BOOST_AUTO_TEST_CASE( test_transform ) { +BOOST_AUTO_TEST_CASE(test_transform) { //[transform int offset = 5; std::vector v; std::vector w; for(int i = 1; i <= 2; ++i) v.push_back(i * 10); - BOOST_CHECK( v[0] == 10 ); BOOST_CHECK( v[1] == 20 ); + BOOST_CHECK(v[0] == 10); BOOST_CHECK(v[1] == 20); w.resize(v.size()); int BOOST_LOCAL_FUNCTION(const bind& offset, int i) { @@ -26,7 +29,7 @@ BOOST_AUTO_TEST_CASE( test_transform ) { } BOOST_LOCAL_FUNCTION_NAME(inc) std::transform(v.begin(), v.end(), w.begin(), inc); - BOOST_CHECK( w[0] == 16 ); BOOST_CHECK( w[1] == 26 ); + BOOST_CHECK(w[0] == 16); BOOST_CHECK(w[1] == 26); int BOOST_LOCAL_FUNCTION(bind& inc, int i, int j) { return inc(i + j); // Call the other bound local function. @@ -34,7 +37,13 @@ BOOST_AUTO_TEST_CASE( test_transform ) { offset = 0; std::transform(v.begin(), v.end(), w.begin(), v.begin(), inc_sum); - BOOST_CHECK( v[0] == 27 ); BOOST_CHECK( v[1] == 47 ); + BOOST_CHECK(v[0] == 27); BOOST_CHECK(v[1] == 47); //] } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/transform_seq.cpp b/test/transform_seq.cpp new file mode 100644 index 0000000..d885f68 --- /dev/null +++ b/test/transform_seq.cpp @@ -0,0 +1,38 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include +#define BOOST_TEST_MODULE TestTranformSeq +#include +#include +#include + +BOOST_AUTO_TEST_CASE(test_transform_seq) { + int offset = 5; + std::vector v; + std::vector w; + + for(int i = 1; i <= 2; ++i) v.push_back(i * 10); + BOOST_CHECK(v[0] == 10); BOOST_CHECK(v[1] == 20); + w.resize(v.size()); + + int BOOST_LOCAL_FUNCTION( (const bind& offset) (int i) ) { + return ++i + offset; + } BOOST_LOCAL_FUNCTION_NAME(inc) + + std::transform(v.begin(), v.end(), w.begin(), inc); + BOOST_CHECK(w[0] == 16); BOOST_CHECK(w[1] == 26); + + int BOOST_LOCAL_FUNCTION( (bind& inc) (int i) (int j) ) { + return inc(i + j); + } BOOST_LOCAL_FUNCTION_NAME(inc_sum) + + offset = 0; + std::transform(v.begin(), v.end(), w.begin(), v.begin(), inc_sum); + BOOST_CHECK(v[0] == 27); BOOST_CHECK(v[1] == 47); +} + diff --git a/test/typeof.cpp b/test/typeof.cpp index c92b4d6..8cc5a1c 100644 --- a/test/typeof.cpp +++ b/test/typeof.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include "addable.hpp" #include #include @@ -13,15 +16,15 @@ #include #include -BOOST_AUTO_TEST_CASE( test_typeof ) { +BOOST_AUTO_TEST_CASE(test_typeof) { //[typeof int sum = 0, factor = 10; void BOOST_LOCAL_FUNCTION(const bind factor, bind& sum, int num) { - // Typeof for concept checking. + // Type-of for concept checking. BOOST_CONCEPT_ASSERT((Addable::type>)); - // Typeof for declarations. + // Type-of for declarations. boost::remove_reference::type mult = factor * num; sum += mult; @@ -29,6 +32,12 @@ BOOST_AUTO_TEST_CASE( test_typeof ) { add(6); //] - BOOST_CHECK( sum == 60 ); + BOOST_CHECK(sum == 60); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/typeof_seq.cpp b/test/typeof_seq.cpp new file mode 100644 index 0000000..8fc2413 --- /dev/null +++ b/test/typeof_seq.cpp @@ -0,0 +1,30 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include "addable.hpp" +#include +#include +#include +#define BOOST_TEST_MODULE TestTypeofSeq +#include +#include + +BOOST_AUTO_TEST_CASE(test_typeof_seq) { + int sum = 0, factor = 10; + + void BOOST_LOCAL_FUNCTION( (const bind factor) (bind& sum) (int num) ) { + BOOST_CONCEPT_ASSERT((Addable::type>)); + boost::remove_reference::type mult = factor * num; + sum += mult; + } BOOST_LOCAL_FUNCTION_NAME(add) + + add(6); + BOOST_CHECK(sum == 60); +} + diff --git a/test/typeof_template.cpp b/test/typeof_template.cpp index 70cea1e..1370d61 100644 --- a/test/typeof_template.cpp +++ b/test/typeof_template.cpp @@ -5,6 +5,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function +#include +#ifndef BOOST_NO_VARIADIC_MACROS + #include "addable.hpp" #include #include @@ -30,7 +33,13 @@ T calculate(const T& factor) { } //] -BOOST_AUTO_TEST_CASE( test_typeof_template ) { - BOOST_CHECK( calculate(10) == 60 ); +BOOST_AUTO_TEST_CASE(test_typeof_template) { + BOOST_CHECK(calculate(10) == 60); } +#else + +int main(void) { return 0; } // Trivial test. + +#endif + diff --git a/test/typeof_template_seq.cpp b/test/typeof_template_seq.cpp new file mode 100644 index 0000000..6541256 --- /dev/null +++ b/test/typeof_template_seq.cpp @@ -0,0 +1,33 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include "addable.hpp" +#include +#include +#include +#define BOOST_TEST_MODULE TestTypeofTemplateSeq +#include +#include + +template +T calculate(const T& factor) { + T sum = 0; + + void BOOST_LOCAL_FUNCTION_TPL( (const bind factor) (bind& sum) (T num) ) { + BOOST_CONCEPT_ASSERT((Addable::type>)); + sum += factor * num; + } BOOST_LOCAL_FUNCTION_NAME(add) + + add(6); + return sum; +} + +BOOST_AUTO_TEST_CASE(test_typeof_template_seq) { + BOOST_CHECK(calculate(10) == 60); +} +