From e379125fea161f4b3c323da9bc7d63c438825699 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Fri, 17 Feb 2012 21:02:00 +0000 Subject: [PATCH 01/51] Added Boost.Utility/IdentityType and Boost.Functional/OverloadedFunction to status/Jamfile.v2 list of regression tests. Updated Boost.ScopeExit documentation. [SVN r77059] --- ..._OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html | 2 +- ...ERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html | 2 +- .../html/boost/make_overloaded_function.html | 2 +- .../doc/html/boost/overloaded_function.html | 22 +++++++++---------- overloaded_function/doc/html/index.html | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html index 209a321..7fb743f 100644 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html @@ -33,7 +33,7 @@ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX
-

Description

+

Description

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When specified by the user, this macro must be a non-negative integer number.

See: Getting Started, boost::overloaded_function.

diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html index 391cc27..c603c6b 100644 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html @@ -33,7 +33,7 @@ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX
-

Description

+

Description

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When defined by the user, this macro must be an integer number greater or equal than 2 (because at least two distinct functions need to be specified in order to define an overload).

See: Getting Started, boost::overloaded_function.

diff --git a/overloaded_function/doc/html/boost/make_overloaded_function.html b/overloaded_function/doc/html/boost/make_overloaded_function.html index eda4191..6ce8980 100644 --- a/overloaded_function/doc/html/boost/make_overloaded_function.html +++ b/overloaded_function/doc/html/boost/make_overloaded_function.html @@ -36,7 +36,7 @@ overloaded_function< __function_type__< F1 >, __function_type__< F2 >,...> make_overloaded_function(F1 f1, F2 f2, ...);
-

Description

+

Description

This function template creates and returns an overloaded_function function object that overloads all the specified functions f1, f2, etc.

The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with overloaded_function. This is especially useful when the explicit type of the returned overloaded_function does not need to be known (e.g., when used with Boost.Typeof's BOOST_AUTO (or C++11 auto) or when the overloaded function object is handled using a function template parameter, see the Tutorial section).

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro.

diff --git a/overloaded_function/doc/html/boost/overloaded_function.html b/overloaded_function/doc/html/boost/overloaded_function.html index 6257929..a0e95b4 100644 --- a/overloaded_function/doc/html/boost/overloaded_function.html +++ b/overloaded_function/doc/html/boost/overloaded_function.html @@ -35,19 +35,19 @@ class overloaded_function { public: // construct/copy/destruct - overloaded_function(const boost::function< F1 > &, + overloaded_function(const boost::function< F1 > &, const boost::function< F2 > &, ...); - // public member functions + // public member functions boost::function_traits< F1 >::result_type - operator()(typename boost::function_traits< F1 >::arg1_type, + operator()(typename boost::function_traits< F1 >::arg1_type, typename boost::function_traits< F1 >::arg2_type, ...) const; boost::function_traits< F2 >::result_type - operator()(typename boost::function_traits< F2 >::arg1_type, + operator()(typename boost::function_traits< F2 >::arg1_type, typename boost::function_traits< F2 >::arg2_type, ...) const; };
-

Description

+

Description

This function object aggregates together calls to functions of all the specified function types F1, F2, etc. The specified function types must have distinct parameters from one another and they must be in the following format (which is the Boost.Function preferred syntax):

    result_type (argument1_type, argumgnet2_type, ...)
 
@@ -55,27 +55,27 @@

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro. The maximum number of function parameters for each of the specified function types is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX configuration macro.

See: Tutorial section, make_overloaded_function, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, Boost.Function.

-

+

overloaded_function public construct/copy/destruct

  1. -
    overloaded_function(const boost::function< F1 > &, 
    +
    overloaded_function(const boost::function< F1 > &, 
                         const boost::function< F2 > &, ...);
    Construct the overloaded function object.

    Any function pointer, function reference, and monomorphic function object that can be converted to a boost::function function object can be specified as parameter.

-

-overloaded_function public member functions

+

+overloaded_function public member functions

  1. boost::function_traits< F1 >::result_type 
    -operator()(typename boost::function_traits< F1 >::arg1_type, 
    +operator()(typename boost::function_traits< F1 >::arg1_type, 
                typename boost::function_traits< F1 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 1st template parameter.

    This will in turn invoke the call operator of the 1st function passed to the constructor.

  2. boost::function_traits< F2 >::result_type 
    -operator()(typename boost::function_traits< F2 >::arg1_type, 
    +operator()(typename boost::function_traits< F2 >::arg1_type, 
                typename boost::function_traits< F2 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 2nd template parameter.

    This will in turn invoke the call operator of the 2nd function passed to the constructor.

    Note: Similar call operators are present for all specified function types F1, F2, etc (even if not exhaustively listed by this documentation).

  3. diff --git a/overloaded_function/doc/html/index.html b/overloaded_function/doc/html/index.html index c0946fd..a2e0f0d 100644 --- a/overloaded_function/doc/html/index.html +++ b/overloaded_function/doc/html/index.html @@ -133,7 +133,7 @@
- +

Last revised: February 14, 2012 at 16:16:51 GMT

Last revised: February 17, 2012 at 20:42:39 GMT


From c4824e0bd68dd4c22acd3ff4e7459fe8ccf7ef7c Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Sat, 18 Feb 2012 15:20:39 +0000 Subject: [PATCH 02/51] Remove a set of extra parenthesis in getting a member function pointer that were not needed and did not compile on clang. [SVN r77065] --- .../functional/overloaded_function/detail/function_type.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/functional/overloaded_function/detail/function_type.hpp b/include/boost/functional/overloaded_function/detail/function_type.hpp index 31f83a7..4494206 100644 --- a/include/boost/functional/overloaded_function/detail/function_type.hpp +++ b/include/boost/functional/overloaded_function/detail/function_type.hpp @@ -29,7 +29,8 @@ namespace boost { namespace overloaded_function_detail { // It does not assume F typedef result_type, arg1_type, ... but needs typeof. template class functor_type { - typedef BOOST_TYPEOF_TPL(&(F::operator())) call_ptr; + // NOTE: clang does not accept extra parenthesis `&(...)`. + typedef BOOST_TYPEOF_TPL(&F::operator()) call_ptr; public: typedef typename boost::function_types::function_type< From 9b08b5632d04c3d562c7710837ec1724e1df2bd2 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Sat, 18 Feb 2012 16:11:21 +0000 Subject: [PATCH 03/51] Added a couple of code comments. [SVN r77068] --- include/boost/functional/overloaded_function/detail/base.hpp | 1 + .../functional/overloaded_function/detail/function_type.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/include/boost/functional/overloaded_function/detail/base.hpp b/include/boost/functional/overloaded_function/detail/base.hpp index 8c1d4bf..8fd9a0a 100644 --- a/include/boost/functional/overloaded_function/detail/base.hpp +++ b/include/boost/functional/overloaded_function/detail/base.hpp @@ -33,6 +33,7 @@ R (BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity, \ BOOST_FUNCTIONAL_DETAIL_arg_type, ~)) +// Do not use namespace ::detail because overloaded_function is already a class. namespace boost { namespace overloaded_function_detail { template diff --git a/include/boost/functional/overloaded_function/detail/function_type.hpp b/include/boost/functional/overloaded_function/detail/function_type.hpp index 4494206..4169ee9 100644 --- a/include/boost/functional/overloaded_function/detail/function_type.hpp +++ b/include/boost/functional/overloaded_function/detail/function_type.hpp @@ -22,6 +22,7 @@ #include #include +// Do not use namespace ::detail because overloaded_function is already a class. namespace boost { namespace overloaded_function_detail { // Requires: F is a monomorphic functor (i.e., has non-template `operator()`). From 6932e9b1dc45df3bcab5a91e3ed092f442b5f75a Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Mon, 20 Feb 2012 20:11:42 +0000 Subject: [PATCH 04/51] Fixed test indentation and updated docs. [SVN r77079] --- ..._OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html | 2 +- ...ERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html | 2 +- .../html/boost/make_overloaded_function.html | 2 +- .../doc/html/boost/overloaded_function.html | 22 ++++++++-------- .../Tutorial.html | 18 ++++++------- overloaded_function/doc/html/index.html | 14 +++++----- overloaded_function/test/identity.cpp | 26 +++++++++---------- 7 files changed, 43 insertions(+), 43 deletions(-) diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html index 7fb743f..e51036e 100644 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html @@ -33,7 +33,7 @@ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX
-

Description

+

Description

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When specified by the user, this macro must be a non-negative integer number.

See: Getting Started, boost::overloaded_function.

diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html index c603c6b..a8a75b6 100644 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html @@ -33,7 +33,7 @@ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX
-

Description

+

Description

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When defined by the user, this macro must be an integer number greater or equal than 2 (because at least two distinct functions need to be specified in order to define an overload).

See: Getting Started, boost::overloaded_function.

diff --git a/overloaded_function/doc/html/boost/make_overloaded_function.html b/overloaded_function/doc/html/boost/make_overloaded_function.html index 6ce8980..65d1fce 100644 --- a/overloaded_function/doc/html/boost/make_overloaded_function.html +++ b/overloaded_function/doc/html/boost/make_overloaded_function.html @@ -36,7 +36,7 @@ overloaded_function< __function_type__< F1 >, __function_type__< F2 >,...> make_overloaded_function(F1 f1, F2 f2, ...);
-

Description

+

Description

This function template creates and returns an overloaded_function function object that overloads all the specified functions f1, f2, etc.

The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with overloaded_function. This is especially useful when the explicit type of the returned overloaded_function does not need to be known (e.g., when used with Boost.Typeof's BOOST_AUTO (or C++11 auto) or when the overloaded function object is handled using a function template parameter, see the Tutorial section).

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro.

diff --git a/overloaded_function/doc/html/boost/overloaded_function.html b/overloaded_function/doc/html/boost/overloaded_function.html index a0e95b4..4f70698 100644 --- a/overloaded_function/doc/html/boost/overloaded_function.html +++ b/overloaded_function/doc/html/boost/overloaded_function.html @@ -35,19 +35,19 @@ class overloaded_function { public: // construct/copy/destruct - overloaded_function(const boost::function< F1 > &, + overloaded_function(const boost::function< F1 > &, const boost::function< F2 > &, ...); - // public member functions + // public member functions boost::function_traits< F1 >::result_type - operator()(typename boost::function_traits< F1 >::arg1_type, + operator()(typename boost::function_traits< F1 >::arg1_type, typename boost::function_traits< F1 >::arg2_type, ...) const; boost::function_traits< F2 >::result_type - operator()(typename boost::function_traits< F2 >::arg1_type, + operator()(typename boost::function_traits< F2 >::arg1_type, typename boost::function_traits< F2 >::arg2_type, ...) const; };
-

Description

+

Description

This function object aggregates together calls to functions of all the specified function types F1, F2, etc. The specified function types must have distinct parameters from one another and they must be in the following format (which is the Boost.Function preferred syntax):

    result_type (argument1_type, argumgnet2_type, ...)
 
@@ -55,27 +55,27 @@

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro. The maximum number of function parameters for each of the specified function types is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX configuration macro.

See: Tutorial section, make_overloaded_function, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, Boost.Function.

-

+

overloaded_function public construct/copy/destruct

  1. -
    overloaded_function(const boost::function< F1 > &, 
    +
    overloaded_function(const boost::function< F1 > &, 
                         const boost::function< F2 > &, ...);
    Construct the overloaded function object.

    Any function pointer, function reference, and monomorphic function object that can be converted to a boost::function function object can be specified as parameter.

-

-overloaded_function public member functions

+

+overloaded_function public member functions

  1. boost::function_traits< F1 >::result_type 
    -operator()(typename boost::function_traits< F1 >::arg1_type, 
    +operator()(typename boost::function_traits< F1 >::arg1_type, 
                typename boost::function_traits< F1 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 1st template parameter.

    This will in turn invoke the call operator of the 1st function passed to the constructor.

  2. boost::function_traits< F2 >::result_type 
    -operator()(typename boost::function_traits< F2 >::arg1_type, 
    +operator()(typename boost::function_traits< F2 >::arg1_type, 
                typename boost::function_traits< F2 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 2nd template parameter.

    This will in turn invoke the call operator of the 2nd function passed to the constructor.

    Note: Similar call operators are present for all specified function types F1, F2, etc (even if not exhaustively listed by this documentation).

  3. diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html index ffd899d..cbb370d 100644 --- a/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html +++ b/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html @@ -69,9 +69,9 @@ > identity(identity_s, identity_i, identity_d); // All calls via single `identity` function. -BOOST_CHECK( identity("abc") == "abc" ); -BOOST_CHECK( identity(123) == 123 ); -BOOST_CHECK( identity(1.23) == 1.23 ); +BOOST_CHECK(identity("abc") == "abc"); +BOOST_CHECK(identity(123) == 123); +BOOST_CHECK(identity(1.23) == 1.23);

    @@ -121,9 +121,9 @@
    BOOST_AUTO(identity, boost::make_overloaded_function(
             identity_s, identity_i, identity_d));
     
    -BOOST_CHECK( identity("abc") == "abc" );
    -BOOST_CHECK( identity(123) == 123 );
    -BOOST_CHECK( identity(1.23) == 1.23 );
    +BOOST_CHECK(identity("abc") == "abc");
    +BOOST_CHECK(identity(123) == 123);
    +BOOST_CHECK(identity(1.23) == 1.23);
     

    @@ -149,9 +149,9 @@

    template<typename F>
     void check(F identity) {
    -    BOOST_CHECK( identity("abc") == "abc" );
    -    BOOST_CHECK( identity(123) == 123 );
    -    BOOST_CHECK( identity(1.23) == 1.23 );
    +    BOOST_CHECK(identity("abc") == "abc");
    +    BOOST_CHECK(identity(123) == 123);
    +    BOOST_CHECK(identity(1.23) == 1.23);
     }
     

    diff --git a/overloaded_function/doc/html/index.html b/overloaded_function/doc/html/index.html index a2e0f0d..f900f8e 100644 --- a/overloaded_function/doc/html/index.html +++ b/overloaded_function/doc/html/index.html @@ -87,9 +87,9 @@

    -
    BOOST_CHECK( identity_s("abc") == "abc" );
    -BOOST_CHECK( identity_i(123) == 123 );
    -BOOST_CHECK( identity_d(1.23) == 1.23 );
    +
    BOOST_CHECK(identity_s("abc") == "abc");
    +BOOST_CHECK(identity_i(123) == 123);
    +BOOST_CHECK(identity_d(1.23) == 1.23);
     

    @@ -108,9 +108,9 @@ > identity(identity_s, identity_i, identity_d); // All calls via single `identity` function. -BOOST_CHECK( identity("abc") == "abc" ); -BOOST_CHECK( identity(123) == 123 ); -BOOST_CHECK( identity(1.23) == 1.23 ); +BOOST_CHECK(identity("abc") == "abc"); +BOOST_CHECK(identity(123) == 123); +BOOST_CHECK(identity(1.23) == 1.23);

    @@ -133,7 +133,7 @@
- +

Last revised: February 17, 2012 at 20:42:39 GMT

Last revised: February 20, 2012 at 20:10:59 GMT


diff --git a/overloaded_function/test/identity.cpp b/overloaded_function/test/identity.cpp index 7df5b7b..9028af7 100644 --- a/overloaded_function/test/identity.cpp +++ b/overloaded_function/test/identity.cpp @@ -14,9 +14,9 @@ //[identity_make_checks template void check(F identity) { - BOOST_CHECK( identity("abc") == "abc" ); - BOOST_CHECK( identity(123) == 123 ); - BOOST_CHECK( identity(1.23) == 1.23 ); + BOOST_CHECK(identity("abc") == "abc"); + BOOST_CHECK(identity(123) == 123); + BOOST_CHECK(identity(1.23) == 1.23); } //] @@ -30,11 +30,11 @@ double identity_d_impl(double x) { return x; } boost::function identity_d = identity_d_impl; // Functor. //] -BOOST_AUTO_TEST_CASE( test_identity ) { +BOOST_AUTO_TEST_CASE(test_identity) { //[identity_calls - BOOST_CHECK( identity_s("abc") == "abc" ); - BOOST_CHECK( identity_i(123) == 123 ); - BOOST_CHECK( identity_d(1.23) == 1.23 ); + BOOST_CHECK(identity_s("abc") == "abc"); + BOOST_CHECK(identity_i(123) == 123); + BOOST_CHECK(identity_d(1.23) == 1.23); //] { @@ -46,9 +46,9 @@ BOOST_AUTO_TEST_CASE( test_identity ) { > identity(identity_s, identity_i, identity_d); // All calls via single `identity` function. - BOOST_CHECK( identity("abc") == "abc" ); - BOOST_CHECK( identity(123) == 123 ); - BOOST_CHECK( identity(1.23) == 1.23 ); + BOOST_CHECK(identity("abc") == "abc"); + BOOST_CHECK(identity(123) == 123); + BOOST_CHECK(identity(1.23) == 1.23); //] } @@ -57,9 +57,9 @@ BOOST_AUTO_TEST_CASE( test_identity ) { BOOST_AUTO(identity, boost::make_overloaded_function( identity_s, identity_i, identity_d)); - BOOST_CHECK( identity("abc") == "abc" ); - BOOST_CHECK( identity(123) == 123 ); - BOOST_CHECK( identity(1.23) == 1.23 ); + BOOST_CHECK(identity("abc") == "abc"); + BOOST_CHECK(identity(123) == 123); + BOOST_CHECK(identity(1.23) == 1.23); //] } From b2dd5d8ac5517535aa26ae12f0d2abb804b110c3 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Thu, 22 Mar 2012 20:54:20 +0000 Subject: [PATCH 05/51] Split Utility/IdentityType and Functional/OverloadedFunction tests into smaller tests. Updated docs for ScopeExit, LocalFunction, Utility/IdentityType, and Functional/OverloadedFunction. [SVN r77484] --- ..._OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html | 2 +- ...ERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html | 2 +- .../html/boost/make_overloaded_function.html | 2 +- .../doc/html/boost/overloaded_function.html | 22 +++--- .../Getting_Started.html | 19 ++++- .../Tutorial.html | 20 ++---- overloaded_function/doc/html/index.html | 16 ++--- .../doc/overloaded_function.qbk | 23 +++--- overloaded_function/test/Jamfile.v2 | 4 +- overloaded_function/test/functor.cpp | 33 +++++++++ overloaded_function/test/identity.cpp | 70 ------------------- overloaded_function/test/identity.hpp | 25 +++++++ overloaded_function/test/make_call.cpp | 27 +++++++ overloaded_function/test/make_decl.cpp | 23 ++++++ 14 files changed, 167 insertions(+), 121 deletions(-) create mode 100644 overloaded_function/test/functor.cpp delete mode 100644 overloaded_function/test/identity.cpp create mode 100644 overloaded_function/test/identity.hpp create mode 100644 overloaded_function/test/make_call.cpp create mode 100644 overloaded_function/test/make_decl.cpp diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html index e51036e..75aa0dd 100644 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html @@ -33,7 +33,7 @@ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX
-

Description

+

Description

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When specified by the user, this macro must be a non-negative integer number.

See: Getting Started, boost::overloaded_function.

diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html index a8a75b6..380227d 100644 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html @@ -33,7 +33,7 @@ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX
-

Description

+

Description

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When defined by the user, this macro must be an integer number greater or equal than 2 (because at least two distinct functions need to be specified in order to define an overload).

See: Getting Started, boost::overloaded_function.

diff --git a/overloaded_function/doc/html/boost/make_overloaded_function.html b/overloaded_function/doc/html/boost/make_overloaded_function.html index 65d1fce..276cea5 100644 --- a/overloaded_function/doc/html/boost/make_overloaded_function.html +++ b/overloaded_function/doc/html/boost/make_overloaded_function.html @@ -36,7 +36,7 @@ overloaded_function< __function_type__< F1 >, __function_type__< F2 >,...> make_overloaded_function(F1 f1, F2 f2, ...);
-

Description

+

Description

This function template creates and returns an overloaded_function function object that overloads all the specified functions f1, f2, etc.

The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with overloaded_function. This is especially useful when the explicit type of the returned overloaded_function does not need to be known (e.g., when used with Boost.Typeof's BOOST_AUTO (or C++11 auto) or when the overloaded function object is handled using a function template parameter, see the Tutorial section).

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro.

diff --git a/overloaded_function/doc/html/boost/overloaded_function.html b/overloaded_function/doc/html/boost/overloaded_function.html index 4f70698..fd63c83 100644 --- a/overloaded_function/doc/html/boost/overloaded_function.html +++ b/overloaded_function/doc/html/boost/overloaded_function.html @@ -35,19 +35,19 @@ class overloaded_function { public: // construct/copy/destruct - overloaded_function(const boost::function< F1 > &, + overloaded_function(const boost::function< F1 > &, const boost::function< F2 > &, ...); - // public member functions + // public member functions boost::function_traits< F1 >::result_type - operator()(typename boost::function_traits< F1 >::arg1_type, + operator()(typename boost::function_traits< F1 >::arg1_type, typename boost::function_traits< F1 >::arg2_type, ...) const; boost::function_traits< F2 >::result_type - operator()(typename boost::function_traits< F2 >::arg1_type, + operator()(typename boost::function_traits< F2 >::arg1_type, typename boost::function_traits< F2 >::arg2_type, ...) const; };
-

Description

+

Description

This function object aggregates together calls to functions of all the specified function types F1, F2, etc. The specified function types must have distinct parameters from one another and they must be in the following format (which is the Boost.Function preferred syntax):

    result_type (argument1_type, argumgnet2_type, ...)
 
@@ -55,27 +55,27 @@

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro. The maximum number of function parameters for each of the specified function types is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX configuration macro.

See: Tutorial section, make_overloaded_function, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, Boost.Function.

-

+

overloaded_function public construct/copy/destruct

  1. -
    overloaded_function(const boost::function< F1 > &, 
    +
    overloaded_function(const boost::function< F1 > &, 
                         const boost::function< F2 > &, ...);
    Construct the overloaded function object.

    Any function pointer, function reference, and monomorphic function object that can be converted to a boost::function function object can be specified as parameter.

-

-overloaded_function public member functions

+

+overloaded_function public member functions

  1. boost::function_traits< F1 >::result_type 
    -operator()(typename boost::function_traits< F1 >::arg1_type, 
    +operator()(typename boost::function_traits< F1 >::arg1_type, 
                typename boost::function_traits< F1 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 1st template parameter.

    This will in turn invoke the call operator of the 1st function passed to the constructor.

  2. boost::function_traits< F2 >::result_type 
    -operator()(typename boost::function_traits< F2 >::arg1_type, 
    +operator()(typename boost::function_traits< F2 >::arg1_type, 
                typename boost::function_traits< F2 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 2nd template parameter.

    This will in turn invoke the call operator of the 2nd function passed to the constructor.

    Note: Similar call operators are present for all specified function types F1, F2, etc (even if not exhaustively listed by this documentation).

  3. diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html index 0a15517..da6325e 100644 --- a/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html +++ b/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html @@ -41,9 +41,22 @@ and Platforms

- The library was tested by the authors on GCC 4.5.3 (with and without C++11 - features -std=c++0x) and MSVC 8.0 under Linux, Cygwin, - and Windows 7. + The authors originally developed and tested the library on: +

+
    +
  1. + GNU Compiler Collection (GCC) C++ 4.5.3 (with and without C++11 features + enabled -std=c++0x) + on Cygwin. +
  2. +
  3. + Miscrosoft Visual C++ (MSVC) 8.0 on Windows 7. +
  4. +
+

+ See the library regressions + test results for detailed information on supported compilers and + platforms.

diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html index cbb370d..1f565ef 100644 --- a/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html +++ b/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html @@ -42,23 +42,15 @@ Consider the following functions with distinct signatures:

-

-
const std::string& identity_s(const std::string& x) { return x; } // As pointer.
-
-int identity_i_impl(int x) { return x; }
-int (&identity_i)(int) = identity_i_impl; // Function reference.
-
-double identity_d_impl(double x) { return x; }
-boost::function<double (double)> identity_d = identity_d_impl; // Functor.
-
-

+ [identity_decls]

This library header boost/functional/overloaded_function.hpp provides a boost::overloaded_function class template that creates a single overloaded function object that can be used to call the specified functions instead of using the separate function - names (see also identity.cpp): + names (see also functor.cpp + and identity.hpp):

@@ -114,7 +106,8 @@

The boost::make_overloaded_function function template can be useful when used together with Boost.Typeof's - BOOST_AUTO (or C++11 auto). For example (see also identity.cpp): + BOOST_AUTO (or C++11 auto). For example (see also make_decl.cpp + and identity.hpp):

@@ -143,7 +136,8 @@ Another case where boost::make_overloaded_function can be useful is when the overloaded function object is passed to a function template which can hide the specific boost::overloaded_function - type using a template parameter. For example (see also identity.cpp): + type using a template parameter. For example (see also make_call.cpp + and identity.hpp):

diff --git a/overloaded_function/doc/html/index.html b/overloaded_function/doc/html/index.html index f900f8e..1ca359c 100644 --- a/overloaded_function/doc/html/index.html +++ b/overloaded_function/doc/html/index.html @@ -69,16 +69,7 @@ Consider the following functions with distinct signatures:

-

-
const std::string& identity_s(const std::string& x) { return x; } // As pointer.
-
-int identity_i_impl(int x) { return x; }
-int (&identity_i)(int) = identity_i_impl; // Function reference.
-
-double identity_d_impl(double x) { return x; }
-boost::function<double (double)> identity_d = identity_d_impl; // Functor.
-
-

+ [identity_decls]

Instead of calling them using their separate names (here BOOST_CHECK @@ -97,7 +88,8 @@ It is possible to use this library to create a single overloaded function object (or functor) named identity that aggregates - together the calls to the specific functions (see also identity.cpp): + together the calls to the specific functions (see also functor.cpp + and identity.hpp):

@@ -133,7 +125,7 @@
- +

Last revised: February 20, 2012 at 20:10:59 GMT

Last revised: March 22, 2012 at 20:51:03 GMT


diff --git a/overloaded_function/doc/overloaded_function.qbk b/overloaded_function/doc/overloaded_function.qbk index 0c1d589..8d2bf06 100644 --- a/overloaded_function/doc/overloaded_function.qbk +++ b/overloaded_function/doc/overloaded_function.qbk @@ -27,7 +27,9 @@ [def __Boost_Function__ [@http://www.boost.org/libs/function Boost.Function]] [def __Boost_Typeof__ [@http://www.boost.org/doc/libs/typeof Boost.Typeof]] -[import ../test/identity.cpp] +[import ../test/functor.cpp] +[import ../test/make_decl.cpp] +[import ../test/make_call.cpp] This library allows to overload different functions into a single function object. @@ -45,9 +47,9 @@ The examples of this documentation are executed as part of the library test suit [identity_calls] -It is possible to use this library to create a single [@http://en.wikipedia.org/wiki/Function_overloading overloaded] function object (or [@http://en.wikipedia.org/wiki/Functor functor]) named `identity` that aggregates together the calls to the specific functions (see also [@../../test/identity.cpp =identity.cpp=]): +It is possible to use this library to create a single [@http://en.wikipedia.org/wiki/Function_overloading overloaded] function object (or [@http://en.wikipedia.org/wiki/Functor functor]) named `identity` that aggregates together the calls to the specific functions (see also [@../../test/functor.cpp =functor.cpp=] and [@../../test/identity.hpp =identity.hpp=]): -[identity] +[identity_functor] Note how the functions are called via a single overloaded function object `identity` instead of using their different names `identity_s`, `identity_i`, and `identity_d`. @@ -59,7 +61,12 @@ This section explains how to setup a system to use this library. [section Compilers and Platforms] -The library was tested by the authors on GCC 4.5.3 (with and without C++11 features [^-std=c++0x]) and MSVC 8.0 under Linux, Cygwin, and Windows 7. +The authors originally developed and tested the library on: + +# GNU Compiler Collection (GCC) C++ 4.5.3 (with and without C++11 features enabled `-std=c++0x`) on Cygwin. +# Miscrosoft Visual C++ (MSVC) 8.0 on Windows 7. + +See the library [@http://www.boost.org/development/tests/release/developer/functional-overloaded_function.html regressions test results] for detailed information on supported compilers and platforms. [endsect] @@ -87,9 +94,9 @@ Consider the following functions with distinct signatures: [identity_decls] -This library header [headerref boost/functional/overloaded_function.hpp] provides a [classref boost::overloaded_function] class template that creates a single overloaded function object that can be used to call the specified functions instead of using the separate function names (see also [@../../test/identity.cpp =identity.cpp=]): +This library header [headerref boost/functional/overloaded_function.hpp] provides a [classref boost::overloaded_function] class template that creates a single overloaded function object that can be used to call the specified functions instead of using the separate function names (see also [@../../test/functor.cpp =functor.cpp=] and [@../../test/identity.hpp =identity.hpp=]): -[identity] +[identity_functor] Note how function types in the following format are passed as template parameters to [classref boost::overloaded_function] (this is the format of __Boost_Function__'s preferred syntax): @@ -119,7 +126,7 @@ For convenience, this library also provides the [funcref boost::make_overloaded_ The function types are automatically deduced from the specified functions and the appropriate [classref boost::overloaded_function] instantiation is returned by [funcref boost::make_overloaded_function]. The [funcref boost::make_overloaded_function] function template can be useful when used together with __Boost_Typeof__'s `BOOST_AUTO` (or C++11 `auto`). -For example (see also [@../../test/identity.cpp =identity.cpp=]): +For example (see also [@../../test/make_decl.cpp =make_decl.cpp=] and [@../../test/identity.hpp =identity.hpp=]): [identity_make] @@ -127,7 +134,7 @@ Note how the overloaded function object `identity` has been created specifying o Therefore, [funcref boost::make_overloaded_function] provides a more concise syntax in this context when compared with [classref boost::overloaded_function]. Another case where [funcref boost::make_overloaded_function] can be useful is when the overloaded function object is passed to a function template which can hide the specific [classref boost::overloaded_function] type using a template parameter. -For example (see also [@../../test/identity.cpp =identity.cpp=]): +For example (see also [@../../test/make_call.cpp =make_call.cpp=] and [@../../test/identity.hpp =identity.hpp=]): [identity_make_checks] [identity_make_call] diff --git a/overloaded_function/test/Jamfile.v2 b/overloaded_function/test/Jamfile.v2 index 8856aac..70d65f9 100644 --- a/overloaded_function/test/Jamfile.v2 +++ b/overloaded_function/test/Jamfile.v2 @@ -9,5 +9,7 @@ import testing ; project : requirements /boost//unit_test_framework ; -run identity.cpp ; +run functor.cpp ; +run make_decl.cpp ; +run make_call.cpp ; diff --git a/overloaded_function/test/functor.cpp b/overloaded_function/test/functor.cpp new file mode 100644 index 0000000..6f028a3 --- /dev/null +++ b/overloaded_function/test/functor.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/functional/overloaded_function + +#include "identity.hpp" +#include +#define BOOST_TEST_MODULE TestFunctor +#include + +BOOST_AUTO_TEST_CASE(test_functor) { + //[identity_calls + BOOST_CHECK(identity_s("abc") == "abc"); + BOOST_CHECK(identity_i(123) == 123); + BOOST_CHECK(identity_d(1.23) == 1.23); + //] + + //[identity_functor + boost::overloaded_function< + const std::string& (const std::string&) + , int (int) + , double (double) + > identity(identity_s, identity_i, identity_d); + + // All calls via single `identity` function. + BOOST_CHECK(identity("abc") == "abc"); + BOOST_CHECK(identity(123) == 123); + BOOST_CHECK(identity(1.23) == 1.23); + //] +} + diff --git a/overloaded_function/test/identity.cpp b/overloaded_function/test/identity.cpp deleted file mode 100644 index 9028af7..0000000 --- a/overloaded_function/test/identity.cpp +++ /dev/null @@ -1,70 +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/functional/overloaded_function - -#include -#include -#define BOOST_TEST_MODULE TestIdentity -#include -#include - -//[identity_make_checks -template -void check(F identity) { - BOOST_CHECK(identity("abc") == "abc"); - BOOST_CHECK(identity(123) == 123); - BOOST_CHECK(identity(1.23) == 1.23); -} -//] - -//[identity_decls -const std::string& identity_s(const std::string& x) { return x; } // As pointer. - -int identity_i_impl(int x) { return x; } -int (&identity_i)(int) = identity_i_impl; // Function reference. - -double identity_d_impl(double x) { return x; } -boost::function identity_d = identity_d_impl; // Functor. -//] - -BOOST_AUTO_TEST_CASE(test_identity) { - //[identity_calls - BOOST_CHECK(identity_s("abc") == "abc"); - BOOST_CHECK(identity_i(123) == 123); - BOOST_CHECK(identity_d(1.23) == 1.23); - //] - - { - //[identity - boost::overloaded_function< - const std::string& (const std::string&) - , int (int) - , double (double) - > identity(identity_s, identity_i, identity_d); - - // All calls via single `identity` function. - BOOST_CHECK(identity("abc") == "abc"); - BOOST_CHECK(identity(123) == 123); - BOOST_CHECK(identity(1.23) == 1.23); - //] - } - - { - //[identity_make - BOOST_AUTO(identity, boost::make_overloaded_function( - identity_s, identity_i, identity_d)); - - BOOST_CHECK(identity("abc") == "abc"); - BOOST_CHECK(identity(123) == 123); - BOOST_CHECK(identity(1.23) == 1.23); - //] - } - - //[identity_make_call - check(boost::make_overloaded_function(identity_s, identity_i, identity_d)); - //] -} - diff --git a/overloaded_function/test/identity.hpp b/overloaded_function/test/identity.hpp new file mode 100644 index 0000000..6602152 --- /dev/null +++ b/overloaded_function/test/identity.hpp @@ -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/functional/overloaded_function + +#ifndef IDENTITY_HPP_ +#define IDENTITY_HPP_ + +#include +#include + +//[identity_decls +const std::string& identity_s(const std::string& x) { return x; } // As pointer. + +int identity_i_impl(int x) { return x; } +int (&identity_i)(int) = identity_i_impl; // Function reference. + +double identity_d_impl(double x) { return x; } +boost::function identity_d = identity_d_impl; // Functor. +//] + +#endif // #include guard + diff --git a/overloaded_function/test/make_call.cpp b/overloaded_function/test/make_call.cpp new file mode 100644 index 0000000..651fb10 --- /dev/null +++ b/overloaded_function/test/make_call.cpp @@ -0,0 +1,27 @@ + +// 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/functional/overloaded_function + +#include "identity.hpp" +#include +#define BOOST_TEST_MODULE TestMakeCall +#include + +//[identity_make_checks +template +void check(F identity) { + BOOST_CHECK(identity("abc") == "abc"); + BOOST_CHECK(identity(123) == 123); + BOOST_CHECK(identity(1.23) == 1.23); +} +//] + +BOOST_AUTO_TEST_CASE(test_identity) { + //[identity_make_call + check(boost::make_overloaded_function(identity_s, identity_i, identity_d)); + //] +} + diff --git a/overloaded_function/test/make_decl.cpp b/overloaded_function/test/make_decl.cpp new file mode 100644 index 0000000..4348e9c --- /dev/null +++ b/overloaded_function/test/make_decl.cpp @@ -0,0 +1,23 @@ + +// 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/functional/overloaded_function + +#include "identity.hpp" +#include +#define BOOST_TEST_MODULE TestMakeDecl +#include + +BOOST_AUTO_TEST_CASE(test_make_decl) { + //[identity_make + BOOST_AUTO(identity, boost::make_overloaded_function( + identity_s, identity_i, identity_d)); + + BOOST_CHECK(identity("abc") == "abc"); + BOOST_CHECK(identity(123) == 123); + BOOST_CHECK(identity(1.23) == 1.23); + //] +} + From 1326990a7ef8fd17e19737706e03d25a37ede9b0 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Mon, 2 Apr 2012 01:08:20 +0000 Subject: [PATCH 06/51] Registering all types so Boost.Functional/OverloadedFunction works in type-of emulation mode (and not just native). [SVN r77709] --- .../boost/functional/overloaded_function.hpp | 16 ++++++++++++---- overloaded_function/test/Jamfile.v2 | 2 -- overloaded_function/test/functor.cpp | 19 ++++++++++--------- overloaded_function/test/identity.hpp | 6 ++++++ overloaded_function/test/make_call.cpp | 12 ++++++------ overloaded_function/test/make_decl.cpp | 12 ++++++------ 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/include/boost/functional/overloaded_function.hpp b/include/boost/functional/overloaded_function.hpp index a918e11..e8ee9f3 100644 --- a/include/boost/functional/overloaded_function.hpp +++ b/include/boost/functional/overloaded_function.hpp @@ -14,6 +14,7 @@ # include # include # include +# include # include # include # include @@ -81,8 +82,6 @@ BOOST_FUNCTIONAL_f_type(z, n, ~) \ >::type -namespace boost { - // Iterate within namespace. # define BOOST_PP_ITERATION_PARAMS_1 \ (3, (0, BOOST_PP_SUB( /*at least 2 func to overload 2, 3, ...*/\ @@ -90,8 +89,6 @@ namespace boost { "boost/functional/overloaded_function.hpp")) # include BOOST_PP_ITERATE() // Iterate over function arity. -} // namespace - #undef BOOST_FUNCTIONAL_f_type #undef BOOST_FUNCTIONAL_f_arg #undef BOOST_FUNCTIONAL_f_tparam @@ -119,6 +116,11 @@ namespace boost { BOOST_PP_LESS(BOOST_FUNCTIONAL_overloads, \ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX) +// For type-of emulation: This must be included at this pp iteration level. +# include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +namespace boost { + template< BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_tparam_dflt, BOOST_FUNCTIONAL_is_tspec) @@ -165,6 +167,12 @@ overloaded_function< >(BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_arg, ~)); } +} // namespace + +// For type-of emulation: Register overloaded function type (for _AUTO, etc). +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::overloaded_function, + BOOST_FUNCTIONAL_overloads) + # undef BOOST_FUNCTIONAL_overloads # undef BOOST_FUNCTIONAL_is_tspec #endif // iteration diff --git a/overloaded_function/test/Jamfile.v2 b/overloaded_function/test/Jamfile.v2 index 70d65f9..6b4c0b0 100644 --- a/overloaded_function/test/Jamfile.v2 +++ b/overloaded_function/test/Jamfile.v2 @@ -7,8 +7,6 @@ import testing ; -project : requirements /boost//unit_test_framework ; - run functor.cpp ; run make_decl.cpp ; run make_call.cpp ; diff --git a/overloaded_function/test/functor.cpp b/overloaded_function/test/functor.cpp index 6f028a3..86827fc 100644 --- a/overloaded_function/test/functor.cpp +++ b/overloaded_function/test/functor.cpp @@ -7,14 +7,13 @@ #include "identity.hpp" #include -#define BOOST_TEST_MODULE TestFunctor -#include +#include -BOOST_AUTO_TEST_CASE(test_functor) { +int main() { //[identity_calls - BOOST_CHECK(identity_s("abc") == "abc"); - BOOST_CHECK(identity_i(123) == 123); - BOOST_CHECK(identity_d(1.23) == 1.23); + BOOST_TEST(identity_s("abc") == "abc"); + BOOST_TEST(identity_i(123) == 123); + BOOST_TEST(identity_d(1.23) == 1.23); //] //[identity_functor @@ -25,9 +24,11 @@ BOOST_AUTO_TEST_CASE(test_functor) { > identity(identity_s, identity_i, identity_d); // All calls via single `identity` function. - BOOST_CHECK(identity("abc") == "abc"); - BOOST_CHECK(identity(123) == 123); - BOOST_CHECK(identity(1.23) == 1.23); + BOOST_TEST(identity("abc") == "abc"); + BOOST_TEST(identity(123) == 123); + BOOST_TEST(identity(1.23) == 1.23); //] + + return boost::report_errors(); } diff --git a/overloaded_function/test/identity.hpp b/overloaded_function/test/identity.hpp index 6602152..db7905a 100644 --- a/overloaded_function/test/identity.hpp +++ b/overloaded_function/test/identity.hpp @@ -19,6 +19,12 @@ int (&identity_i)(int) = identity_i_impl; // Function reference. double identity_d_impl(double x) { return x; } boost::function identity_d = identity_d_impl; // Functor. + +// For type-of emulation on compilers without native type-of. +#include +#include +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function1, 2) // Use `functionN`. //] #endif // #include guard diff --git a/overloaded_function/test/make_call.cpp b/overloaded_function/test/make_call.cpp index 651fb10..e2abdde 100644 --- a/overloaded_function/test/make_call.cpp +++ b/overloaded_function/test/make_call.cpp @@ -7,21 +7,21 @@ #include "identity.hpp" #include -#define BOOST_TEST_MODULE TestMakeCall -#include +#include //[identity_make_checks template void check(F identity) { - BOOST_CHECK(identity("abc") == "abc"); - BOOST_CHECK(identity(123) == 123); - BOOST_CHECK(identity(1.23) == 1.23); + BOOST_TEST(identity("abc") == "abc"); + BOOST_TEST(identity(123) == 123); + BOOST_TEST(identity(1.23) == 1.23); } //] -BOOST_AUTO_TEST_CASE(test_identity) { +int main() { //[identity_make_call check(boost::make_overloaded_function(identity_s, identity_i, identity_d)); //] + return boost::report_errors(); } diff --git a/overloaded_function/test/make_decl.cpp b/overloaded_function/test/make_decl.cpp index 4348e9c..919b77b 100644 --- a/overloaded_function/test/make_decl.cpp +++ b/overloaded_function/test/make_decl.cpp @@ -7,17 +7,17 @@ #include "identity.hpp" #include -#define BOOST_TEST_MODULE TestMakeDecl -#include +#include -BOOST_AUTO_TEST_CASE(test_make_decl) { +int main() { //[identity_make BOOST_AUTO(identity, boost::make_overloaded_function( identity_s, identity_i, identity_d)); - BOOST_CHECK(identity("abc") == "abc"); - BOOST_CHECK(identity(123) == 123); - BOOST_CHECK(identity(1.23) == 1.23); + BOOST_TEST(identity("abc") == "abc"); + BOOST_TEST(identity(123) == 123); + BOOST_TEST(identity(1.23) == 1.23); //] + return boost::report_errors(); } From afa123f28ec9cad01dafbf4578b71e4fe48e3412 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Wed, 4 Apr 2012 21:15:16 +0000 Subject: [PATCH 07/51] Added a temporary workaround the Boost.Config bug that causes Boost.Typeof to fail on Sun (Jamfile __typeof__=__typeof__ so Boost.Config does not define __typeof__ to be typeof). [SVN r77770] --- overloaded_function/test/Jamfile.v2 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/overloaded_function/test/Jamfile.v2 b/overloaded_function/test/Jamfile.v2 index 6b4c0b0..079b116 100644 --- a/overloaded_function/test/Jamfile.v2 +++ b/overloaded_function/test/Jamfile.v2 @@ -7,6 +7,9 @@ import testing ; +# Workaround a Boost.Config bug that causes Boost.Typeof to fail on Sun. +project : requirements sun:__typeof__=__typeof__ ; + run functor.cpp ; run make_decl.cpp ; run make_call.cpp ; From 6abc944e570667f92343d637a1656f8b5d425be7 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Sat, 7 Apr 2012 18:45:13 +0000 Subject: [PATCH 08/51] Wrapped a metafunction call into a local struct to try to workaround a problem with add_template on the intel compiler. [SVN r77820] --- overloaded_function/test/identity.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/overloaded_function/test/identity.hpp b/overloaded_function/test/identity.hpp index db7905a..a1419f5 100644 --- a/overloaded_function/test/identity.hpp +++ b/overloaded_function/test/identity.hpp @@ -24,7 +24,8 @@ boost::function identity_d = identity_d_impl; // Functor. #include #include #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() -BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function1, 2) // Use `functionN`. +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function, 1) +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function1, 2) // Also `functionN`. //] #endif // #include guard From 01aba11b879e72d7df0cc156546cc2465e97e058 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Sat, 7 Apr 2012 19:43:03 +0000 Subject: [PATCH 09/51] Trying to fix a pp error on Sun... using a separate macro to force expansion but not sure if that was the issue. [SVN r77823] --- include/boost/functional/overloaded_function.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/boost/functional/overloaded_function.hpp b/include/boost/functional/overloaded_function.hpp index e8ee9f3..fc88a1b 100644 --- a/include/boost/functional/overloaded_function.hpp +++ b/include/boost/functional/overloaded_function.hpp @@ -83,10 +83,14 @@ >::type // Iterate within namespace. +# define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_OVERLOAD_COUNT \ + /*at least 2 func to overload 2, 3, ...*/ \ + BOOST_PP_SUB( \ + BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, \ + 2) # define BOOST_PP_ITERATION_PARAMS_1 \ - (3, (0, BOOST_PP_SUB( /*at least 2 func to overload 2, 3, ...*/\ - BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, 2), \ - "boost/functional/overloaded_function.hpp")) + (3, (0, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_OVERLOAD_COUNT, \ + "boost/functional/overloaded_function.hpp")) # include BOOST_PP_ITERATE() // Iterate over function arity. #undef BOOST_FUNCTIONAL_f_type From 3910f072cd3548b4db11549fbb43b721fd19c3c1 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 8 Apr 2012 15:29:15 +0000 Subject: [PATCH 10/51] Unordered/hash: Avoid a gcc warning. Refs #6771 [SVN r77832] --- hash/test/Jamfile.v2 | 4 ++-- hash/test/hash_complex_test.cpp | 4 ++++ hash/test/hash_float_test.hpp | 4 ++++ hash/test/hash_number_test.cpp | 4 ++++ .../boost/functional/hash/detail/hash_float.hpp | 16 +++++++++++++++- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index 7b3ccd9..cf64ece 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -10,8 +10,8 @@ project hash-tests all intel:on intel:-strict-ansi - gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion" - darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion" + gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal" + darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal" msvc:on #gcc:on #darwin:on diff --git a/hash/test/hash_complex_test.cpp b/hash/test/hash_complex_test.cpp index 67e2aff..bb1592c 100644 --- a/hash/test/hash_complex_test.cpp +++ b/hash/test/hash_complex_test.cpp @@ -35,6 +35,10 @@ int main() {} #endif #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + #include #include #include diff --git a/hash/test/hash_float_test.hpp b/hash/test/hash_float_test.hpp index dd1358e..c608915 100644 --- a/hash/test/hash_float_test.hpp +++ b/hash/test/hash_float_test.hpp @@ -30,6 +30,10 @@ #endif #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + char const* float_type(float*) { return "float"; } char const* float_type(double*) { return "double"; } char const* float_type(long double*) { return "long double"; } diff --git a/hash/test/hash_number_test.cpp b/hash/test/hash_number_test.cpp index b989d22..b233c71 100644 --- a/hash/test/hash_number_test.cpp +++ b/hash/test/hash_number_test.cpp @@ -28,6 +28,10 @@ #pragma warning(disable:4310) // cast truncates constant value #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + template void numeric_test(T*) { diff --git a/include/boost/functional/hash/detail/hash_float.hpp b/include/boost/functional/hash/detail/hash_float.hpp index ea1bc25..194be1c 100644 --- a/include/boost/functional/hash/detail/hash_float.hpp +++ b/include/boost/functional/hash/detail/hash_float.hpp @@ -86,10 +86,24 @@ namespace boost { namespace hash_detail { + template + inline bool is_zero(T v) + { +#if !defined(__GNUC__) + return v == 0; +#else + // GCC's '-Wfloat-equal' will complain about comparing + // v to 0, but because it disables warnings for system + // headers it won't complain if you use std::equal_to to + // compare with 0. Resulting in this silliness: + return std::equal_to()(v, 0); +#endif + } + template inline std::size_t float_hash_value(T v) { - return v == 0 ? 0 : float_hash_impl(v); + return boost::hash_detail::is_zero(v) ? 0 : float_hash_impl(v); } } } From e7e599a7d230ef09f34b6aaf4d4043f495898571 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Mon, 9 Apr 2012 22:33:45 +0000 Subject: [PATCH 11/51] Added a test to figure out problem on Sun... [SVN r77867] --- overloaded_function/test/Jamfile.v2 | 4 +--- overloaded_function/test/sun_bug.cpp | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 overloaded_function/test/sun_bug.cpp diff --git a/overloaded_function/test/Jamfile.v2 b/overloaded_function/test/Jamfile.v2 index 079b116..160130d 100644 --- a/overloaded_function/test/Jamfile.v2 +++ b/overloaded_function/test/Jamfile.v2 @@ -7,10 +7,8 @@ import testing ; -# Workaround a Boost.Config bug that causes Boost.Typeof to fail on Sun. -project : requirements sun:__typeof__=__typeof__ ; - run functor.cpp ; run make_decl.cpp ; run make_call.cpp ; +run sun_bug.cpp ; diff --git a/overloaded_function/test/sun_bug.cpp b/overloaded_function/test/sun_bug.cpp new file mode 100644 index 0000000..024d4b3 --- /dev/null +++ b/overloaded_function/test/sun_bug.cpp @@ -0,0 +1,5 @@ + +#include + +int main() { return 0; } + From 9e7ccedcfef4411efe459c192e05ea79de7108fc Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Tue, 10 Apr 2012 19:17:41 +0000 Subject: [PATCH 12/51] Added a specialization to deduced F from boost::function removing the need to register boost::function for type-of emulation (because it required to register boost::functionN instead of boost::function and that was confusing). [SVN r77891] --- .../overloaded_function/detail/function_type.hpp | 12 +++++++++++- overloaded_function/test/identity.hpp | 7 ------- overloaded_function/test/make_decl.cpp | 2 ++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/boost/functional/overloaded_function/detail/function_type.hpp b/include/boost/functional/overloaded_function/detail/function_type.hpp index 4169ee9..0c28607 100644 --- a/include/boost/functional/overloaded_function/detail/function_type.hpp +++ b/include/boost/functional/overloaded_function/detail/function_type.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,15 @@ public: type; }; +// NOTE: When using boost::function in Boost.Typeof emulation mode, the user +// has to register boost::functionN instead of boost::function in oder to +// do TYPEOF(F::operator()). That is confusing, so boost::function is handled +// separately so it does not require any Boost.Typeof registration at all. +template +struct functor_type< boost::function > { + typedef F type; +}; + // Requires: F is a function type, pointer, reference, or monomorphic functor. // Returns: F's function type `result_type (arg1_type, arg2_type, ...)`. template @@ -61,7 +71,7 @@ struct function_type { typename boost::mpl::if_, boost::remove_reference - , // Requires, it's a functor. + , // Else, requires that F is a functor. functor_type >::type >::type diff --git a/overloaded_function/test/identity.hpp b/overloaded_function/test/identity.hpp index a1419f5..6602152 100644 --- a/overloaded_function/test/identity.hpp +++ b/overloaded_function/test/identity.hpp @@ -19,13 +19,6 @@ int (&identity_i)(int) = identity_i_impl; // Function reference. double identity_d_impl(double x) { return x; } boost::function identity_d = identity_d_impl; // Functor. - -// For type-of emulation on compilers without native type-of. -#include -#include -#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() -BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function, 1) -BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function1, 2) // Also `functionN`. //] #endif // #include guard diff --git a/overloaded_function/test/make_decl.cpp b/overloaded_function/test/make_decl.cpp index 919b77b..7aae187 100644 --- a/overloaded_function/test/make_decl.cpp +++ b/overloaded_function/test/make_decl.cpp @@ -7,6 +7,8 @@ #include "identity.hpp" #include +#include // For `BOOST_AUTO`. +#include // No need to register `boost::function`. #include int main() { From f6beb74abb8385969f373e6c31c1c8d3845fc867 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Tue, 10 Apr 2012 20:42:53 +0000 Subject: [PATCH 13/51] Updated docs. [SVN r77899] --- .../boost/functional/overloaded_function.hpp | 39 +++++++---- ..._OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html | 2 +- ...ERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html | 2 +- .../html/boost/make_overloaded_function.html | 8 +-- .../doc/html/boost/overloaded_function.html | 47 ++++++++----- .../Getting_Started.html | 9 +-- .../Tutorial.html | 70 ++++++++++++++----- overloaded_function/doc/html/index.html | 43 ++++++++---- overloaded_function/doc/html/reference.html | 2 +- .../doc/overloaded_function.qbk | 34 +++++---- overloaded_function/test/identity.hpp | 6 +- overloaded_function/test/make_decl.cpp | 5 +- 12 files changed, 175 insertions(+), 92 deletions(-) diff --git a/include/boost/functional/overloaded_function.hpp b/include/boost/functional/overloaded_function.hpp index fc88a1b..2ed228d 100644 --- a/include/boost/functional/overloaded_function.hpp +++ b/include/boost/functional/overloaded_function.hpp @@ -186,8 +186,8 @@ BOOST_TYPEOF_REGISTER_TEMPLATE(boost::overloaded_function, #else // DOXYGEN /** @file -@brief Overload distinct function pointers, function references, and function -objects into a single function object. +@brief Overload distinct function pointers, function references, and +monomorphic function objects into a single function object. */ namespace boost { @@ -196,18 +196,25 @@ namespace boost { @brief Function object to overload functions with distinct signatures. This function object aggregates together calls to functions of all the -specified function types F1, F2, etc. -The specified function types must have distinct parameters from one another and -they must be in the following format (which is the Boost.Function preferred -syntax): +specified function types F1, F2, etc which must have distinct +function signatures from one another. + +@Params +@Param{Fi, +Each function type must be specified using the following syntax (which is +Boost.Function's preferred syntax): @code - result_type (argument1_type, argumgnet2_type, ...) + result_type (argument1_type\, argumgnet2_type\, ...) @endcode +} +@EndParams In some cases, the @RefFunc{make_overloaded_function} function template can be -useful to construct the overloaded function object without explicitly +useful to construct an overloaded function object without explicitly specifying the function types. +At least two distinct function types must be specified (because there is +nothing to overload between one or zero functions). The maximum number of functions to overload is given by the @RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX} configuration macro. @@ -232,6 +239,10 @@ public: Any function pointer, function reference, and monomorphic function object that can be converted to a boost::function function object can be specified as parameter. + + @Note Unfortunately, it is not possible to support polymorphic function + objects (as explained here). */ overloaded_function(const boost::function&, const boost::function&, ...); @@ -270,24 +281,24 @@ public: function types. This function template creates and returns an @RefClass{overloaded_function} -function object that overloads all the specified functions f1, -f2, etc. +object that overloads all the specified functions f1, f2, etc. The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with @RefClass{overloaded_function}. This is especially useful when the explicit type of the returned -@RefClass{overloaded_function} does not need to be known (e.g., when used with Boost.Typeof's BOOST_AUTO (or C++11 auto) or when the overloaded -function object is handled using a function template parameter, see the -@RefSect{Tutorial} section). +@RefClass{overloaded_function} object does not need to be known (e.g., when +used with Boost.Typeof's BOOST_AUTO, C++11 auto, or when the +overloaded function object is handled using a function template parameter, see +the @RefSect{Tutorial} section). The maximum number of functions to overload is given by the @RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX} configuration macro. @Note In this documentation, __function_type__ is a placeholder for a -symbol that is specific to implementation of this library. +symbol that is specific to the implementation of this library. @See @RefSect{Tutorial} section, diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html index 75aa0dd..9e12102 100644 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html @@ -33,7 +33,7 @@ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX
-

Description

+

Description

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When specified by the user, this macro must be a non-negative integer number.

See: Getting Started, boost::overloaded_function.

diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html index 380227d..acc24c2 100644 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html @@ -33,7 +33,7 @@ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX
-

Description

+

Description

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When defined by the user, this macro must be an integer number greater or equal than 2 (because at least two distinct functions need to be specified in order to define an overload).

See: Getting Started, boost::overloaded_function.

diff --git a/overloaded_function/doc/html/boost/make_overloaded_function.html b/overloaded_function/doc/html/boost/make_overloaded_function.html index 276cea5..8f2b773 100644 --- a/overloaded_function/doc/html/boost/make_overloaded_function.html +++ b/overloaded_function/doc/html/boost/make_overloaded_function.html @@ -36,11 +36,11 @@ overloaded_function< __function_type__< F1 >, __function_type__< F2 >,...> make_overloaded_function(F1 f1, F2 f2, ...);
-

Description

-

This function template creates and returns an overloaded_function function object that overloads all the specified functions f1, f2, etc.

-

The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with overloaded_function. This is especially useful when the explicit type of the returned overloaded_function does not need to be known (e.g., when used with Boost.Typeof's BOOST_AUTO (or C++11 auto) or when the overloaded function object is handled using a function template parameter, see the Tutorial section).

+

Description

+

This function template creates and returns an overloaded_function object that overloads all the specified functions f1, f2, etc.

+

The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with overloaded_function. This is especially useful when the explicit type of the returned overloaded_function object does not need to be known (e.g., when used with Boost.Typeof's BOOST_AUTO, C++11 auto, or when the overloaded function object is handled using a function template parameter, see the Tutorial section).

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro.

-

Note: In this documentation, __function_type__ is a placeholder for a symbol that is specific to implementation of this library.

+

Note: In this documentation, __function_type__ is a placeholder for a symbol that is specific to the implementation of this library.

See: Tutorial section, overloaded_function, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.

diff --git a/overloaded_function/doc/html/boost/overloaded_function.html b/overloaded_function/doc/html/boost/overloaded_function.html index fd63c83..55db374 100644 --- a/overloaded_function/doc/html/boost/overloaded_function.html +++ b/overloaded_function/doc/html/boost/overloaded_function.html @@ -35,47 +35,60 @@ class overloaded_function { public: // construct/copy/destruct - overloaded_function(const boost::function< F1 > &, + overloaded_function(const boost::function< F1 > &, const boost::function< F2 > &, ...); - // public member functions + // public member functions boost::function_traits< F1 >::result_type - operator()(typename boost::function_traits< F1 >::arg1_type, + operator()(typename boost::function_traits< F1 >::arg1_type, typename boost::function_traits< F1 >::arg2_type, ...) const; boost::function_traits< F2 >::result_type - operator()(typename boost::function_traits< F2 >::arg1_type, + operator()(typename boost::function_traits< F2 >::arg1_type, typename boost::function_traits< F2 >::arg2_type, ...) const; };
-

Description

-

This function object aggregates together calls to functions of all the specified function types F1, F2, etc. The specified function types must have distinct parameters from one another and they must be in the following format (which is the Boost.Function preferred syntax):

-
    result_type (argument1_type, argumgnet2_type, ...)
-
-

In some cases, the make_overloaded_function function template can be useful to construct the overloaded function object without explicitly specifying the function types.

-

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro. The maximum number of function parameters for each of the specified function types is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX configuration macro.

+

Description

+

This function object aggregates together calls to functions of all the specified function types F1, F2, etc which must have distinct function signatures from one another.

+

Parameters:

+
++++ + + + + +
FiEach function type must be specified using the following syntax (which is Boost.Function's preferred syntax):
    result_type (argument1_type, argumgnet2_type, ...)
+
+

+

+

In some cases, the make_overloaded_function function template can be useful to construct an overloaded function object without explicitly specifying the function types.

+

At least two distinct function types must be specified (because there is nothing to overload between one or zero functions). The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro. The maximum number of function parameters for each of the specified function types is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX configuration macro.

See: Tutorial section, make_overloaded_function, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, Boost.Function.

-

+

overloaded_function public construct/copy/destruct

  1. -
    overloaded_function(const boost::function< F1 > &, 
    -                    const boost::function< F2 > &, ...);
    Construct the overloaded function object.

    Any function pointer, function reference, and monomorphic function object that can be converted to a boost::function function object can be specified as parameter.

    +
    overloaded_function(const boost::function< F1 > &, 
    +                    const boost::function< F2 > &, ...);
    Construct the overloaded function object.

    Any function pointer, function reference, and monomorphic function object that can be converted to a boost::function function object can be specified as parameter.

    +

    Note: Unfortunately, it is not possible to support polymorphic function objects (as explained here).

-

-overloaded_function public member functions

+

+overloaded_function public member functions

  1. boost::function_traits< F1 >::result_type 
    -operator()(typename boost::function_traits< F1 >::arg1_type, 
    +operator()(typename boost::function_traits< F1 >::arg1_type, 
                typename boost::function_traits< F1 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 1st template parameter.

    This will in turn invoke the call operator of the 1st function passed to the constructor.

  2. boost::function_traits< F2 >::result_type 
    -operator()(typename boost::function_traits< F2 >::arg1_type, 
    +operator()(typename boost::function_traits< F2 >::arg1_type, 
                typename boost::function_traits< F2 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 2nd template parameter.

    This will in turn invoke the call operator of the 2nd function passed to the constructor.

    Note: Similar call operators are present for all specified function types F1, F2, etc (even if not exhaustively listed by this documentation).

  3. diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html index da6325e..6ac82c8 100644 --- a/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html +++ b/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html @@ -41,7 +41,7 @@ and Platforms

- The authors originally developed and tested the library on: + The authors originally developed and tested this library on:

  1. @@ -56,7 +56,8 @@

    See the library regressions test results for detailed information on supported compilers and - platforms. + platforms. Check the library regression test Jamfile.v2 + for any special configuration that might be required for a specific compiler.

@@ -72,9 +73,9 @@

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro. The maximum number of function parameters for each of - the specified function types is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX + the specified function type is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX configuration macro. All configuration macros have appropriate default values - when they are left undefined by the user. + when they are left undefined.

diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html index 1f565ef..8211939 100644 --- a/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html +++ b/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html @@ -39,10 +39,20 @@ Overloading

- Consider the following functions with distinct signatures: + Consider the following functions which have distinct signatures:

- [identity_decls] +

+
const std::string& identity_s(const std::string& x) // Function (as pointer).
+    { return x; }
+
+int identity_i_impl(int x) { return x; }
+int (&identity_i)(int) = identity_i_impl; // Function reference.
+
+double identity_d_impl(double x) { return x; }
+boost::function<double (double)> identity_d = identity_d_impl; // Functor.
+
+

This library header boost/functional/overloaded_function.hpp @@ -61,16 +71,15 @@ > identity(identity_s, identity_i, identity_d); // All calls via single `identity` function. -BOOST_CHECK(identity("abc") == "abc"); -BOOST_CHECK(identity(123) == 123); -BOOST_CHECK(identity(1.23) == 1.23); +BOOST_TEST(identity("abc") == "abc"); +BOOST_TEST(identity(123) == 123); +BOOST_TEST(identity(1.23) == 1.23);

- Note how function types in the following format are passed as template parameters - to boost::overloaded_function - (this is the format of Boost.Function's + Note how each function type is passed as a template parameter of boost::overloaded_function using + the following syntax (this is Boost.Function's preferred syntax):

result-type (argument1-type, argument2-type, ...)
@@ -79,10 +88,10 @@
         Then the relative function pointers, function references, or monomorphic
         function objects are passed to the boost::overloaded_function
         constructor matching the order of the specified template parameters. [2] In the above example, identity_s
-        is passed as function pointer (the function address is automatically taken
-        from the function name by compiler), identity_i
-        as function reference, and identity_d
-        as function object.
+        is passed as a function pointer (the function address is automatically taken
+        from the function name by the compiler), identity_i
+        as a function reference, and identity_d
+        as a function object.
       

All specified function types must have distinct parameters from one another @@ -114,9 +123,9 @@

BOOST_AUTO(identity, boost::make_overloaded_function(
         identity_s, identity_i, identity_d));
 
-BOOST_CHECK(identity("abc") == "abc");
-BOOST_CHECK(identity(123) == 123);
-BOOST_CHECK(identity(1.23) == 1.23);
+BOOST_TEST(identity("abc") == "abc");
+BOOST_TEST(identity(123) == 123);
+BOOST_TEST(identity(1.23) == 1.23);
 

@@ -135,7 +144,7 @@

Another case where boost::make_overloaded_function can be useful is when the overloaded function object is passed to a function - template which can hide the specific boost::overloaded_function + template which can hold the specific boost::overloaded_function type using a template parameter. For example (see also make_call.cpp and identity.hpp):

@@ -143,9 +152,9 @@

template<typename F>
 void check(F identity) {
-    BOOST_CHECK(identity("abc") == "abc");
-    BOOST_CHECK(identity(123) == 123);
-    BOOST_CHECK(identity(1.23) == 1.23);
+    BOOST_TEST(identity("abc") == "abc");
+    BOOST_TEST(identity(123) == 123);
+    BOOST_TEST(identity(1.23) == 1.23);
 }
 

@@ -154,6 +163,27 @@

check(boost::make_overloaded_function(identity_s, identity_i, identity_d));
 
+

+

+

+ The library implementation of boost::make_overloaded_function + uses Boost.Typeof + to automatically deduce some of the function types. In order to compile code + in Boost.Typeof + emulation mode, all types should be properly registered using BOOST_TYPEOF_REGISTER_TYPE and BOOST_TYPEOF_REGISTER_TEMPLATE, or appropriate + Boost.Typeof headers + should be included (see Boost.Typeof + for more information). For the above examples, it is sufficient to include + the Boost.Typeof + header that registers std::string + (this library does not require to register boost::function + for Boost.Typeof + emulation): +

+

+

+
#include <boost/typeof/std/string.hpp> // No need to register `boost::function`.
+

@@ -171,6 +201,8 @@ pointers and function references). Finally, monomorphic function objects are instances of classes with a non-template call operator of the form result-type operator()(argument1-type, ...). + Unfortunately, it is not possible to support polymorphic function objects + (see http://lists.boost.org/Archives/boost/2012/03/191744.php).

[3] Note that in C++ the function result type is not used for overload resolution diff --git a/overloaded_function/doc/html/index.html b/overloaded_function/doc/html/index.html index 1ca359c..c5ac2b1 100644 --- a/overloaded_function/doc/html/index.html +++ b/overloaded_function/doc/html/index.html @@ -66,21 +66,31 @@ Introduction

- Consider the following functions with distinct signatures: + Consider the following functions which have distinct signatures:

- [identity_decls] +

+
const std::string& identity_s(const std::string& x) // Function (as pointer).
+    { return x; }
+
+int identity_i_impl(int x) { return x; }
+int (&identity_i)(int) = identity_i_impl; // Function reference.
+
+double identity_d_impl(double x) { return x; }
+boost::function<double (double)> identity_d = identity_d_impl; // Functor.
+
+

- Instead of calling them using their separate names (here BOOST_CHECK + Instead of calling them using their separate names (here BOOST_TEST is equivalent to assert): [1]

-
BOOST_CHECK(identity_s("abc") == "abc");
-BOOST_CHECK(identity_i(123) == 123);
-BOOST_CHECK(identity_d(1.23) == 1.23);
+
BOOST_TEST(identity_s("abc") == "abc");
+BOOST_TEST(identity_i(123) == 123);
+BOOST_TEST(identity_d(1.23) == 1.23);
 

@@ -100,9 +110,9 @@ > identity(identity_s, identity_i, identity_d); // All calls via single `identity` function. -BOOST_CHECK(identity("abc") == "abc"); -BOOST_CHECK(identity(123) == 123); -BOOST_CHECK(identity(1.23) == 1.23); +BOOST_TEST(identity("abc") == "abc"); +BOOST_TEST(identity(123) == 123); +BOOST_TEST(identity(1.23) == 1.23);

@@ -116,16 +126,19 @@


[1] - In the examples presented in this documentation, BOOST_CHECK - is used instead of assert - because it allows to write regression tests using Boost.Test. - The examples of this documentation are executed as part of the library test - suite to verify that they always compile and run correctly. + In most of the examples presented in this documentation, the Boost.Detail/LightweightTest + (boost/detail/lightweight_test.hpp) macro BOOST_TEST is used to check correctness + conditions (conceptually similar to assert). + A failure of the checked condition does not abort the execution of the program, + it will instead make boost::report_errors + return a non-zero program exit code. Using Boost.Detail/LightweightTest allows + to add the examples to the library regression tests so to make sure that + they always compile and run correctly.

- +

Last revised: March 22, 2012 at 20:51:03 GMT

Last revised: April 10, 2012 at 20:37:20 GMT


diff --git a/overloaded_function/doc/html/reference.html b/overloaded_function/doc/html/reference.html index 4dd4a17..3fcf6f5 100644 --- a/overloaded_function/doc/html/reference.html +++ b/overloaded_function/doc/html/reference.html @@ -32,7 +32,7 @@
-

Overload distinct function pointers, function references, and function objects into a single function object.

+

Overload distinct function pointers, function references, and monomorphic function objects into a single function object.

namespace boost {
   template<typename F1, typename F2, ... > class overloaded_function;
   template<typename F1, typename F2, ... > 
diff --git a/overloaded_function/doc/overloaded_function.qbk b/overloaded_function/doc/overloaded_function.qbk
index 8d2bf06..5bda0df 100644
--- a/overloaded_function/doc/overloaded_function.qbk
+++ b/overloaded_function/doc/overloaded_function.qbk
@@ -27,6 +27,7 @@
 [def __Boost_Function__ [@http://www.boost.org/libs/function Boost.Function]]
 [def __Boost_Typeof__ [@http://www.boost.org/doc/libs/typeof Boost.Typeof]]
 
+[import ../test/identity.hpp]
 [import ../test/functor.cpp]
 [import ../test/make_decl.cpp]
 [import ../test/make_call.cpp]
@@ -35,14 +36,15 @@ This library allows to overload different functions into a single function objec
 
 [section:Introduction Introduction]
 
-Consider the following functions with distinct signatures:
+Consider the following functions which have distinct signatures:
 
 [identity_decls]
 
-Instead of calling them using their separate names (here `BOOST_CHECK` is equivalent to `assert`):
+Instead of calling them using their separate names (here `BOOST_TEST` is equivalent to `assert`):
 [footnote
-In the examples presented in this documentation, `BOOST_CHECK` is used instead of `assert` because it allows to write regression tests using __Boost_Test__.
-The examples of this documentation are executed as part of the library test suite to verify that they always compile and run correctly.
+In most of the examples presented in this documentation, the Boost.Detail/LightweightTest (=boost/detail/lightweight_test.hpp=) macro `BOOST_TEST` is used to check correctness conditions (conceptually similar to `assert`).
+A failure of the checked condition does not abort the execution of the program, it will instead make `boost::report_errors` return a non-zero program exit code.
+Using Boost.Detail/LightweightTest allows to add the examples to the library regression tests so to make sure that they always compile and run correctly.
 ]
 
 [identity_calls]
@@ -61,12 +63,13 @@ This section explains how to setup a system to use this library.
 
 [section Compilers and Platforms]
 
-The authors originally developed and tested the library on:
+The authors originally developed and tested this library on:
 
 # GNU Compiler Collection (GCC) C++ 4.5.3 (with and without C++11 features enabled `-std=c++0x`) on Cygwin.
 # Miscrosoft Visual C++ (MSVC) 8.0 on Windows 7.
 
 See the library [@http://www.boost.org/development/tests/release/developer/functional-overloaded_function.html regressions test results] for detailed information on supported compilers and platforms.
+Check the library regression test [@../../test/Jamfile.v2 =Jamfile.v2=] for any special configuration that might be required for a specific compiler.
 
 [endsect]
 
@@ -77,8 +80,8 @@ Therefore there is no pre-compiled object file which needs to be installed.
 Programmers can simply instruct the compiler where to find the library header files (`-I` option on GCC, `/I` option on MSVC, etc) and compile code using the library.
 
 The maximum number of functions to overload is given by the [macroref BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX] configuration macro.
-The maximum number of function parameters for each of the specified function types is given by the [macroref BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX] configuration macro.
-All configuration macros have appropriate default values when they are left undefined by the user.
+The maximum number of function parameters for each of the specified function type is given by the [macroref BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX] configuration macro.
+All configuration macros have appropriate default values when they are left undefined.
 
 [endsect]
 
@@ -90,7 +93,7 @@ This section explains how to use this library.
 
 [section Overloading]
 
-Consider the following functions with distinct signatures:
+Consider the following functions which have distinct signatures:
 
 [identity_decls]
 
@@ -98,7 +101,7 @@ This library header [headerref boost/functional/overloaded_function.hpp] provide
 
 [identity_functor]
 
-Note how function types in the following format are passed as template parameters to [classref boost::overloaded_function] (this is the format of __Boost_Function__'s preferred syntax):
+Note how each function type is passed as a template parameter of [classref boost::overloaded_function] using the following syntax (this is __Boost_Function__'s preferred syntax):
 
     ``/result-type/`` (``/argument1-type/``, ``/argument2-type/``, ...)
 
@@ -108,8 +111,9 @@ Function pointers are of the form [^['result-type ]]`(*)(`[^['argument1-type]]`,
 Function references are of the form [^['result-type ]]`(&)(`[^['argument1-type]]`, ...)`.
 Function types are of the form [^['result-type ]]`(`[^['argument1-type]]`, ...)` (note how they lack of both `*` and `&` when compared to function pointers and function references).
 Finally, monomorphic function objects are instances of classes with a non-template call operator of the form [^['result-type ]]`operator()(`[^['argument1-type]]`, ...)`.
+Unfortunately, it is not possible to support polymorphic function objects (see [@http://lists.boost.org/Archives/boost/2012/03/191744.php]).
 ]
-In the above example, `identity_s` is passed as function pointer (the function address is automatically taken from the function name by compiler), `identity_i` as function reference, and `identity_d` as function object.
+In the above example, `identity_s` is passed as a function pointer (the function address is automatically taken from the function name by the compiler), `identity_i` as a function reference, and `identity_d` as a function object.
 
 All specified function types must have distinct parameters from one another (so the overloaded calls can be resolved by this library).
 [footnote
@@ -128,17 +132,23 @@ The function types are automatically deduced from the specified functions and th
 The [funcref boost::make_overloaded_function] function template can be useful when used together with __Boost_Typeof__'s `BOOST_AUTO` (or C++11 `auto`).
 For example (see also [@../../test/make_decl.cpp =make_decl.cpp=] and [@../../test/identity.hpp =identity.hpp=]):
 
-[identity_make]
+[identity_make_decl]
 
 Note how the overloaded function object `identity` has been created specifying only the functions `identity_s`, `identity_i`, `identity_d` and without specifying the function types `const std::string& (const std::string&)`, `int (int)`, and `double (double)` as required instead by [classref boost::overloaded_function].
 Therefore, [funcref boost::make_overloaded_function] provides a more concise syntax in this context when compared with [classref boost::overloaded_function].
 
-Another case where [funcref boost::make_overloaded_function] can be useful is when the overloaded function object is passed to a function template which can hide the specific [classref boost::overloaded_function] type using a template parameter.
+Another case where [funcref boost::make_overloaded_function] can be useful is when the overloaded function object is passed to a function template which can hold the specific [classref boost::overloaded_function] type using a template parameter.
 For example (see also [@../../test/make_call.cpp =make_call.cpp=] and [@../../test/identity.hpp =identity.hpp=]):
 
 [identity_make_checks]
 [identity_make_call]
 
+The library implementation of [funcref boost::make_overloaded_function] uses __Boost_Typeof__ to automatically deduce some of the function types.
+In order to compile code in __Boost_Typeof__ emulation mode, all types should be properly registered using `BOOST_TYPEOF_REGISTER_TYPE` and `BOOST_TYPEOF_REGISTER_TEMPLATE`, or appropriate __Boost_Typeof__ headers should be included (see __Boost_Typeof__ for more information).
+For the above examples, it is sufficient to include the __Boost_Typeof__ header that registers `std::string` (this library does not require to register `boost::function` for __Boost_Typeof__ emulation):
+
+[identity_typeof]
+
 [endsect]
 
 [endsect]
diff --git a/overloaded_function/test/identity.hpp b/overloaded_function/test/identity.hpp
index 6602152..755a6da 100644
--- a/overloaded_function/test/identity.hpp
+++ b/overloaded_function/test/identity.hpp
@@ -9,10 +9,14 @@
 #define IDENTITY_HPP_
 
 #include 
+//[identity_typeof
+#include  // No need to register `boost::function`.
+//]
 #include 
 
 //[identity_decls
-const std::string& identity_s(const std::string& x) { return x; } // As pointer.
+const std::string& identity_s(const std::string& x) // Function (as pointer).
+    { return x; }
 
 int identity_i_impl(int x) { return x; }
 int (&identity_i)(int) = identity_i_impl; // Function reference.
diff --git a/overloaded_function/test/make_decl.cpp b/overloaded_function/test/make_decl.cpp
index 7aae187..6f5cbdf 100644
--- a/overloaded_function/test/make_decl.cpp
+++ b/overloaded_function/test/make_decl.cpp
@@ -7,12 +7,11 @@
 
 #include "identity.hpp"
 #include 
-#include  // For `BOOST_AUTO`.
-#include  // No need to register `boost::function`.
+#include 
 #include 
 
 int main() {
-    //[identity_make
+    //[identity_make_decl
     BOOST_AUTO(identity, boost::make_overloaded_function(
             identity_s, identity_i, identity_d));
 

From c5a4dc3db111ec2245bc5fcf166992380cc4d030 Mon Sep 17 00:00:00 2001
From: Lorenzo Caminiti 
Date: Tue, 10 Apr 2012 21:09:36 +0000
Subject: [PATCH 14/51] Commented out some code in overloaded_function to try
 to see what breaks on Sun.

[SVN r77900]
---
 include/boost/functional/overloaded_function.hpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/boost/functional/overloaded_function.hpp b/include/boost/functional/overloaded_function.hpp
index 2ed228d..9e24e99 100644
--- a/include/boost/functional/overloaded_function.hpp
+++ b/include/boost/functional/overloaded_function.hpp
@@ -11,8 +11,9 @@
 #   ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_HPP_
 #       define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_HPP_
 
-#       include 
-#       include 
+/** @todo[Lorenzo Caminiti] Uncomment this... trying to see what breaks on Sun */
+//#       include 
+//#       include 
 #       include 
 #       include 
 #       include 

From 094516d6869f272faa985d0387d49938a8a7d2b3 Mon Sep 17 00:00:00 2001
From: Lorenzo Caminiti 
Date: Wed, 11 Apr 2012 20:55:54 +0000
Subject: [PATCH 15/51] Added some tests to figure out pp problem with
 OverloadedFunciton on Sun.

[SVN r77925]
---
 include/boost/functional/overloaded_function.hpp             | 5 ++---
 include/boost/functional/overloaded_function/detail/base.hpp | 4 +++-
 .../functional/overloaded_function/detail/function_type.hpp  | 2 +-
 overloaded_function/test/identity.hpp                        | 2 +-
 overloaded_function/test/sun_bug.cpp                         | 3 ++-
 5 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/include/boost/functional/overloaded_function.hpp b/include/boost/functional/overloaded_function.hpp
index 9e24e99..2ed228d 100644
--- a/include/boost/functional/overloaded_function.hpp
+++ b/include/boost/functional/overloaded_function.hpp
@@ -11,9 +11,8 @@
 #   ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_HPP_
 #       define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_HPP_
 
-/** @todo[Lorenzo Caminiti] Uncomment this... trying to see what breaks on Sun */
-//#       include 
-//#       include 
+#       include 
+#       include 
 #       include 
 #       include 
 #       include 
diff --git a/include/boost/functional/overloaded_function/detail/base.hpp b/include/boost/functional/overloaded_function/detail/base.hpp
index 8fd9a0a..38083ed 100644
--- a/include/boost/functional/overloaded_function/detail/base.hpp
+++ b/include/boost/functional/overloaded_function/detail/base.hpp
@@ -10,7 +10,7 @@
 #       define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_BASE_HPP_
 
 #       include 
-#       include 
+/**@todo#       include */
 #       include 
 #       include 
 #       include 
@@ -39,10 +39,12 @@ namespace boost { namespace overloaded_function_detail {
 template
 class base {}; // Empty template cannot be used directly (only its spec).
 
+/*@todo
 #       define BOOST_PP_ITERATION_PARAMS_1 \
                 (3, (0, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, \
                 "boost/functional/overloaded_function/detail/base.hpp"))
 #       include BOOST_PP_ITERATE() // Iterate over funciton arity.
+*/
 
 } } // namespace
 
diff --git a/include/boost/functional/overloaded_function/detail/function_type.hpp b/include/boost/functional/overloaded_function/detail/function_type.hpp
index 0c28607..58bf09c 100644
--- a/include/boost/functional/overloaded_function/detail/function_type.hpp
+++ b/include/boost/functional/overloaded_function/detail/function_type.hpp
@@ -16,7 +16,7 @@
 #include 
 #include 
 #include 
-#include 
+/** @todo #include */
 #include 
 #include 
 #include 
diff --git a/overloaded_function/test/identity.hpp b/overloaded_function/test/identity.hpp
index 755a6da..9b64da7 100644
--- a/overloaded_function/test/identity.hpp
+++ b/overloaded_function/test/identity.hpp
@@ -8,7 +8,7 @@
 #ifndef IDENTITY_HPP_
 #define IDENTITY_HPP_
 
-#include 
+/** @todo #include  */
 //[identity_typeof
 #include  // No need to register `boost::function`.
 //]
diff --git a/overloaded_function/test/sun_bug.cpp b/overloaded_function/test/sun_bug.cpp
index 024d4b3..ac829b2 100644
--- a/overloaded_function/test/sun_bug.cpp
+++ b/overloaded_function/test/sun_bug.cpp
@@ -1,5 +1,6 @@
 
-#include 
+/**@todo remove this test */
+#include 
 
 int main() { return 0; }
 

From 90b94a956043d8f82b626eb58ced3654a9e2bb37 Mon Sep 17 00:00:00 2001
From: Lorenzo Caminiti 
Date: Thu, 12 Apr 2012 21:12:28 +0000
Subject: [PATCH 16/51] Forcing type-of emulation on Sun. Trying to fix
 OverloadedFunction pp bug on Sun by removing SUB on iteration range (doing
 ADD on iteration index instead).

[SVN r77940]
---
 .../boost/functional/overloaded_function.hpp    | 17 ++++++++---------
 .../overloaded_function/detail/base.hpp         |  4 +---
 .../detail/function_type.hpp                    |  2 +-
 overloaded_function/test/Jamfile.v2             |  3 +++
 overloaded_function/test/identity.hpp           |  2 +-
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/boost/functional/overloaded_function.hpp b/include/boost/functional/overloaded_function.hpp
index 2ed228d..f224c4f 100644
--- a/include/boost/functional/overloaded_function.hpp
+++ b/include/boost/functional/overloaded_function.hpp
@@ -24,6 +24,7 @@
 #       include 
 #       include 
 #       include 
+#       include 
 #       include 
 #       include 
 #       include 
@@ -82,14 +83,10 @@
         BOOST_FUNCTIONAL_f_type(z, n, ~) \
     >::type
 
-// Iterate within namespace.
-#       define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_OVERLOAD_COUNT \
-            /*at least 2 func to overload 2, 3, ...*/ \
-            BOOST_PP_SUB( \
-                    BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, \
-                    2)
 #       define BOOST_PP_ITERATION_PARAMS_1 \
-            (3, (0, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_OVERLOAD_COUNT, \
+            /* at least 2 func to overload so start from 2 to MAX */ \
+            /* (cannot iterate [0, MAX-2) because error on Sun) */ \
+            (3, (2, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, \
             "boost/functional/overloaded_function.hpp"))
 #       include BOOST_PP_ITERATE() // Iterate over function arity.
 
@@ -113,8 +110,10 @@
 #elif BOOST_PP_ITERATION_DEPTH() == 1
 #   define BOOST_FUNCTIONAL_overloads \
         /* iterate as OVERLOADS, OVERLOADS-1, OVERLOADS-2, ... */ \
-        BOOST_PP_SUB(BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, \
-                BOOST_PP_FRAME_ITERATION(1))
+        /* (add 2 because iteration started from 2 to MAX) */ \
+        BOOST_PP_ADD(2, BOOST_PP_SUB( \
+                BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, \
+                BOOST_PP_FRAME_ITERATION(1)))
 #   define BOOST_FUNCTIONAL_is_tspec \
         /* if template specialization */ \
         BOOST_PP_LESS(BOOST_FUNCTIONAL_overloads, \
diff --git a/include/boost/functional/overloaded_function/detail/base.hpp b/include/boost/functional/overloaded_function/detail/base.hpp
index 38083ed..8fd9a0a 100644
--- a/include/boost/functional/overloaded_function/detail/base.hpp
+++ b/include/boost/functional/overloaded_function/detail/base.hpp
@@ -10,7 +10,7 @@
 #       define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_BASE_HPP_
 
 #       include 
-/**@todo#       include */
+#       include 
 #       include 
 #       include 
 #       include 
@@ -39,12 +39,10 @@ namespace boost { namespace overloaded_function_detail {
 template
 class base {}; // Empty template cannot be used directly (only its spec).
 
-/*@todo
 #       define BOOST_PP_ITERATION_PARAMS_1 \
                 (3, (0, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, \
                 "boost/functional/overloaded_function/detail/base.hpp"))
 #       include BOOST_PP_ITERATE() // Iterate over funciton arity.
-*/
 
 } } // namespace
 
diff --git a/include/boost/functional/overloaded_function/detail/function_type.hpp b/include/boost/functional/overloaded_function/detail/function_type.hpp
index 58bf09c..0c28607 100644
--- a/include/boost/functional/overloaded_function/detail/function_type.hpp
+++ b/include/boost/functional/overloaded_function/detail/function_type.hpp
@@ -16,7 +16,7 @@
 #include 
 #include 
 #include 
-/** @todo #include */
+#include 
 #include 
 #include 
 #include 
diff --git a/overloaded_function/test/Jamfile.v2 b/overloaded_function/test/Jamfile.v2
index 160130d..f4fab4c 100644
--- a/overloaded_function/test/Jamfile.v2
+++ b/overloaded_function/test/Jamfile.v2
@@ -7,6 +7,9 @@
 
 import testing ;
 
+# Sun does not automatically detect type-of emulation (force it).
+project : requirements sun:BOOST_TYPEOF_EMULATION ;
+
 run functor.cpp ;
 run make_decl.cpp ;
 run make_call.cpp ;
diff --git a/overloaded_function/test/identity.hpp b/overloaded_function/test/identity.hpp
index 9b64da7..5134429 100644
--- a/overloaded_function/test/identity.hpp
+++ b/overloaded_function/test/identity.hpp
@@ -8,10 +8,10 @@
 #ifndef IDENTITY_HPP_
 #define IDENTITY_HPP_
 
-/** @todo #include  */
 //[identity_typeof
 #include  // No need to register `boost::function`.
 //]
+#include 
 #include 
 
 //[identity_decls

From 6360c143f1365794026dd2272862fa6208a12f69 Mon Sep 17 00:00:00 2001
From: Lorenzo Caminiti 
Date: Fri, 13 Apr 2012 01:02:02 +0000
Subject: [PATCH 17/51] Added Lorenzo Caminiti to maintainers.txt and
 libraries.htm.

[SVN r77945]
---
 ..._OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html |  2 +-
 ...ERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html |  2 +-
 .../html/boost/make_overloaded_function.html  |  2 +-
 .../doc/html/boost/overloaded_function.html   | 22 +++++++++----------
 overloaded_function/doc/html/index.html       |  2 +-
 5 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html
index 9e12102..b59ac5a 100644
--- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html
+++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html
@@ -33,7 +33,7 @@
 
 BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX
-

Description

+

Description

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When specified by the user, this macro must be a non-negative integer number.

See: Getting Started, boost::overloaded_function.

diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html index acc24c2..9db47e1 100644 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html @@ -33,7 +33,7 @@ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX
-

Description

+

Description

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When defined by the user, this macro must be an integer number greater or equal than 2 (because at least two distinct functions need to be specified in order to define an overload).

See: Getting Started, boost::overloaded_function.

diff --git a/overloaded_function/doc/html/boost/make_overloaded_function.html b/overloaded_function/doc/html/boost/make_overloaded_function.html index 8f2b773..998264b 100644 --- a/overloaded_function/doc/html/boost/make_overloaded_function.html +++ b/overloaded_function/doc/html/boost/make_overloaded_function.html @@ -36,7 +36,7 @@ overloaded_function< __function_type__< F1 >, __function_type__< F2 >,...> make_overloaded_function(F1 f1, F2 f2, ...);
-

Description

+

Description

This function template creates and returns an overloaded_function object that overloads all the specified functions f1, f2, etc.

The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with overloaded_function. This is especially useful when the explicit type of the returned overloaded_function object does not need to be known (e.g., when used with Boost.Typeof's BOOST_AUTO, C++11 auto, or when the overloaded function object is handled using a function template parameter, see the Tutorial section).

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro.

diff --git a/overloaded_function/doc/html/boost/overloaded_function.html b/overloaded_function/doc/html/boost/overloaded_function.html index 55db374..7421832 100644 --- a/overloaded_function/doc/html/boost/overloaded_function.html +++ b/overloaded_function/doc/html/boost/overloaded_function.html @@ -35,19 +35,19 @@ class overloaded_function { public: // construct/copy/destruct - overloaded_function(const boost::function< F1 > &, + overloaded_function(const boost::function< F1 > &, const boost::function< F2 > &, ...); - // public member functions + // public member functions boost::function_traits< F1 >::result_type - operator()(typename boost::function_traits< F1 >::arg1_type, + operator()(typename boost::function_traits< F1 >::arg1_type, typename boost::function_traits< F1 >::arg2_type, ...) const; boost::function_traits< F2 >::result_type - operator()(typename boost::function_traits< F2 >::arg1_type, + operator()(typename boost::function_traits< F2 >::arg1_type, typename boost::function_traits< F2 >::arg2_type, ...) const; };
-

Description

+

Description

This function object aggregates together calls to functions of all the specified function types F1, F2, etc which must have distinct function signatures from one another.

Parameters:

@@ -67,28 +67,28 @@

At least two distinct function types must be specified (because there is nothing to overload between one or zero functions). The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro. The maximum number of function parameters for each of the specified function types is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX configuration macro.

See: Tutorial section, make_overloaded_function, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, Boost.Function.

-

+

overloaded_function public construct/copy/destruct

  1. -
    overloaded_function(const boost::function< F1 > &, 
    +
    overloaded_function(const boost::function< F1 > &, 
                         const boost::function< F2 > &, ...);
    Construct the overloaded function object.

    Any function pointer, function reference, and monomorphic function object that can be converted to a boost::function function object can be specified as parameter.

    Note: Unfortunately, it is not possible to support polymorphic function objects (as explained here).

-

-overloaded_function public member functions

+

+overloaded_function public member functions

  1. boost::function_traits< F1 >::result_type 
    -operator()(typename boost::function_traits< F1 >::arg1_type, 
    +operator()(typename boost::function_traits< F1 >::arg1_type, 
                typename boost::function_traits< F1 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 1st template parameter.

    This will in turn invoke the call operator of the 1st function passed to the constructor.

  2. boost::function_traits< F2 >::result_type 
    -operator()(typename boost::function_traits< F2 >::arg1_type, 
    +operator()(typename boost::function_traits< F2 >::arg1_type, 
                typename boost::function_traits< F2 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 2nd template parameter.

    This will in turn invoke the call operator of the 2nd function passed to the constructor.

    Note: Similar call operators are present for all specified function types F1, F2, etc (even if not exhaustively listed by this documentation).

  3. diff --git a/overloaded_function/doc/html/index.html b/overloaded_function/doc/html/index.html index c5ac2b1..c9f1f8d 100644 --- a/overloaded_function/doc/html/index.html +++ b/overloaded_function/doc/html/index.html @@ -138,7 +138,7 @@
- +

Last revised: April 10, 2012 at 20:37:20 GMT

Last revised: April 13, 2012 at 00:59:44 GMT


From 7759fa0aa091326e9d8d671274f2897011db354d Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Fri, 13 Apr 2012 19:54:16 +0000 Subject: [PATCH 18/51] Removed a test used to figure out a bug on Sun (the bug was fixed by not doing any macro expansion in the definition of the pp-iteration params macro). [SVN r77954] --- overloaded_function/test/Jamfile.v2 | 1 - overloaded_function/test/sun_bug.cpp | 6 ------ 2 files changed, 7 deletions(-) delete mode 100644 overloaded_function/test/sun_bug.cpp diff --git a/overloaded_function/test/Jamfile.v2 b/overloaded_function/test/Jamfile.v2 index f4fab4c..3871ee5 100644 --- a/overloaded_function/test/Jamfile.v2 +++ b/overloaded_function/test/Jamfile.v2 @@ -13,5 +13,4 @@ project : requirements sun:BOOST_TYPEOF_EMULATION ; run functor.cpp ; run make_decl.cpp ; run make_call.cpp ; -run sun_bug.cpp ; diff --git a/overloaded_function/test/sun_bug.cpp b/overloaded_function/test/sun_bug.cpp deleted file mode 100644 index ac829b2..0000000 --- a/overloaded_function/test/sun_bug.cpp +++ /dev/null @@ -1,6 +0,0 @@ - -/**@todo remove this test */ -#include - -int main() { return 0; } - From 5e3ec9012e0731a5dca9de8d838a5267640c767c Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 22 Apr 2012 19:45:58 +0000 Subject: [PATCH 19/51] Hash: Note about previous change. [SVN r78143] --- hash/doc/changes.qbk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hash/doc/changes.qbk b/hash/doc/changes.qbk index eb6572f..41d6511 100644 --- a/hash/doc/changes.qbk +++ b/hash/doc/changes.qbk @@ -123,4 +123,8 @@ * Avoid warning due with gcc's `-Wconversion` flag. +[h2 Boost 1.50.0] + +* Avoid gcc's `-Wfloat-equal` warning. + [endsect] From 7444eee62b6ea8f06d575d961e615ee4df17e93b Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 22 Apr 2012 19:46:28 +0000 Subject: [PATCH 20/51] Hash: Support std::array and std::tuple. Refs #6806. [SVN r78144] --- hash/doc/changes.qbk | 2 + hash/doc/ref.xml | 28 +++++ hash/test/Jamfile.v2 | 2 + hash/test/hash_map_test.cpp | 2 +- hash/test/hash_std_array_test.cpp | 103 ++++++++++++++++++ hash/test/hash_std_tuple_test.cpp | 77 +++++++++++++ .../hash/detail/container_fwd_0x.hpp | 41 +++++++ include/boost/functional/hash/extensions.hpp | 89 +++++++++++++-- 8 files changed, 333 insertions(+), 11 deletions(-) create mode 100644 hash/test/hash_std_array_test.cpp create mode 100644 hash/test/hash_std_tuple_test.cpp create mode 100644 include/boost/functional/hash/detail/container_fwd_0x.hpp diff --git a/hash/doc/changes.qbk b/hash/doc/changes.qbk index 41d6511..1673b34 100644 --- a/hash/doc/changes.qbk +++ b/hash/doc/changes.qbk @@ -126,5 +126,7 @@ [h2 Boost 1.50.0] * Avoid gcc's `-Wfloat-equal` warning. +* [@http://svn.boost.org/trac/boost/ticket/6806 Ticket 6806]: + Support `std::array` and `std::tuple` when available. [endsect] diff --git a/hash/doc/ref.xml b/hash/doc/ref.xml index 318bf85..9256e98 100644 --- a/hash/doc/ref.xml +++ b/hash/doc/ref.xml @@ -744,6 +744,25 @@ for(; first != last; ++first) std::type_index + + + std::size_t + std::array<T, N> const& + + + + + std::size_t + std::tuple<T...> + + Generally shouldn't be called directly by users, instead they should use boost::hash, boost::hash_range @@ -810,6 +829,7 @@ for(; first != last; ++first) std::multiset<K, C, A>, std::map<K, T, C, A>, std::multimap<K, T, C, A> + std::array<T, N> hash_range(val.begin(), val.end()) @@ -818,6 +838,14 @@ for(; first != last; ++first) size_t seed = 0; hash_combine(seed, val.first); hash_combine(seed, val.second); +return seed; + + + std::tuple<T...> + size_t seed = 0; +hash_combine(seed, get<0>(val)); +hash_combine(seed, get<1>(val)); +// .... return seed; diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index cf64ece..af24329 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -40,6 +40,8 @@ test-suite functional/hash [ run hash_map_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] [ run hash_complex_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] [ run hash_type_index_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] + [ run hash_std_array_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] + [ run hash_std_tuple_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] [ run link_test.cpp link_test_2.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] [ run link_ext_test.cpp link_no_ext_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] [ run extensions_hpp_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] diff --git a/hash/test/hash_map_test.cpp b/hash/test/hash_map_test.cpp index 2f813c3..7e117c7 100644 --- a/hash/test/hash_map_test.cpp +++ b/hash/test/hash_map_test.cpp @@ -27,7 +27,7 @@ using std::multimap; #define CONTAINER_TYPE multimap #include "./hash_map_test.hpp" -#endif // TEST_EXTENSTIONS +#endif // TEST_EXTENSIONS int main() { diff --git a/hash/test/hash_std_array_test.cpp b/hash/test/hash_std_array_test.cpp new file mode 100644 index 0000000..5e8a3d4 --- /dev/null +++ b/hash/test/hash_std_array_test.cpp @@ -0,0 +1,103 @@ + +// Copyright 2012 Daniel James. +// 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include +# else +# include +# endif +#endif + +#include +#include + +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_0X_HDR_ARRAY) +#define TEST_ARRAY +#include +#include +#endif + +#ifdef TEST_ARRAY + +template +void array_tests(T const& v) { + boost::hash hf; + for(typename T::const_iterator i = v.begin(); i != v.end(); ++i) { + for(typename T::const_iterator j = v.begin(); j != v.end(); ++j) { + if (i != j) + BOOST_TEST(hf(*i) != hf(*j)); + else + BOOST_TEST(hf(*i) == hf(*j)); + } + } +} + +void empty_array_test() { +/* + boost::hash > empty_array_hash; + std::array empty_array; + BOOST_TEST(empty_array_hash(empty_array) == boost::hash_value(empty_array)); +*/ +} + +void int_1_array_test() +{ + std::vector > arrays; + std::array val; + val[0] = 0; + arrays.emplace_back(val); + val[0] = 1; + arrays.emplace_back(val); + val[0] = 2; + arrays.emplace_back(val); + array_tests(arrays); +} + +void string_1_array_test() +{ + std::vector > arrays; + std::array val; + arrays.emplace_back(val); + val[0] = "one"; + arrays.emplace_back(val); + val[0] = "two"; + arrays.emplace_back(val); + array_tests(arrays); +} + +void string_3_array_test() +{ + std::vector > arrays; + std::array val; + arrays.emplace_back(val); + val[0] = "one"; + arrays.emplace_back(val); + val[0] = ""; val[1] = "one"; val[2] = ""; + arrays.emplace_back(val); + val[0] = ""; val[1] = ""; val[2] = "one"; + arrays.emplace_back(val); + val[0] = "one"; val[1] = "one"; val[2] = "one"; + arrays.emplace_back(val); + val[0] = "one"; val[1] = "two"; val[2] = "three"; + arrays.emplace_back(val); + array_tests(arrays); +} + +#endif // TEST_ARRAY + +int main() +{ +#ifdef TEST_ARRAY + empty_array_test(); + int_1_array_test(); + string_1_array_test(); + string_3_array_test(); +#endif + + return boost::report_errors(); +} diff --git a/hash/test/hash_std_tuple_test.cpp b/hash/test/hash_std_tuple_test.cpp new file mode 100644 index 0000000..84aae75 --- /dev/null +++ b/hash/test/hash_std_tuple_test.cpp @@ -0,0 +1,77 @@ + +// Copyright 2012 Daniel James. +// 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include +# else +# include +# endif +#endif + +#include +#include + +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_0X_HDR_TUPLE) +#define TEST_TUPLE +#include +#include +#endif + +#ifdef TEST_TUPLE + +template +void tuple_tests(T const& v) { + boost::hash hf; + for(typename T::const_iterator i = v.begin(); i != v.end(); ++i) { + for(typename T::const_iterator j = v.begin(); j != v.end(); ++j) { + if (i != j) + BOOST_TEST(hf(*i) != hf(*j)); + else + BOOST_TEST(hf(*i) == hf(*j)); + } + } +} + +void empty_tuple_test() { + boost::hash > empty_tuple_hash; + std::tuple<> empty_tuple; + BOOST_TEST(empty_tuple_hash(empty_tuple) == boost::hash_value(empty_tuple)); +} + +void int_tuple_test() { + std::vector > int_tuples; + int_tuples.push_back(std::make_tuple(0)); + int_tuples.push_back(std::make_tuple(1)); + int_tuples.push_back(std::make_tuple(2)); + tuple_tests(int_tuples); +} + +void int_string_tuple_test() { + std::vector > int_string_tuples; + int_string_tuples.push_back(std::make_tuple(0, "zero")); + int_string_tuples.push_back(std::make_tuple(1, "one")); + int_string_tuples.push_back(std::make_tuple(2, "two")); + int_string_tuples.push_back(std::make_tuple(0, "one")); + int_string_tuples.push_back(std::make_tuple(1, "zero")); + int_string_tuples.push_back(std::make_tuple(0, "")); + int_string_tuples.push_back(std::make_tuple(1, "")); + tuple_tests(int_string_tuples); +} + +#endif // TEST_TUPLE + +int main() +{ +#ifdef TEST_TUPLE + empty_tuple_test(); + int_tuple_test(); + int_string_tuple_test(); +#endif + + return boost::report_errors(); +} diff --git a/include/boost/functional/hash/detail/container_fwd_0x.hpp b/include/boost/functional/hash/detail/container_fwd_0x.hpp new file mode 100644 index 0000000..566f2af --- /dev/null +++ b/include/boost/functional/hash/detail/container_fwd_0x.hpp @@ -0,0 +1,41 @@ + +// Copyright 2012 Daniel James. +// 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(BOOST_DETAIL_CONTAINER_FWD_0X_HPP) +#define BOOST_DETAIL_CONTAINER_FWD_0X_HPP + +#include + +// std::array + +#if !defined(BOOST_NO_0X_HDR_ARRAY) + // Don't forward declare std::array for Dinkumware, as it seems to be + // just 'using std::tr1::array'. +# if (defined(BOOST_DETAIL_NO_CONTAINER_FWD) && \ + !defined(BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD)) || \ + (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER) +# include +# else +namespace std { + template class array; +} +# endif +#endif + +// std::tuple + +#if !defined(BOOST_NO_0X_HDR_TUPLE) +# if (defined(BOOST_DETAIL_NO_CONTAINER_FWD) && \ + !defined(BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD)) || \ + defined(BOOST_NO_VARIADIC_TEMPLATES) +# include +# else +namespace std { + template class tuple; +} +# endif +#endif + +#endif diff --git a/include/boost/functional/hash/extensions.hpp b/include/boost/functional/hash/extensions.hpp index 3c587a3..1d873ed 100644 --- a/include/boost/functional/hash/extensions.hpp +++ b/include/boost/functional/hash/extensions.hpp @@ -14,7 +14,11 @@ #define BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP #include -#include +#include +#include +#include +#include +#include #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once @@ -54,51 +58,51 @@ namespace boost std::size_t hash_value(std::pair const& v) { std::size_t seed = 0; - hash_combine(seed, v.first); - hash_combine(seed, v.second); + boost::hash_combine(seed, v.first); + boost::hash_combine(seed, v.second); return seed; } template std::size_t hash_value(std::vector const& v) { - return hash_range(v.begin(), v.end()); + return boost::hash_range(v.begin(), v.end()); } template std::size_t hash_value(std::list const& v) { - return hash_range(v.begin(), v.end()); + return boost::hash_range(v.begin(), v.end()); } template std::size_t hash_value(std::deque const& v) { - return hash_range(v.begin(), v.end()); + return boost::hash_range(v.begin(), v.end()); } template std::size_t hash_value(std::set const& v) { - return hash_range(v.begin(), v.end()); + return boost::hash_range(v.begin(), v.end()); } template std::size_t hash_value(std::multiset const& v) { - return hash_range(v.begin(), v.end()); + return boost::hash_range(v.begin(), v.end()); } template std::size_t hash_value(std::map const& v) { - return hash_range(v.begin(), v.end()); + return boost::hash_range(v.begin(), v.end()); } template std::size_t hash_value(std::multimap const& v) { - return hash_range(v.begin(), v.end()); + return boost::hash_range(v.begin(), v.end()); } template @@ -110,6 +114,71 @@ namespace boost return seed; } +#if !defined(BOOST_NO_0X_HDR_ARRAY) + template + std::size_t hash_value(std::array const& v) + { + return boost::hash_range(v.begin(), v.end()); + } +#endif + +#if !defined(BOOST_NO_0X_HDR_TUPLE) + namespace hash_detail { + template + inline typename boost::enable_if_c<(I == std::tuple_size::value), + void>::type + hash_combine_tuple(std::size_t&, T const&) + { + } + + template + inline typename boost::enable_if_c<(I < std::tuple_size::value), + void>::type + hash_combine_tuple(std::size_t& seed, T const& v) + { + boost::hash_combine(seed, std::get(v)); + boost::hash_detail::hash_combine_tuple(seed, v); + } + + template + inline std::size_t hash_tuple(T const& v) + { + std::size_t seed = 0; + boost::hash_detail::hash_combine_tuple<0>(seed, v); + return seed; + } + } + +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) + template + inline std::size_t hash_value(std::tuple const& v) + { + return boost::hash_detail::hash_tuple(v); + } +#else + + inline std::size_t hash_value(std::tuple<> const& v) + { + return boost::hash_detail::hash_tuple(v); + } + +# define BOOST_HASH_TUPLE_F(z, n, _) \ + template< \ + BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \ + > \ + inline std::size_t hash_value(std::tuple< \ + BOOST_PP_ENUM_PARAMS_Z(z, n, A) \ + > const& v) \ + { \ + return boost::hash_detail::hash_tuple(v); \ + } + + BOOST_PP_REPEAT_FROM_TO(1, 11, BOOST_HASH_TUPLE_F, _) +# undef BOOST_HASH_TUPLE_F +#endif + +#endif + // // call_hash_impl // From 8f9ad424a9abe6e0c10babbe7468e1b8526ef7ca Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 22 Apr 2012 19:49:41 +0000 Subject: [PATCH 21/51] Hash: Missing comma. [SVN r78145] --- hash/doc/ref.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hash/doc/ref.xml b/hash/doc/ref.xml index 9256e98..fa29fcd 100644 --- a/hash/doc/ref.xml +++ b/hash/doc/ref.xml @@ -828,7 +828,7 @@ for(; first != last; ++first) std::set<K, C, A>, std::multiset<K, C, A>, std::map<K, T, C, A>, - std::multimap<K, T, C, A> + std::multimap<K, T, C, A>, std::array<T, N> hash_range(val.begin(), val.end()) From dfa8524f2f4225bb33f9e91763c32e6f0f6c5eb2 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 23 Apr 2012 20:49:30 +0000 Subject: [PATCH 22/51] Hash: Some formatting. [SVN r78164] --- include/boost/functional/hash/extensions.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/boost/functional/hash/extensions.hpp b/include/boost/functional/hash/extensions.hpp index 1d873ed..e61c2f3 100644 --- a/include/boost/functional/hash/extensions.hpp +++ b/include/boost/functional/hash/extensions.hpp @@ -162,15 +162,15 @@ namespace boost return boost::hash_detail::hash_tuple(v); } -# define BOOST_HASH_TUPLE_F(z, n, _) \ - template< \ - BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \ - > \ - inline std::size_t hash_value(std::tuple< \ - BOOST_PP_ENUM_PARAMS_Z(z, n, A) \ - > const& v) \ - { \ - return boost::hash_detail::hash_tuple(v); \ +# define BOOST_HASH_TUPLE_F(z, n, _) \ + template< \ + BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \ + > \ + inline std::size_t hash_value(std::tuple< \ + BOOST_PP_ENUM_PARAMS_Z(z, n, A) \ + > const& v) \ + { \ + return boost::hash_detail::hash_tuple(v); \ } BOOST_PP_REPEAT_FROM_TO(1, 11, BOOST_HASH_TUPLE_F, _) From 32fe58c6d74c93f373c1483179088b32b15ebaf3 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 23 Apr 2012 20:51:21 +0000 Subject: [PATCH 23/51] Hash: fix tests for older C++0x libraries. [SVN r78165] --- hash/test/hash_std_array_test.cpp | 24 ++++++++++++------------ hash/test/hash_std_tuple_test.cpp | 14 +++++++------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/hash/test/hash_std_array_test.cpp b/hash/test/hash_std_array_test.cpp index 5e8a3d4..540b676 100644 --- a/hash/test/hash_std_array_test.cpp +++ b/hash/test/hash_std_array_test.cpp @@ -50,11 +50,11 @@ void int_1_array_test() std::vector > arrays; std::array val; val[0] = 0; - arrays.emplace_back(val); + arrays.push_back(val); val[0] = 1; - arrays.emplace_back(val); + arrays.push_back(val); val[0] = 2; - arrays.emplace_back(val); + arrays.push_back(val); array_tests(arrays); } @@ -62,11 +62,11 @@ void string_1_array_test() { std::vector > arrays; std::array val; - arrays.emplace_back(val); + arrays.push_back(val); val[0] = "one"; - arrays.emplace_back(val); + arrays.push_back(val); val[0] = "two"; - arrays.emplace_back(val); + arrays.push_back(val); array_tests(arrays); } @@ -74,17 +74,17 @@ void string_3_array_test() { std::vector > arrays; std::array val; - arrays.emplace_back(val); + arrays.push_back(val); val[0] = "one"; - arrays.emplace_back(val); + arrays.push_back(val); val[0] = ""; val[1] = "one"; val[2] = ""; - arrays.emplace_back(val); + arrays.push_back(val); val[0] = ""; val[1] = ""; val[2] = "one"; - arrays.emplace_back(val); + arrays.push_back(val); val[0] = "one"; val[1] = "one"; val[2] = "one"; - arrays.emplace_back(val); + arrays.push_back(val); val[0] = "one"; val[1] = "two"; val[2] = "three"; - arrays.emplace_back(val); + arrays.push_back(val); array_tests(arrays); } diff --git a/hash/test/hash_std_tuple_test.cpp b/hash/test/hash_std_tuple_test.cpp index 84aae75..15ef483 100644 --- a/hash/test/hash_std_tuple_test.cpp +++ b/hash/test/hash_std_tuple_test.cpp @@ -53,13 +53,13 @@ void int_tuple_test() { void int_string_tuple_test() { std::vector > int_string_tuples; - int_string_tuples.push_back(std::make_tuple(0, "zero")); - int_string_tuples.push_back(std::make_tuple(1, "one")); - int_string_tuples.push_back(std::make_tuple(2, "two")); - int_string_tuples.push_back(std::make_tuple(0, "one")); - int_string_tuples.push_back(std::make_tuple(1, "zero")); - int_string_tuples.push_back(std::make_tuple(0, "")); - int_string_tuples.push_back(std::make_tuple(1, "")); + int_string_tuples.push_back(std::make_tuple(0, std::string("zero"))); + int_string_tuples.push_back(std::make_tuple(1, std::string("one"))); + int_string_tuples.push_back(std::make_tuple(2, std::string("two"))); + int_string_tuples.push_back(std::make_tuple(0, std::string("one"))); + int_string_tuples.push_back(std::make_tuple(1, std::string("zero"))); + int_string_tuples.push_back(std::make_tuple(0, std::string(""))); + int_string_tuples.push_back(std::make_tuple(1, std::string(""))); tuple_tests(int_string_tuples); } From 6e74c243ed7da696ae40bfe4e02da321e37f77a1 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Sat, 28 Apr 2012 02:16:51 +0000 Subject: [PATCH 24/51] Replacing old docs. [SVN r78232] --- ..._OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html | 54 ----- ...ERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html | 54 ----- .../html/boost/make_overloaded_function.html | 60 ----- .../doc/html/boost/overloaded_function.html | 112 --------- .../Acknowledgments.html | 60 ----- .../Getting_Started.html | 95 -------- .../Tutorial.html | 228 ------------------ overloaded_function/doc/html/index.html | 147 ----------- overloaded_function/doc/html/reference.html | 66 ----- 9 files changed, 876 deletions(-) delete mode 100644 overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html delete mode 100644 overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html delete mode 100644 overloaded_function/doc/html/boost/make_overloaded_function.html delete mode 100644 overloaded_function/doc/html/boost/overloaded_function.html delete mode 100644 overloaded_function/doc/html/boost_functional_overloadedfunction/Acknowledgments.html delete mode 100644 overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html delete mode 100644 overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html delete mode 100644 overloaded_function/doc/html/index.html delete mode 100644 overloaded_function/doc/html/reference.html diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html deleted file mode 100644 index b59ac5a..0000000 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html +++ /dev/null @@ -1,54 +0,0 @@ - - - -Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX - - - - - - - - - - - - - - - -
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-
-
-

Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX

-

BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX — Specify the maximum number of arguments of the functions being overloaded.

-
-

Synopsis

-
// In header: <boost/functional/overloaded_function/config.hpp>
-
-BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX
-
-

Description

-

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When specified by the user, this macro must be a non-negative integer number.

-

See: Getting Started, boost::overloaded_function.

-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html deleted file mode 100644 index 9db47e1..0000000 --- a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html +++ /dev/null @@ -1,54 +0,0 @@ - - - -Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX - - - - - - - - - - - - - - - -
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-
-
-

Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX

-

BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX — Specify the maximum number of functions that can be overloaded.

-
-

Synopsis

-
// In header: <boost/functional/overloaded_function/config.hpp>
-
-BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX
-
-

Description

-

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When defined by the user, this macro must be an integer number greater or equal than 2 (because at least two distinct functions need to be specified in order to define an overload).

-

See: Getting Started, boost::overloaded_function.

-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/overloaded_function/doc/html/boost/make_overloaded_function.html b/overloaded_function/doc/html/boost/make_overloaded_function.html deleted file mode 100644 index 998264b..0000000 --- a/overloaded_function/doc/html/boost/make_overloaded_function.html +++ /dev/null @@ -1,60 +0,0 @@ - - - -Function template make_overloaded_function - - - - - - - - - - - - - - - -
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-
-
-

Function template make_overloaded_function

-

boost::make_overloaded_function — Make an overloaded function object without explicitly specifying the function types.

-
-

Synopsis

-
// In header: <boost/functional/overloaded_function.hpp>
-
-
-template<typename F1, typename F2, ... > 
-  overloaded_function< __function_type__< F1 >, __function_type__< F2 >,...> 
-  make_overloaded_function(F1 f1, F2 f2, ...);
-
-

Description

-

This function template creates and returns an overloaded_function object that overloads all the specified functions f1, f2, etc.

-

The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with overloaded_function. This is especially useful when the explicit type of the returned overloaded_function object does not need to be known (e.g., when used with Boost.Typeof's BOOST_AUTO, C++11 auto, or when the overloaded function object is handled using a function template parameter, see the Tutorial section).

-

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro.

-

Note: In this documentation, __function_type__ is a placeholder for a symbol that is specific to the implementation of this library.

-

See: Tutorial section, overloaded_function, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.

-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/overloaded_function/doc/html/boost/overloaded_function.html b/overloaded_function/doc/html/boost/overloaded_function.html deleted file mode 100644 index 7421832..0000000 --- a/overloaded_function/doc/html/boost/overloaded_function.html +++ /dev/null @@ -1,112 +0,0 @@ - - - -Class template overloaded_function - - - - - - - - - - - - - - - -
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-
-
-

Class template overloaded_function

-

boost::overloaded_function — Function object to overload functions with distinct signatures.

-
-

Synopsis

-
// In header: <boost/functional/overloaded_function.hpp>
-
-template<typename F1, typename F2, ... > 
-class overloaded_function {
-public:
-  // construct/copy/destruct
-  overloaded_function(const boost::function< F1 > &, 
-                      const boost::function< F2 > &, ...);
-
-  // public member functions
-  boost::function_traits< F1 >::result_type 
-  operator()(typename boost::function_traits< F1 >::arg1_type, 
-             typename boost::function_traits< F1 >::arg2_type, ...) const;
-  boost::function_traits< F2 >::result_type 
-  operator()(typename boost::function_traits< F2 >::arg1_type, 
-             typename boost::function_traits< F2 >::arg2_type, ...) const;
-};
-
-

Description

-

This function object aggregates together calls to functions of all the specified function types F1, F2, etc which must have distinct function signatures from one another.

-

Parameters:

-
---- - - - - -
FiEach function type must be specified using the following syntax (which is Boost.Function's preferred syntax):
    result_type (argument1_type, argumgnet2_type, ...)
-
-

-

-

In some cases, the make_overloaded_function function template can be useful to construct an overloaded function object without explicitly specifying the function types.

-

At least two distinct function types must be specified (because there is nothing to overload between one or zero functions). The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro. The maximum number of function parameters for each of the specified function types is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX configuration macro.

-

See: Tutorial section, make_overloaded_function, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, Boost.Function.

-
-

-overloaded_function - public - construct/copy/destruct

-
  1. -
    overloaded_function(const boost::function< F1 > &, 
    -                    const boost::function< F2 > &, ...);
    Construct the overloaded function object.

    Any function pointer, function reference, and monomorphic function object that can be converted to a boost::function function object can be specified as parameter.

    -

    Note: Unfortunately, it is not possible to support polymorphic function objects (as explained here).

    -
-
-
-

-overloaded_function public member functions

-
    -
  1. -
    boost::function_traits< F1 >::result_type 
    -operator()(typename boost::function_traits< F1 >::arg1_type, 
    -           typename boost::function_traits< F1 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 1st template parameter.

    This will in turn invoke the call operator of the 1st function passed to the constructor.

    -
  2. -
  3. -
    boost::function_traits< F2 >::result_type 
    -operator()(typename boost::function_traits< F2 >::arg1_type, 
    -           typename boost::function_traits< F2 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 2nd template parameter.

    This will in turn invoke the call operator of the 2nd function passed to the constructor.

    -

    Note: Similar call operators are present for all specified function types F1, F2, etc (even if not exhaustively listed by this documentation).

    -
  4. -
-
-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/Acknowledgments.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/Acknowledgments.html deleted file mode 100644 index f03dd92..0000000 --- a/overloaded_function/doc/html/boost_functional_overloadedfunction/Acknowledgments.html +++ /dev/null @@ -1,60 +0,0 @@ - - - -Acknowledgments - - - - - - - - - - - - - - -
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
-
-
-PrevUpHome -
-
- -

- Many thanks to Mathias Gaunard for suggesting to implement boost::overloaded_function - and for some sample code. -

-

- Thanks to John Bytheway for suggesting to implement boost::make_overloaded_function. -

-

- Thanks to Nathan Ridge for suggestions on how to implement boost::make_overloaded_function. -

-

- Thanks to Robert Stewart for commenting on the library name. -

-

- Many thanks to the entire Boost community - and mailing list for providing valuable comments about this library and great - insights on the C++ programming language. -

-
- - - -
-
-
-PrevUpHome -
- - diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html deleted file mode 100644 index 6ac82c8..0000000 --- a/overloaded_function/doc/html/boost_functional_overloadedfunction/Getting_Started.html +++ /dev/null @@ -1,95 +0,0 @@ - - - -Getting Started - - - - - - - - - - - - - - - -
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
- - -

- This section explains how to setup a system to use this library. -

-
- -

- The authors originally developed and tested this library on: -

-
    -
  1. - GNU Compiler Collection (GCC) C++ 4.5.3 (with and without C++11 features - enabled -std=c++0x) - on Cygwin. -
  2. -
  3. - Miscrosoft Visual C++ (MSVC) 8.0 on Windows 7. -
  4. -
-

- See the library regressions - test results for detailed information on supported compilers and - platforms. Check the library regression test Jamfile.v2 - for any special configuration that might be required for a specific compiler. -

-
-
- -

- This library is composed of header files only. Therefore there is no pre-compiled - object file which needs to be installed. Programmers can simply instruct - the compiler where to find the library header files (-I option on GCC, /I option on MSVC, etc) and compile code - using the library. -

-

- The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX - configuration macro. The maximum number of function parameters for each of - the specified function type is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX - configuration macro. All configuration macros have appropriate default values - when they are left undefined. -

-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html deleted file mode 100644 index 8211939..0000000 --- a/overloaded_function/doc/html/boost_functional_overloadedfunction/Tutorial.html +++ /dev/null @@ -1,228 +0,0 @@ - - - -Tutorial - - - - - - - - - - - - - - - -
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
- - -

- This section explains how to use this library. -

-
- -

- Consider the following functions which have distinct signatures: -

-

-

-
const std::string& identity_s(const std::string& x) // Function (as pointer).
-    { return x; }
-
-int identity_i_impl(int x) { return x; }
-int (&identity_i)(int) = identity_i_impl; // Function reference.
-
-double identity_d_impl(double x) { return x; }
-boost::function<double (double)> identity_d = identity_d_impl; // Functor.
-
-

-

-

- This library header boost/functional/overloaded_function.hpp - provides a boost::overloaded_function - class template that creates a single overloaded function object that can - be used to call the specified functions instead of using the separate function - names (see also functor.cpp - and identity.hpp): -

-

-

-
boost::overloaded_function<
-      const std::string& (const std::string&)
-    , int (int)
-    , double (double)
-> identity(identity_s, identity_i, identity_d);
-
-// All calls via single `identity` function.
-BOOST_TEST(identity("abc") == "abc");
-BOOST_TEST(identity(123) == 123);
-BOOST_TEST(identity(1.23) == 1.23);
-
-

-

-

- Note how each function type is passed as a template parameter of boost::overloaded_function using - the following syntax (this is Boost.Function's - preferred syntax): -

-
result-type (argument1-type, argument2-type, ...)
-
-

- Then the relative function pointers, function references, or monomorphic - function objects are passed to the boost::overloaded_function - constructor matching the order of the specified template parameters. [2] In the above example, identity_s - is passed as a function pointer (the function address is automatically taken - from the function name by the compiler), identity_i - as a function reference, and identity_d - as a function object. -

-

- All specified function types must have distinct parameters from one another - (so the overloaded calls can be resolved by this library). [3] In order to create an overloaded function object, it is necessary - to specify at least two function types (because there is nothing to overload - between one or zero functions). -

-
-
- -

- For convenience, this library also provides the boost::make_overloaded_function - function template which allows to create the overloaded function object without - explicitly specifying the function types. The function types are automatically - deduced from the specified functions and the appropriate boost::overloaded_function - instantiation is returned by boost::make_overloaded_function. -

-

- The boost::make_overloaded_function - function template can be useful when used together with Boost.Typeof's - BOOST_AUTO (or C++11 auto). For example (see also make_decl.cpp - and identity.hpp): -

-

-

-
BOOST_AUTO(identity, boost::make_overloaded_function(
-        identity_s, identity_i, identity_d));
-
-BOOST_TEST(identity("abc") == "abc");
-BOOST_TEST(identity(123) == 123);
-BOOST_TEST(identity(1.23) == 1.23);
-
-

-

-

- Note how the overloaded function object identity - has been created specifying only the functions identity_s, - identity_i, identity_d and without specifying the function - types const std::string& (const - std::string&), - int (int), and - double (double) as - required instead by boost::overloaded_function. - Therefore, boost::make_overloaded_function - provides a more concise syntax in this context when compared with boost::overloaded_function. -

-

- Another case where boost::make_overloaded_function - can be useful is when the overloaded function object is passed to a function - template which can hold the specific boost::overloaded_function - type using a template parameter. For example (see also make_call.cpp - and identity.hpp): -

-

-

-
template<typename F>
-void check(F identity) {
-    BOOST_TEST(identity("abc") == "abc");
-    BOOST_TEST(identity(123) == 123);
-    BOOST_TEST(identity(1.23) == 1.23);
-}
-
-

-

-

-

-
check(boost::make_overloaded_function(identity_s, identity_i, identity_d));
-
-

-

-

- The library implementation of boost::make_overloaded_function - uses Boost.Typeof - to automatically deduce some of the function types. In order to compile code - in Boost.Typeof - emulation mode, all types should be properly registered using BOOST_TYPEOF_REGISTER_TYPE and BOOST_TYPEOF_REGISTER_TEMPLATE, or appropriate - Boost.Typeof headers - should be included (see Boost.Typeof - for more information). For the above examples, it is sufficient to include - the Boost.Typeof - header that registers std::string - (this library does not require to register boost::function - for Boost.Typeof - emulation): -

-

-

-
#include <boost/typeof/std/string.hpp> // No need to register `boost::function`.
-
-

-

-
-
-

-

[2] - Function pointers are of the form result-type (*)(argument1-type, ...) (the - C++ compiler is usually able to automatically promote a function name to - a function pointer in a context where a function pointer is expected even - if the function name is not prefixed by &). - Function references are of the form result-type (&)(argument1-type, ...). - Function types are of the form result-type (argument1-type, ...) (note - how they lack of both * and - & when compared to function - pointers and function references). Finally, monomorphic function objects - are instances of classes with a non-template call operator of the form - result-type operator()(argument1-type, ...). - Unfortunately, it is not possible to support polymorphic function objects - (see http://lists.boost.org/Archives/boost/2012/03/191744.php). -

-

[3] - Note that in C++ the function result type is not used for overload resolution - (to avoid making the overload resolution context dependent). Therefore, - at least one of the function parameters must be distinct for each specified - function type. -

-
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/overloaded_function/doc/html/index.html b/overloaded_function/doc/html/index.html deleted file mode 100644 index c9f1f8d..0000000 --- a/overloaded_function/doc/html/index.html +++ /dev/null @@ -1,147 +0,0 @@ - - - -Chapter 1. Boost.Functional/OverloadedFunction 1.0.0 - - - - - - - - - - - - - -
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
-
-
Next
-
-
-

-Chapter 1. Boost.Functional/OverloadedFunction 1.0.0

-

-Lorenzo Caminiti -

-
-
-

- 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) -

-
-
- -

- This library allows to overload different functions into a single function object. -

-
- -

- Consider the following functions which have distinct signatures: -

-

-

-
const std::string& identity_s(const std::string& x) // Function (as pointer).
-    { return x; }
-
-int identity_i_impl(int x) { return x; }
-int (&identity_i)(int) = identity_i_impl; // Function reference.
-
-double identity_d_impl(double x) { return x; }
-boost::function<double (double)> identity_d = identity_d_impl; // Functor.
-
-

-

-

- Instead of calling them using their separate names (here BOOST_TEST - is equivalent to assert): - [1] -

-

-

-
BOOST_TEST(identity_s("abc") == "abc");
-BOOST_TEST(identity_i(123) == 123);
-BOOST_TEST(identity_d(1.23) == 1.23);
-
-

-

-

- It is possible to use this library to create a single overloaded - function object (or functor) - named identity that aggregates - together the calls to the specific functions (see also functor.cpp - and identity.hpp): -

-

-

-
boost::overloaded_function<
-      const std::string& (const std::string&)
-    , int (int)
-    , double (double)
-> identity(identity_s, identity_i, identity_d);
-
-// All calls via single `identity` function.
-BOOST_TEST(identity("abc") == "abc");
-BOOST_TEST(identity(123) == 123);
-BOOST_TEST(identity(1.23) == 1.23);
-
-

-

-

- Note how the functions are called via a single overloaded function object - identity instead of using their - different names identity_s, - identity_i, and identity_d. -

-
-
-

-

[1] - In most of the examples presented in this documentation, the Boost.Detail/LightweightTest - (boost/detail/lightweight_test.hpp) macro BOOST_TEST is used to check correctness - conditions (conceptually similar to assert). - A failure of the checked condition does not abort the execution of the program, - it will instead make boost::report_errors - return a non-zero program exit code. Using Boost.Detail/LightweightTest allows - to add the examples to the library regression tests so to make sure that - they always compile and run correctly. -

-
-
- - - -

Last revised: April 13, 2012 at 00:59:44 GMT

-
-
Next
- - diff --git a/overloaded_function/doc/html/reference.html b/overloaded_function/doc/html/reference.html deleted file mode 100644 index 3fcf6f5..0000000 --- a/overloaded_function/doc/html/reference.html +++ /dev/null @@ -1,66 +0,0 @@ - - - -Reference - - - - - - - - - - - - - - - -
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
-
-
-PrevUpHomeNext -
-
-

-Reference

- -
- -

Overload distinct function pointers, function references, and monomorphic function objects into a single function object.

-
namespace boost {
-  template<typename F1, typename F2, ... > class overloaded_function;
-  template<typename F1, typename F2, ... > 
-    overloaded_function< __function_type__< F1 >, __function_type__< F2 >,...> 
-    make_overloaded_function(F1, F2, ...);
-}
-
- -
- - - -
-
-
-PrevUpHomeNext -
- - From 37f91f600d58f5b0f1d159950a52197a42b6dae5 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Sat, 28 Apr 2012 02:21:15 +0000 Subject: [PATCH 25/51] Using all lower case section IDs. [SVN r78233] --- .../boost/functional/overloaded_function.hpp | 18 +- .../functional/overloaded_function/config.hpp | 16 +- overloaded_function/doc/Jamfile.v2 | 2 +- ..._OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html | 54 +++++ ...ERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html | 54 +++++ .../html/boost/make_overloaded_function.html | 60 +++++ .../doc/html/boost/overloaded_function.html | 112 +++++++++ .../acknowledgments.html | 60 +++++ .../getting_started.html | 95 ++++++++ .../tutorial.html | 228 ++++++++++++++++++ overloaded_function/doc/html/index.html | 147 +++++++++++ overloaded_function/doc/html/reference.html | 66 +++++ .../doc/overloaded_function.qbk | 14 +- 13 files changed, 898 insertions(+), 28 deletions(-) create mode 100644 overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html create mode 100644 overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html create mode 100644 overloaded_function/doc/html/boost/make_overloaded_function.html create mode 100644 overloaded_function/doc/html/boost/overloaded_function.html create mode 100644 overloaded_function/doc/html/boost_functional_overloadedfunction/acknowledgments.html create mode 100644 overloaded_function/doc/html/boost_functional_overloadedfunction/getting_started.html create mode 100644 overloaded_function/doc/html/boost_functional_overloadedfunction/tutorial.html create mode 100644 overloaded_function/doc/html/index.html create mode 100644 overloaded_function/doc/html/reference.html diff --git a/include/boost/functional/overloaded_function.hpp b/include/boost/functional/overloaded_function.hpp index f224c4f..83fe4b3 100644 --- a/include/boost/functional/overloaded_function.hpp +++ b/include/boost/functional/overloaded_function.hpp @@ -222,12 +222,10 @@ types is given by the @RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX} configuration macro. -@See - @RefSect{Tutorial} section, - @RefFunc{make_overloaded_function}, - @RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}, - @RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX}, - Boost.Function. +@See @RefSect{tutorial, Tutorial} section, @RefFunc{make_overloaded_function}, +@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}, +@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX}, +Boost.Function. */ template class overloaded_function { @@ -290,7 +288,7 @@ This is especially useful when the explicit type of the returned @RefClass{overloaded_function} object does not need to be known (e.g., when used with Boost.Typeof's BOOST_AUTO, C++11 auto, or when the overloaded function object is handled using a function template parameter, see -the @RefSect{Tutorial} section). +the @RefSect{tutorial, Tutorial} section). The maximum number of functions to overload is given by the @RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX} @@ -299,10 +297,8 @@ configuration macro. @Note In this documentation, __function_type__ is a placeholder for a symbol that is specific to the implementation of this library. -@See - @RefSect{Tutorial} section, - @RefClass{overloaded_function}, - @RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}. +@See @RefSect{tutorial, Tutorial} section, @RefClass{overloaded_function}, +@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}. */ template overloaded_function< diff --git a/include/boost/functional/overloaded_function/config.hpp b/include/boost/functional/overloaded_function/config.hpp index 17bd825..2f5d9e1 100644 --- a/include/boost/functional/overloaded_function/config.hpp +++ b/include/boost/functional/overloaded_function/config.hpp @@ -20,12 +20,11 @@ If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When specified by the user, this macro must be a non-negative integer number. -@See - @RefSectId{Getting_Started, Getting Started}, - @RefClass{boost::overloaded_function}. +@See @RefSect{getting_started, Getting Started}, +@RefClass{boost::overloaded_function}. */ #ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX -#define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX 5 +# define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX 5 #endif /** @@ -37,15 +36,14 @@ When defined by the user, this macro must be an integer number greater or equal than 2 (because at least two distinct functions need to be specified in order to define an overload). -@See - @RefSectId{Getting_Started, Getting Started}, - @RefClass{boost::overloaded_function}. +@See @RefSect{getting_started, Getting Started}, +@RefClass{boost::overloaded_function}. */ #ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX -#define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX 5 +# define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX 5 #endif #if BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX < 2 -#error "BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX must be >= 2" +# error "maximum overload macro cannot be less than 2" #endif #endif // #include guard diff --git a/overloaded_function/doc/Jamfile.v2 b/overloaded_function/doc/Jamfile.v2 index f09dabf..1cfbc8e 100644 --- a/overloaded_function/doc/Jamfile.v2 +++ b/overloaded_function/doc/Jamfile.v2 @@ -17,7 +17,7 @@ doxygen reference WARN_IF_UNDOCUMENTED=NO HIDE_UNDOC_MEMBERS=YES HIDE_UNDOC_CLASSES=YES - ALIASES=" Params=\"Parameters: \" Param{2}=\"\" EndParams=\"
\\1\\2
\" Returns=\"Returns:\" Note=\"Note:\" Warning=\"Warning:\" See=\"See:\" RefSect{1}=\"\\xmlonly\\1\\endxmlonly\" RefSectId{2}=\"\\xmlonly\\2\\endxmlonly\" RefClass{1}=\"\\xmlonly\\1\\endxmlonly\" RefFunc{1}=\"\\xmlonly\\1\\endxmlonly\" RefMacro{1}=\"\\xmlonly\\1\\endxmlonly\" " + ALIASES=" Params=\"Parameters: \" Param{2}=\"\" EndParams=\"
\\1\\2
\" Returns=\"Returns:\" Note=\"Note:\" Warning=\"Warning:\" See=\"See:\" RefSect{2}=\"\\xmlonly\\2\\endxmlonly\" RefClass{1}=\"\\xmlonly\\1\\endxmlonly\" RefFunc{1}=\"\\xmlonly\\1\\endxmlonly\" RefMacro{1}=\"\\xmlonly\\1\\endxmlonly\" " ; xml qbk : overloaded_function.qbk : reference ; diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html new file mode 100644 index 0000000..4baf1a8 --- /dev/null +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX.html @@ -0,0 +1,54 @@ + + + +Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+
+
+

Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX

+

BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX — Specify the maximum number of arguments of the functions being overloaded.

+
+

Synopsis

+
// In header: <boost/functional/overloaded_function/config.hpp>
+
+BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX
+
+

Description

+

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When specified by the user, this macro must be a non-negative integer number.

+

See: Getting Started, boost::overloaded_function.

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html new file mode 100644 index 0000000..3ebb559 --- /dev/null +++ b/overloaded_function/doc/html/BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.html @@ -0,0 +1,54 @@ + + + +Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+
+
+

Macro BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX

+

BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX — Specify the maximum number of functions that can be overloaded.

+
+

Synopsis

+
// In header: <boost/functional/overloaded_function/config.hpp>
+
+BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX
+
+

Description

+

If this macro is left undefined by the user, it has a default value of 5 (increasing this number might increase compilation time). When defined by the user, this macro must be an integer number greater or equal than 2 (because at least two distinct functions need to be specified in order to define an overload).

+

See: Getting Started, boost::overloaded_function.

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/overloaded_function/doc/html/boost/make_overloaded_function.html b/overloaded_function/doc/html/boost/make_overloaded_function.html new file mode 100644 index 0000000..21f5f39 --- /dev/null +++ b/overloaded_function/doc/html/boost/make_overloaded_function.html @@ -0,0 +1,60 @@ + + + +Function template make_overloaded_function + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+
+
+

Function template make_overloaded_function

+

boost::make_overloaded_function — Make an overloaded function object without explicitly specifying the function types.

+
+

Synopsis

+
// In header: <boost/functional/overloaded_function.hpp>
+
+
+template<typename F1, typename F2, ... > 
+  overloaded_function< __function_type__< F1 >, __function_type__< F2 >,...> 
+  make_overloaded_function(F1 f1, F2 f2, ...);
+
+

Description

+

This function template creates and returns an overloaded_function object that overloads all the specified functions f1, f2, etc.

+

The function types are internally determined from the template parameter types so they do not need to be explicitly specified. Therefore, this function template usually has a more concise syntax when compared with overloaded_function. This is especially useful when the explicit type of the returned overloaded_function object does not need to be known (e.g., when used with Boost.Typeof's BOOST_AUTO, C++11 auto, or when the overloaded function object is handled using a function template parameter, see the Tutorial section).

+

The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro.

+

Note: In this documentation, __function_type__ is a placeholder for a symbol that is specific to the implementation of this library.

+

See: Tutorial section, overloaded_function, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX.

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/overloaded_function/doc/html/boost/overloaded_function.html b/overloaded_function/doc/html/boost/overloaded_function.html new file mode 100644 index 0000000..c8c600f --- /dev/null +++ b/overloaded_function/doc/html/boost/overloaded_function.html @@ -0,0 +1,112 @@ + + + +Class template overloaded_function + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+
+
+

Class template overloaded_function

+

boost::overloaded_function — Function object to overload functions with distinct signatures.

+
+

Synopsis

+
// In header: <boost/functional/overloaded_function.hpp>
+
+template<typename F1, typename F2, ... > 
+class overloaded_function {
+public:
+  // construct/copy/destruct
+  overloaded_function(const boost::function< F1 > &, 
+                      const boost::function< F2 > &, ...);
+
+  // public member functions
+  boost::function_traits< F1 >::result_type 
+  operator()(typename boost::function_traits< F1 >::arg1_type, 
+             typename boost::function_traits< F1 >::arg2_type, ...) const;
+  boost::function_traits< F2 >::result_type 
+  operator()(typename boost::function_traits< F2 >::arg1_type, 
+             typename boost::function_traits< F2 >::arg2_type, ...) const;
+};
+
+

Description

+

This function object aggregates together calls to functions of all the specified function types F1, F2, etc which must have distinct function signatures from one another.

+

Parameters:

+
++++ + + + + +
FiEach function type must be specified using the following syntax (which is Boost.Function's preferred syntax):
    result_type (argument1_type, argumgnet2_type, ...)
+
+

+

+

In some cases, the make_overloaded_function function template can be useful to construct an overloaded function object without explicitly specifying the function types.

+

At least two distinct function types must be specified (because there is nothing to overload between one or zero functions). The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX configuration macro. The maximum number of function parameters for each of the specified function types is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX configuration macro.

+

See: Tutorial section, make_overloaded_function, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, Boost.Function.

+
+

+overloaded_function + public + construct/copy/destruct

+
  1. +
    overloaded_function(const boost::function< F1 > &, 
    +                    const boost::function< F2 > &, ...);
    Construct the overloaded function object.

    Any function pointer, function reference, and monomorphic function object that can be converted to a boost::function function object can be specified as parameter.

    +

    Note: Unfortunately, it is not possible to support polymorphic function objects (as explained here).

    +
+
+
+

+overloaded_function public member functions

+
    +
  1. +
    boost::function_traits< F1 >::result_type 
    +operator()(typename boost::function_traits< F1 >::arg1_type, 
    +           typename boost::function_traits< F1 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 1st template parameter.

    This will in turn invoke the call operator of the 1st function passed to the constructor.

    +
  2. +
  3. +
    boost::function_traits< F2 >::result_type 
    +operator()(typename boost::function_traits< F2 >::arg1_type, 
    +           typename boost::function_traits< F2 >::arg2_type, ...) const;
    Call operator matching the signature of the function type specified as 2nd template parameter.

    This will in turn invoke the call operator of the 2nd function passed to the constructor.

    +

    Note: Similar call operators are present for all specified function types F1, F2, etc (even if not exhaustively listed by this documentation).

    +
  4. +
+
+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/acknowledgments.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/acknowledgments.html new file mode 100644 index 0000000..605d481 --- /dev/null +++ b/overloaded_function/doc/html/boost_functional_overloadedfunction/acknowledgments.html @@ -0,0 +1,60 @@ + + + +Acknowledgments + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHome +
+
+ +

+ Many thanks to Mathias Gaunard for suggesting to implement boost::overloaded_function + and for some sample code. +

+

+ Thanks to John Bytheway for suggesting to implement boost::make_overloaded_function. +

+

+ Thanks to Nathan Ridge for suggestions on how to implement boost::make_overloaded_function. +

+

+ Thanks to Robert Stewart for commenting on the library name. +

+

+ Many thanks to the entire Boost community + and mailing list for providing valuable comments about this library and great + insights on the C++ programming language. +

+
+ + + +
+
+
+PrevUpHome +
+ + diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/getting_started.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/getting_started.html new file mode 100644 index 0000000..459e7d5 --- /dev/null +++ b/overloaded_function/doc/html/boost_functional_overloadedfunction/getting_started.html @@ -0,0 +1,95 @@ + + + +Getting Started + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +

+ This section explains how to setup a system to use this library. +

+
+ +

+ The authors originally developed and tested this library on: +

+
    +
  1. + GNU Compiler Collection (GCC) C++ 4.5.3 (with and without C++11 features + enabled -std=c++0x) + on Cygwin. +
  2. +
  3. + Miscrosoft Visual C++ (MSVC) 8.0 on Windows 7. +
  4. +
+

+ See the library regressions + test results for detailed information on supported compilers and + platforms. Check the library regression test Jamfile.v2 + for any special configuration that might be required for a specific compiler. +

+
+
+ +

+ This library is composed of header files only. Therefore there is no pre-compiled + object file which needs to be installed. Programmers can simply instruct + the compiler where to find the library header files (-I option on GCC, /I option on MSVC, etc) and compile code + using the library. +

+

+ The maximum number of functions to overload is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX + configuration macro. The maximum number of function parameters for each of + the specified function type is given by the BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX + configuration macro. All configuration macros have appropriate default values + when they are left undefined. +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/overloaded_function/doc/html/boost_functional_overloadedfunction/tutorial.html b/overloaded_function/doc/html/boost_functional_overloadedfunction/tutorial.html new file mode 100644 index 0000000..98493ac --- /dev/null +++ b/overloaded_function/doc/html/boost_functional_overloadedfunction/tutorial.html @@ -0,0 +1,228 @@ + + + +Tutorial + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +

+ This section explains how to use this library. +

+
+ +

+ Consider the following functions which have distinct signatures: +

+

+

+
const std::string& identity_s(const std::string& x) // Function (as pointer).
+    { return x; }
+
+int identity_i_impl(int x) { return x; }
+int (&identity_i)(int) = identity_i_impl; // Function reference.
+
+double identity_d_impl(double x) { return x; }
+boost::function<double (double)> identity_d = identity_d_impl; // Functor.
+
+

+

+

+ This library header boost/functional/overloaded_function.hpp + provides a boost::overloaded_function + class template that creates a single overloaded function object that can + be used to call the specified functions instead of using the separate function + names (see also functor.cpp + and identity.hpp): +

+

+

+
boost::overloaded_function<
+      const std::string& (const std::string&)
+    , int (int)
+    , double (double)
+> identity(identity_s, identity_i, identity_d);
+
+// All calls via single `identity` function.
+BOOST_TEST(identity("abc") == "abc");
+BOOST_TEST(identity(123) == 123);
+BOOST_TEST(identity(1.23) == 1.23);
+
+

+

+

+ Note how each function type is passed as a template parameter of boost::overloaded_function using + the following syntax (this is Boost.Function's + preferred syntax): +

+
result-type (argument1-type, argument2-type, ...)
+
+

+ Then the relative function pointers, function references, or monomorphic + function objects are passed to the boost::overloaded_function + constructor matching the order of the specified template parameters. [2] In the above example, identity_s + is passed as a function pointer (the function address is automatically taken + from the function name by the compiler), identity_i + as a function reference, and identity_d + as a function object. +

+

+ All specified function types must have distinct parameters from one another + (so the overloaded calls can be resolved by this library). [3] In order to create an overloaded function object, it is necessary + to specify at least two function types (because there is nothing to overload + between one or zero functions). +

+
+
+ +

+ For convenience, this library also provides the boost::make_overloaded_function + function template which allows to create the overloaded function object without + explicitly specifying the function types. The function types are automatically + deduced from the specified functions and the appropriate boost::overloaded_function + instantiation is returned by boost::make_overloaded_function. +

+

+ The boost::make_overloaded_function + function template can be useful when used together with Boost.Typeof's + BOOST_AUTO (or C++11 auto). For example (see also make_decl.cpp + and identity.hpp): +

+

+

+
BOOST_AUTO(identity, boost::make_overloaded_function(
+        identity_s, identity_i, identity_d));
+
+BOOST_TEST(identity("abc") == "abc");
+BOOST_TEST(identity(123) == 123);
+BOOST_TEST(identity(1.23) == 1.23);
+
+

+

+

+ Note how the overloaded function object identity + has been created specifying only the functions identity_s, + identity_i, identity_d and without specifying the function + types const std::string& (const + std::string&), + int (int), and + double (double) as + required instead by boost::overloaded_function. + Therefore, boost::make_overloaded_function + provides a more concise syntax in this context when compared with boost::overloaded_function. +

+

+ Another case where boost::make_overloaded_function + can be useful is when the overloaded function object is passed to a function + template which can hold the specific boost::overloaded_function + type using a template parameter. For example (see also make_call.cpp + and identity.hpp): +

+

+

+
template<typename F>
+void check(F identity) {
+    BOOST_TEST(identity("abc") == "abc");
+    BOOST_TEST(identity(123) == 123);
+    BOOST_TEST(identity(1.23) == 1.23);
+}
+
+

+

+

+

+
check(boost::make_overloaded_function(identity_s, identity_i, identity_d));
+
+

+

+

+ The library implementation of boost::make_overloaded_function + uses Boost.Typeof + to automatically deduce some of the function types. In order to compile code + in Boost.Typeof + emulation mode, all types should be properly registered using BOOST_TYPEOF_REGISTER_TYPE and BOOST_TYPEOF_REGISTER_TEMPLATE, or appropriate + Boost.Typeof headers + should be included (see Boost.Typeof + for more information). For the above examples, it is sufficient to include + the Boost.Typeof + header that registers std::string + (this library does not require to register boost::function + for Boost.Typeof + emulation): +

+

+

+
#include <boost/typeof/std/string.hpp> // No need to register `boost::function`.
+
+

+

+
+
+

+

[2] + Function pointers are of the form result-type (*)(argument1-type, ...) (the + C++ compiler is usually able to automatically promote a function name to + a function pointer in a context where a function pointer is expected even + if the function name is not prefixed by &). + Function references are of the form result-type (&)(argument1-type, ...). + Function types are of the form result-type (argument1-type, ...) (note + how they lack of both * and + & when compared to function + pointers and function references). Finally, monomorphic function objects + are instances of classes with a non-template call operator of the form + result-type operator()(argument1-type, ...). + Unfortunately, it is not possible to support polymorphic function objects + (see http://lists.boost.org/Archives/boost/2012/03/191744.php). +

+

[3] + Note that in C++ the function result type is not used for overload resolution + (to avoid making the overload resolution context dependent). Therefore, + at least one of the function parameters must be distinct for each specified + function type. +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/overloaded_function/doc/html/index.html b/overloaded_function/doc/html/index.html new file mode 100644 index 0000000..5e6c0e9 --- /dev/null +++ b/overloaded_function/doc/html/index.html @@ -0,0 +1,147 @@ + + + +Chapter 1. Boost.Functional/OverloadedFunction 1.0.0 + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
Next
+
+
+

+Chapter 1. Boost.Functional/OverloadedFunction 1.0.0

+

+Lorenzo Caminiti +

+
+
+

+ 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) +

+
+
+ +

+ This library allows to overload different functions into a single function object. +

+
+ +

+ Consider the following functions which have distinct signatures: +

+

+

+
const std::string& identity_s(const std::string& x) // Function (as pointer).
+    { return x; }
+
+int identity_i_impl(int x) { return x; }
+int (&identity_i)(int) = identity_i_impl; // Function reference.
+
+double identity_d_impl(double x) { return x; }
+boost::function<double (double)> identity_d = identity_d_impl; // Functor.
+
+

+

+

+ Instead of calling them using their separate names (here BOOST_TEST + is equivalent to assert): + [1] +

+

+

+
BOOST_TEST(identity_s("abc") == "abc");
+BOOST_TEST(identity_i(123) == 123);
+BOOST_TEST(identity_d(1.23) == 1.23);
+
+

+

+

+ It is possible to use this library to create a single overloaded + function object (or functor) + named identity that aggregates + together the calls to the specific functions (see also functor.cpp + and identity.hpp): +

+

+

+
boost::overloaded_function<
+      const std::string& (const std::string&)
+    , int (int)
+    , double (double)
+> identity(identity_s, identity_i, identity_d);
+
+// All calls via single `identity` function.
+BOOST_TEST(identity("abc") == "abc");
+BOOST_TEST(identity(123) == 123);
+BOOST_TEST(identity(1.23) == 1.23);
+
+

+

+

+ Note how the functions are called via a single overloaded function object + identity instead of using their + different names identity_s, + identity_i, and identity_d. +

+
+
+

+

[1] + In most of the examples presented in this documentation, the Boost.Detail/LightweightTest + (boost/detail/lightweight_test.hpp) macro BOOST_TEST is used to check correctness + conditions (conceptually similar to assert). + A failure of the checked condition does not abort the execution of the program, + it will instead make boost::report_errors + return a non-zero program exit code. Using Boost.Detail/LightweightTest allows + to add the examples to the library regression tests so to make sure that + they always compile and run correctly. +

+
+
+ + + +

Last revised: April 28, 2012 at 02:19:13 GMT

+
+
Next
+ + diff --git a/overloaded_function/doc/html/reference.html b/overloaded_function/doc/html/reference.html new file mode 100644 index 0000000..55a89f0 --- /dev/null +++ b/overloaded_function/doc/html/reference.html @@ -0,0 +1,66 @@ + + + +Reference + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+

+Reference

+ +
+ +

Overload distinct function pointers, function references, and monomorphic function objects into a single function object.

+
namespace boost {
+  template<typename F1, typename F2, ... > class overloaded_function;
+  template<typename F1, typename F2, ... > 
+    overloaded_function< __function_type__< F1 >, __function_type__< F2 >,...> 
+    make_overloaded_function(F1, F2, ...);
+}
+
+ +
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/overloaded_function/doc/overloaded_function.qbk b/overloaded_function/doc/overloaded_function.qbk index 5bda0df..6cf6964 100644 --- a/overloaded_function/doc/overloaded_function.qbk +++ b/overloaded_function/doc/overloaded_function.qbk @@ -19,9 +19,9 @@ [category Function Objects and Higher-Order Programming] ] -[def __Introduction__ [link functional_overloaded_function.Introduction Introduction]] -[def __Getting_Started__ [link functional_overloaded_function.Getting_Started Getting Started]] -[def __Tutorial__ [link functional_overloaded_function.Tutorial Tutorial]] +[def __Introduction__ [link functional_overloaded_function.introduction Introduction]] +[def __Getting_Started__ [link functional_overloaded_function.getting_started Getting Started]] +[def __Tutorial__ [link functional_overloaded_function.tutorial Tutorial]] [def __Boost__ [@http://www.boost.org Boost]] [def __Boost_Test__ [@http://www.boost.org/libs/test Boost.Test]] [def __Boost_Function__ [@http://www.boost.org/libs/function Boost.Function]] @@ -34,7 +34,7 @@ This library allows to overload different functions into a single function object. -[section:Introduction Introduction] +[section Introduction] Consider the following functions which have distinct signatures: @@ -57,7 +57,7 @@ Note how the functions are called via a single overloaded function object `ident [endsect] -[section:Getting_Started Getting Started] +[section Getting Started] This section explains how to setup a system to use this library. @@ -87,7 +87,7 @@ All configuration macros have appropriate default values when they are left unde [endsect] -[section:Tutorial Tutorial] +[section Tutorial] This section explains how to use this library. @@ -155,7 +155,7 @@ For the above examples, it is sufficient to include the __Boost_Typeof__ header [xinclude reference.xml] -[section:Acknowledgments Acknowledgments] +[section Acknowledgments] Many thanks to Mathias Gaunard for suggesting to implement [classref boost::overloaded_function] and for some sample code. From 8e0b32aca53d09d5c5a83dc8c0f518d0684540d8 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 3 May 2012 21:35:51 +0000 Subject: [PATCH 26/51] Unordered/Hash: Release notes. [SVN r78318] --- hash/doc/changes.qbk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hash/doc/changes.qbk b/hash/doc/changes.qbk index 1673b34..c47bd56 100644 --- a/hash/doc/changes.qbk +++ b/hash/doc/changes.qbk @@ -125,7 +125,8 @@ [h2 Boost 1.50.0] -* Avoid gcc's `-Wfloat-equal` warning. +* [@http://svn.boost.org/trac/boost/ticket/6771 Ticket 6771]: + Avoid gcc's `-Wfloat-equal` warning. * [@http://svn.boost.org/trac/boost/ticket/6806 Ticket 6806]: Support `std::array` and `std::tuple` when available. From 8d18d5b53ee4f94b40dde2e758e64541ae62644d Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 7 May 2012 10:57:35 +0000 Subject: [PATCH 27/51] Unordered: Avoid `-Wshadow` warnings. Refs #6190. [SVN r78364] --- hash/test/Jamfile.v2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index af24329..2d1a527 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -10,8 +10,8 @@ project hash-tests all intel:on intel:-strict-ansi - gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal" - darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal" + gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow" + darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow" msvc:on #gcc:on #darwin:on From 65bade2cb21347a56382423fac18b27102d31aa6 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 7 May 2012 10:58:55 +0000 Subject: [PATCH 28/51] Hash: Add some notes about forwarding header. Refs #6849. [SVN r78366] --- hash/doc/ref.xml | 17 ++++++++++++++--- hash/doc/tutorial.qbk | 12 +++++++++++- hash/examples/Jamfile.v2 | 1 + hash/examples/template.cpp | 18 ++++++++++++++++++ hash/examples/template.hpp | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 hash/examples/template.cpp create mode 100644 hash/examples/template.hpp diff --git a/hash/doc/ref.xml b/hash/doc/ref.xml index fa29fcd..d7c427c 100644 --- a/hash/doc/ref.xml +++ b/hash/doc/ref.xml @@ -55,6 +55,10 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) is defined. The specializations are still defined, so only the specializations required by TR1 are defined.
+ + Forward declared in + <boost/functional/hash_fwd.hpp> + Only throws if @@ -451,6 +455,10 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) hash_value is called without qualification, so that overloads can be found via ADL. This is an extension to TR1 + + Forward declared in + <boost/functional/hash_fwd.hpp> + Only throws if hash_value(T) throws. @@ -499,15 +507,14 @@ for(; first != last; ++first) return seed; - For the three arguments overload: + + For the three arguments overload: for(; first != last; ++first) { hash_combine(seed, *first); } - - @@ -516,6 +523,10 @@ for(; first != last; ++first) container. This is an extension to TR1 + + Forward declared in + <boost/functional/hash_fwd.hpp> + Only throws if hash_value(std::iterator_traits<It>::value_type) diff --git a/hash/doc/tutorial.qbk b/hash/doc/tutorial.qbk index 81c1b15..916ab93 100644 --- a/hash/doc/tutorial.qbk +++ b/hash/doc/tutorial.qbk @@ -198,5 +198,15 @@ To calculate the hash of an iterator range you can use [funcref boost::hash_rang std::vector some_strings; std::size_t hash = ``[funcref boost::hash_range]``(some_strings.begin(), some_strings.end()); -[endsect] +Note that when writing template classes, you might not want to include the main +hash header as it's quite an expensive include that brings in a lot of other +headers, so instead you can include the `` +header which forward declares [classref boost::hash], +[funcref boost::hash_range] and [funcref boost::hash_combine]. You'll need to +include the main header before instantiating [classref boost::hash]. When using +a container that uses [classref boost::hash] it should do that for you, so your +type will work fine with the boost hash containers. There's an example of this +in [@boost:/libs/unordered/examples/template.hpp template.hpp] and +[@boost:/libs/unordered/examples/template.cpp template.cpp]. +[endsect] diff --git a/hash/examples/Jamfile.v2 b/hash/examples/Jamfile.v2 index dc5bdce..6291621 100644 --- a/hash/examples/Jamfile.v2 +++ b/hash/examples/Jamfile.v2 @@ -6,3 +6,4 @@ run books.cpp ; run point.cpp ; run portable.cpp ; +run template.cpp ; diff --git a/hash/examples/template.cpp b/hash/examples/template.cpp new file mode 100644 index 0000000..d74f0a9 --- /dev/null +++ b/hash/examples/template.cpp @@ -0,0 +1,18 @@ + +// Copyright 2012 Daniel James. +// 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 "template.hpp" +#include +#include + +int main() +{ + typedef my_pair pair; + boost::unordered_set pair_set; + pair_set.emplace(10, 0.5f); + + assert(pair_set.find(pair(10, 0.5f)) != pair_set.end()); + assert(pair_set.find(pair(10, 0.6f)) == pair_set.end()); +} diff --git a/hash/examples/template.hpp b/hash/examples/template.hpp new file mode 100644 index 0000000..b630704 --- /dev/null +++ b/hash/examples/template.hpp @@ -0,0 +1,36 @@ + +// Copyright 2012 Daniel James. +// 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) + +// This is an example of how to write a hash function for a template +// class. + +#include + +template +class my_pair +{ + A value1; + B value2; +public: + my_pair(A const& v1, B const& v2) + : value1(v1), value2(v2) + {} + + bool operator==(my_pair const& other) const + { + return value1 == other.value1 && + value2 == other.value2; + } + + friend std::size_t hash_value(my_pair const& p) + { + std::size_t seed = 0; + boost::hash_combine(seed, p.value1); + boost::hash_combine(seed, p.value2); + + return seed; + } +}; + From f54e6e8af14a4cb01f5ac0de2e643294856a3c46 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Tue, 8 May 2012 22:24:46 +0000 Subject: [PATCH 29/51] Hash: Use SFINAE to avoid implicit casts to numbers. [SVN r78391] --- hash/test/Jamfile.v2 | 76 ++++----- ...plicit_fail_test.cpp => implicit_test.cpp} | 0 include/boost/functional/hash/hash.hpp | 160 +++++++----------- 3 files changed, 91 insertions(+), 145 deletions(-) rename hash/test/{implicit_fail_test.cpp => implicit_test.cpp} (100%) diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index 2d1a527..0d85829 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -19,51 +19,37 @@ project hash-tests test-suite functional/hash : - [ run hash_fwd_test_1.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_fwd_test_2.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_number_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_pointer_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_function_pointer_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_float_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_long_double_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_string_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_range_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_custom_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_global_namespace_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_friend_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_built_in_array_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_value_array_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_vector_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_list_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_deque_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_set_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_map_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_complex_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_type_index_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_std_array_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_std_tuple_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run link_test.cpp link_test_2.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run link_ext_test.cpp link_no_ext_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run extensions_hpp_test.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ compile-fail hash_no_ext_fail_test.cpp : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ compile-fail namespace_fail_test.cpp : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ compile-fail implicit_fail_test.cpp : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_no_ext_macro_1.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_no_ext_macro_2.cpp : : : BOOST_HASH_NO_IMPLICIT_CASTS ] - ; - -test-suite functional/hash_implicit_casts - : - [ run hash_number_test.cpp : : : : implicit_number ] - [ run hash_pointer_test.cpp : : : : implicit_pointer ] - [ run hash_function_pointer_test.cpp : : : : implicit_function_pointer ] - [ run hash_float_test.cpp : : : : implicit_float ] - [ run hash_string_test.cpp : : : : implicit_string ] - [ run hash_range_test.cpp : : : : implicit_range ] - [ run hash_custom_test.cpp : : : : implicit_custom ] - [ run hash_built_in_array_test.cpp : : : : implicit_built_in_array ] - [ run link_test.cpp link_test_2.cpp : : : : implicit_link ] - [ run implicit_fail_test.cpp : : : : implicit_test ] + [ run hash_fwd_test_1.cpp ] + [ run hash_fwd_test_2.cpp ] + [ run hash_number_test.cpp ] + [ run hash_pointer_test.cpp ] + [ run hash_function_pointer_test.cpp ] + [ run hash_float_test.cpp ] + [ run hash_long_double_test.cpp ] + [ run hash_string_test.cpp ] + [ run hash_range_test.cpp ] + [ run hash_custom_test.cpp ] + [ run hash_global_namespace_test.cpp ] + [ run hash_friend_test.cpp ] + [ run hash_built_in_array_test.cpp ] + [ run hash_value_array_test.cpp ] + [ run hash_vector_test.cpp ] + [ run hash_list_test.cpp ] + [ run hash_deque_test.cpp ] + [ run hash_set_test.cpp ] + [ run hash_map_test.cpp ] + [ run hash_complex_test.cpp ] + [ run hash_type_index_test.cpp ] + [ run hash_std_array_test.cpp ] + [ run hash_std_tuple_test.cpp ] + [ run link_test.cpp link_test_2.cpp ] + [ run link_ext_test.cpp link_no_ext_test.cpp ] + [ run extensions_hpp_test.cpp ] + [ compile-fail hash_no_ext_fail_test.cpp ] + [ compile-fail namespace_fail_test.cpp ] + [ run implicit_test.cpp ] + [ run hash_no_ext_macro_1.cpp ] + [ run hash_no_ext_macro_2.cpp ] ; test-suite functional/hash_no_ext diff --git a/hash/test/implicit_fail_test.cpp b/hash/test/implicit_test.cpp similarity index 100% rename from hash/test/implicit_fail_test.cpp rename to hash/test/implicit_test.cpp diff --git a/include/boost/functional/hash/hash.hpp b/include/boost/functional/hash/hash.hpp index 51ec860..7559e56 100644 --- a/include/boost/functional/hash/hash.hpp +++ b/include/boost/functional/hash/hash.hpp @@ -16,10 +16,6 @@ #include #include -#if defined(BOOST_HASH_NO_IMPLICIT_CASTS) -#include -#endif - #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #include #endif @@ -37,38 +33,63 @@ namespace boost { -#if defined(BOOST_HASH_NO_IMPLICIT_CASTS) + namespace hash_detail + { + struct enable_hash_value { typedef std::size_t type; }; - // If you get a static assertion here, it's because hash_value - // isn't declared for your type. - template - std::size_t hash_value(T const&) { - BOOST_STATIC_ASSERT((T*) 0 && false); - return 0; - } + template struct basic_numbers {}; + template struct long_numbers {}; + template struct ulong_numbers {}; + template struct float_numbers {}; -#endif - - std::size_t hash_value(bool); - std::size_t hash_value(char); - std::size_t hash_value(unsigned char); - std::size_t hash_value(signed char); - std::size_t hash_value(short); - std::size_t hash_value(unsigned short); - std::size_t hash_value(int); - std::size_t hash_value(unsigned int); - std::size_t hash_value(long); - std::size_t hash_value(unsigned long); + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) - std::size_t hash_value(wchar_t); + template <> struct basic_numbers : + boost::hash_detail::enable_hash_value {}; #endif - + #if !defined(BOOST_NO_LONG_LONG) - std::size_t hash_value(boost::long_long_type); - std::size_t hash_value(boost::ulong_long_type); + template <> struct long_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct ulong_numbers : + boost::hash_detail::enable_hash_value {}; #endif + template <> struct float_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct float_numbers : + boost::hash_detail::enable_hash_value {}; + template <> struct float_numbers : + boost::hash_detail::enable_hash_value {}; + } + + template + typename boost::hash_detail::basic_numbers::type hash_value(T); + template + typename boost::hash_detail::long_numbers::type hash_value(T); + template + typename boost::hash_detail::ulong_numbers::type hash_value(T); + #if !BOOST_WORKAROUND(__DMC__, <= 0x848) template std::size_t hash_value(T* const&); #else @@ -83,14 +104,13 @@ namespace boost std::size_t hash_value(T (&x)[N]); #endif - std::size_t hash_value(float v); - std::size_t hash_value(double v); - std::size_t hash_value(long double v); - template std::size_t hash_value( std::basic_string, A> const&); + template + typename boost::hash_detail::float_numbers::type hash_value(T); + #if !defined(BOOST_NO_0X_HDR_TYPEINDEX) std::size_t hash_value(std::type_index); #endif @@ -141,74 +161,23 @@ namespace boost } } - inline std::size_t hash_value(bool v) + template + typename boost::hash_detail::basic_numbers::type hash_value(T v) { return static_cast(v); } - inline std::size_t hash_value(char v) - { - return static_cast(v); - } - - inline std::size_t hash_value(unsigned char v) - { - return static_cast(v); - } - - inline std::size_t hash_value(signed char v) - { - return static_cast(v); - } - - inline std::size_t hash_value(short v) - { - return static_cast(v); - } - - inline std::size_t hash_value(unsigned short v) - { - return static_cast(v); - } - - inline std::size_t hash_value(int v) - { - return static_cast(v); - } - - inline std::size_t hash_value(unsigned int v) - { - return static_cast(v); - } - - inline std::size_t hash_value(long v) - { - return static_cast(v); - } - - inline std::size_t hash_value(unsigned long v) - { - return static_cast(v); - } - -#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) - inline std::size_t hash_value(wchar_t v) - { - return static_cast(v); - } -#endif - -#if !defined(BOOST_NO_LONG_LONG) - inline std::size_t hash_value(boost::long_long_type v) + template + typename boost::hash_detail::long_numbers::type hash_value(T v) { return hash_detail::hash_value_signed(v); } - inline std::size_t hash_value(boost::ulong_long_type v) + template + typename boost::hash_detail::ulong_numbers::type hash_value(T v) { return hash_detail::hash_value_unsigned(v); } -#endif // Implementation by Alberto Barbati and Dave Harris. #if !BOOST_WORKAROUND(__DMC__, <= 0x848) @@ -324,17 +293,8 @@ namespace boost return hash_range(v.begin(), v.end()); } - inline std::size_t hash_value(float v) - { - return boost::hash_detail::float_hash_value(v); - } - - inline std::size_t hash_value(double v) - { - return boost::hash_detail::float_hash_value(v); - } - - inline std::size_t hash_value(long double v) + template + typename boost::hash_detail::float_numbers::type hash_value(T v) { return boost::hash_detail::float_hash_value(v); } From f88d46a03a1fac3674c319d136237952af4aacf6 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 21 May 2012 21:58:18 +0000 Subject: [PATCH 30/51] Add warning to deprecated header `boost/functional/detail/container_fwd.hpp`. Should have done this years ago, removing this header should make modularization a tad bit cleaner. [SVN r78533] --- hash/test/Jamfile.v2 | 1 + hash/test/deprecated_container_fwd.cpp | 14 ++++++++++++++ include/boost/functional/detail/container_fwd.hpp | 14 +++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 hash/test/deprecated_container_fwd.cpp diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index 0d85829..47f0a95 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -50,6 +50,7 @@ test-suite functional/hash [ run implicit_test.cpp ] [ run hash_no_ext_macro_1.cpp ] [ run hash_no_ext_macro_2.cpp ] + [ compile deprecated_container_fwd.cpp ] ; test-suite functional/hash_no_ext diff --git a/hash/test/deprecated_container_fwd.cpp b/hash/test/deprecated_container_fwd.cpp new file mode 100644 index 0000000..1c6e12b --- /dev/null +++ b/hash/test/deprecated_container_fwd.cpp @@ -0,0 +1,14 @@ + +// Copyright 2012 Daniel James. +// 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 + +typedef std::vector > int_vector; + +#include + +int main() { + int_vector x; +} diff --git a/include/boost/functional/detail/container_fwd.hpp b/include/boost/functional/detail/container_fwd.hpp index 9a69d15..dd55571 100644 --- a/include/boost/functional/detail/container_fwd.hpp +++ b/include/boost/functional/detail/container_fwd.hpp @@ -1,11 +1,11 @@ -// Copyright 2005-2008 Daniel James. +// Copyright 2005-2012 Daniel James. // 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) // Forwarding header for container_fwd.hpp's new location. -// This header is deprecated, I'll be adding a warning in a future release, -// then converting it to an error and finally removing this header completely. +// This header is deprecated, I'll change the warning to an error in a future +// release, and then later remove the header completely. #if !defined(BOOST_FUNCTIONAL_DETAIL_CONTAINER_FWD_HPP) #define BOOST_FUNCTIONAL_DETAIL_CONTAINER_FWD_HPP @@ -14,6 +14,14 @@ # pragma once #endif +#if defined(__EDG__) +#elif defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__) +#pragma message("Warning: boost/functional/detail/container_fwd.hpp is deprecated, use boost/detail/container_fwd.hpp instead."); +#elif defined(__GNUC__) || defined(__HP_aCC) || \ + defined(__SUNPRO_CC) || defined(__IBMCPP__) +#warning "boost/functional/detail/container_fwd.hpp is deprecated, use boost/detail/container_fwd.hpp instead." +#endif + #include #endif From 9f2652ae0733c03410cc3653ae2f86d392c819c6 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 26 May 2012 15:02:26 +0000 Subject: [PATCH 31/51] Hash: Remove stary semicolon from deprecation pragma. [SVN r78635] --- include/boost/functional/detail/container_fwd.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/functional/detail/container_fwd.hpp b/include/boost/functional/detail/container_fwd.hpp index dd55571..e2bf865 100644 --- a/include/boost/functional/detail/container_fwd.hpp +++ b/include/boost/functional/detail/container_fwd.hpp @@ -16,7 +16,7 @@ #if defined(__EDG__) #elif defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__) -#pragma message("Warning: boost/functional/detail/container_fwd.hpp is deprecated, use boost/detail/container_fwd.hpp instead."); +#pragma message("Warning: boost/functional/detail/container_fwd.hpp is deprecated, use boost/detail/container_fwd.hpp instead.") #elif defined(__GNUC__) || defined(__HP_aCC) || \ defined(__SUNPRO_CC) || defined(__IBMCPP__) #warning "boost/functional/detail/container_fwd.hpp is deprecated, use boost/detail/container_fwd.hpp instead." From 446b6496a72c85904ba8a3a7b0f7fc9bd06625c0 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 27 May 2012 20:55:14 +0000 Subject: [PATCH 32/51] Hash: Extra changelog note. [SVN r78696] --- hash/doc/changes.qbk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hash/doc/changes.qbk b/hash/doc/changes.qbk index c47bd56..3aa3dee 100644 --- a/hash/doc/changes.qbk +++ b/hash/doc/changes.qbk @@ -129,5 +129,7 @@ Avoid gcc's `-Wfloat-equal` warning. * [@http://svn.boost.org/trac/boost/ticket/6806 Ticket 6806]: Support `std::array` and `std::tuple` when available. +* Add deprecation warning to the long deprecated + `boost/functional/detail/container_fwd.hpp`. [endsect] From b839b806cfaafbd2e38d33dbb7760305f31eec94 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Tue, 29 May 2012 19:41:19 +0000 Subject: [PATCH 33/51] Hash: Only use typeid when available. [SVN r78755] --- hash/test/hash_type_index_test.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hash/test/hash_type_index_test.cpp b/hash/test/hash_type_index_test.cpp index 7892918..917bca9 100644 --- a/hash/test/hash_type_index_test.cpp +++ b/hash/test/hash_type_index_test.cpp @@ -18,12 +18,16 @@ #include void test_type_index() { + HASH_NAMESPACE::hash hasher; + +#if defined(BOOST_NO_TYPEID) + std::cout<<"Unable to test std::type_index, as typeid isn't available" + < hasher; - BOOST_TEST(hasher(int_index) == int_index.hash_code()); BOOST_TEST(hasher(int_index) == int2_index.hash_code()); BOOST_TEST(hasher(char_index) == char_index.hash_code()); @@ -33,6 +37,7 @@ void test_type_index() { BOOST_TEST(hasher(int_index) == hasher(int2_index)); BOOST_TEST(hasher(int_index) != hasher(char_index)); +#endif } #endif From b5d39108b2634d19567568f0c972781ec3ab69cf Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 7 Jun 2012 12:32:56 +0000 Subject: [PATCH 34/51] Changes required to build PDF versions of docs. [SVN r78845] --- overloaded_function/doc/Jamfile.v2 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/overloaded_function/doc/Jamfile.v2 b/overloaded_function/doc/Jamfile.v2 index 1cfbc8e..33182da 100644 --- a/overloaded_function/doc/Jamfile.v2 +++ b/overloaded_function/doc/Jamfile.v2 @@ -28,3 +28,7 @@ boostbook doc : qbk pdf:boost.url.prefix=http://www.boost.org/doc/libs/release/libs/functional/overloaded_function/doc/html ; +install pdf-install : doc : . PDF overloaded_function.pdf ; + + + From 769ec4369d62cbbca0b3c22fcdafd6c7de3bd637 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 11 Jun 2012 01:33:10 +0000 Subject: [PATCH 35/51] Make the new pdf install rules explicit, and fix intrusive's. [SVN r78877] --- overloaded_function/doc/Jamfile.v2 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/overloaded_function/doc/Jamfile.v2 b/overloaded_function/doc/Jamfile.v2 index 33182da..a728e83 100644 --- a/overloaded_function/doc/Jamfile.v2 +++ b/overloaded_function/doc/Jamfile.v2 @@ -29,6 +29,4 @@ boostbook doc : qbk ; install pdf-install : doc : . PDF overloaded_function.pdf ; - - - +explicit pdf-install ; From e723967c7e426d6bb9c84c67173950c6cd0fb972 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 9 Jul 2012 20:12:04 +0000 Subject: [PATCH 36/51] Switch from deprecated macros to new shiny ones; no functionality change [SVN r79392] --- hash/test/hash_std_array_test.cpp | 2 +- hash/test/hash_std_tuple_test.cpp | 2 +- hash/test/hash_type_index_test.cpp | 4 ++-- include/boost/functional/hash/detail/container_fwd_0x.hpp | 4 ++-- include/boost/functional/hash/extensions.hpp | 4 ++-- include/boost/functional/hash/hash.hpp | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hash/test/hash_std_array_test.cpp b/hash/test/hash_std_array_test.cpp index 540b676..6f67a67 100644 --- a/hash/test/hash_std_array_test.cpp +++ b/hash/test/hash_std_array_test.cpp @@ -16,7 +16,7 @@ #include #include -#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_0X_HDR_ARRAY) +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_ARRAY) #define TEST_ARRAY #include #include diff --git a/hash/test/hash_std_tuple_test.cpp b/hash/test/hash_std_tuple_test.cpp index 15ef483..9314336 100644 --- a/hash/test/hash_std_tuple_test.cpp +++ b/hash/test/hash_std_tuple_test.cpp @@ -16,7 +16,7 @@ #include #include -#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_0X_HDR_TUPLE) +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_TUPLE) #define TEST_TUPLE #include #include diff --git a/hash/test/hash_type_index_test.cpp b/hash/test/hash_type_index_test.cpp index 917bca9..27fcfff 100644 --- a/hash/test/hash_type_index_test.cpp +++ b/hash/test/hash_type_index_test.cpp @@ -13,7 +13,7 @@ #include #include -#if !defined(BOOST_NO_0X_HDR_TYPEINDEX) +#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX) #include @@ -43,7 +43,7 @@ void test_type_index() { int main() { -#if !defined(BOOST_NO_0X_HDR_TYPEINDEX) +#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX) test_type_index(); #else std::cout<<" not available."< std::size_t hash_value(std::array const& v) { @@ -122,7 +122,7 @@ namespace boost } #endif -#if !defined(BOOST_NO_0X_HDR_TUPLE) +#if !defined(BOOST_NO_CXX11_HDR_TUPLE) namespace hash_detail { template inline typename boost::enable_if_c<(I == std::tuple_size::value), diff --git a/include/boost/functional/hash/hash.hpp b/include/boost/functional/hash/hash.hpp index 7559e56..c179fab 100644 --- a/include/boost/functional/hash/hash.hpp +++ b/include/boost/functional/hash/hash.hpp @@ -20,7 +20,7 @@ #include #endif -#if !defined(BOOST_NO_0X_HDR_TYPEINDEX) +#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX) #include #endif @@ -111,7 +111,7 @@ namespace boost template typename boost::hash_detail::float_numbers::type hash_value(T); -#if !defined(BOOST_NO_0X_HDR_TYPEINDEX) +#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX) std::size_t hash_value(std::type_index); #endif @@ -299,7 +299,7 @@ namespace boost return boost::hash_detail::float_hash_value(v); } -#if !defined(BOOST_NO_0X_HDR_TYPEINDEX) +#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX) inline std::size_t hash_value(std::type_index v) { return v.hash_code(); @@ -410,7 +410,7 @@ namespace boost BOOST_HASH_SPECIALIZE(boost::ulong_long_type) #endif -#if !defined(BOOST_NO_0X_HDR_TYPEINDEX) +#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX) BOOST_HASH_SPECIALIZE(std::type_index) #endif From 4533e3b83fe6fbee55a90fdb6a408460b955d2d2 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sat, 14 Jul 2012 11:21:03 +0000 Subject: [PATCH 37/51] Fix PDF install rule so that it's explicit and automatically invokes a PDF build when specified on the command line. So "bjam pdfinstall" will now build and install the PDF to the current directory. This works around some problems that the previous versions had if the user did not have an FO processor installed (basically Daniel James was unable to build the HTML docs for the distribution if the pdfinstall rule was implicit). [SVN r79492] --- overloaded_function/doc/Jamfile.v2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/overloaded_function/doc/Jamfile.v2 b/overloaded_function/doc/Jamfile.v2 index a728e83..04c13dd 100644 --- a/overloaded_function/doc/Jamfile.v2 +++ b/overloaded_function/doc/Jamfile.v2 @@ -28,5 +28,5 @@ boostbook doc : qbk pdf:boost.url.prefix=http://www.boost.org/doc/libs/release/libs/functional/overloaded_function/doc/html ; -install pdf-install : doc : . PDF overloaded_function.pdf ; -explicit pdf-install ; +install pdfinstall : doc/pdf : . PDF overloaded_function.pdf ; +explicit pdfinstall ; From 84d32ce136e763f6936cd351943f50f912f32e70 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 14 Jul 2012 22:32:29 +0000 Subject: [PATCH 38/51] Hash: `std::shared_ptr`, `std::unique_ptr` support. [SVN r79516] --- hash/test/Jamfile.v2 | 1 + hash/test/hash_std_smart_ptr_test.cpp | 80 +++++++++++++++++++ .../hash/detail/container_fwd_0x.hpp | 14 ++++ include/boost/functional/hash/extensions.hpp | 12 +++ 4 files changed, 107 insertions(+) create mode 100644 hash/test/hash_std_smart_ptr_test.cpp diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index 47f0a95..fc731d2 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -42,6 +42,7 @@ test-suite functional/hash [ run hash_type_index_test.cpp ] [ run hash_std_array_test.cpp ] [ run hash_std_tuple_test.cpp ] + [ run hash_std_smart_ptr_test.cpp ] [ run link_test.cpp link_test_2.cpp ] [ run link_ext_test.cpp link_no_ext_test.cpp ] [ run extensions_hpp_test.cpp ] diff --git a/hash/test/hash_std_smart_ptr_test.cpp b/hash/test/hash_std_smart_ptr_test.cpp new file mode 100644 index 0000000..83e705b --- /dev/null +++ b/hash/test/hash_std_smart_ptr_test.cpp @@ -0,0 +1,80 @@ + +// Copyright 2012 Daniel James. +// 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 "./config.hpp" + +#ifdef TEST_STD_INCLUDES +# include +#else +# include +#endif + +#include +#include "./compile_time.hpp" + +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_TUPLE) +#define TEST_SMART_PTRS +#include +#endif + +#ifdef TEST_SMART_PTRS + +void shared_ptr_tests() +{ + std::shared_ptr x; + compile_time_tests(&x); + + HASH_NAMESPACE::hash > x1; + HASH_NAMESPACE::hash > x2; + + std::shared_ptr ptr1(new int(10)); + std::shared_ptr ptr2; + + BOOST_TEST(x1(x) == x2(ptr2)); + BOOST_TEST(x1(x) != x2(ptr1)); + ptr2.reset(new int(10)); + BOOST_TEST(x1(ptr1) == x2(ptr1)); + BOOST_TEST(x1(ptr1) != x2(ptr2)); + ptr2 = ptr1; + BOOST_TEST(x1(ptr1) == x2(ptr2)); +#if defined(TEST_EXTENSIONS) + BOOST_TEST(x1(x) == HASH_NAMESPACE::hash_value(x)); + BOOST_TEST(x1(ptr1) == HASH_NAMESPACE::hash_value(ptr2)); +#endif +} + +void unique_ptr_tests() +{ + std::unique_ptr x; + compile_time_tests(&x); + + HASH_NAMESPACE::hash > x1; + HASH_NAMESPACE::hash > x2; + + std::unique_ptr ptr1(new int(10)); + std::unique_ptr ptr2; + + BOOST_TEST(x1(x) == x2(ptr2)); + BOOST_TEST(x1(x) != x2(ptr1)); + ptr2.reset(new int(10)); + BOOST_TEST(x1(ptr1) == x2(ptr1)); + BOOST_TEST(x1(ptr1) != x2(ptr2)); + +#if defined(TEST_EXTENSIONS) + BOOST_TEST(x1(x) == HASH_NAMESPACE::hash_value(x)); +#endif +} + +#endif + +int main() +{ +#ifdef TEST_SMART_PTRS + shared_ptr_tests(); + unique_ptr_tests(); +#endif + + return boost::report_errors(); +} diff --git a/include/boost/functional/hash/detail/container_fwd_0x.hpp b/include/boost/functional/hash/detail/container_fwd_0x.hpp index 442ec6c..4e2dd7e 100644 --- a/include/boost/functional/hash/detail/container_fwd_0x.hpp +++ b/include/boost/functional/hash/detail/container_fwd_0x.hpp @@ -38,4 +38,18 @@ namespace std { # endif #endif +// std::shared_ptr/std::unique_ptr + +#if !defined(BOOST_NO_CXX11_HDR_MEMORY) +# if (defined(BOOST_DETAIL_NO_CONTAINER_FWD) && \ + !defined(BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD)) +# include +# else +namespace std { + template class shared_ptr; + template class unique_ptr; +} +# endif +#endif + #endif diff --git a/include/boost/functional/hash/extensions.hpp b/include/boost/functional/hash/extensions.hpp index 9c4a6be..dc59b45 100644 --- a/include/boost/functional/hash/extensions.hpp +++ b/include/boost/functional/hash/extensions.hpp @@ -177,6 +177,18 @@ namespace boost # undef BOOST_HASH_TUPLE_F #endif +#endif + +#if !defined(BOOST_NO_CXX11_HDR_MEMORY) + template + inline std::size_t hash_value(std::shared_ptr const& x) { + return boost::hash_value(x.get()); + } + + template + inline std::size_t hash_value(std::unique_ptr const& x) { + return boost::hash_value(x.get()); + } #endif // From 1a126042f840a9799c8000c304d20ce38cb28386 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 15 Jul 2012 07:43:40 +0000 Subject: [PATCH 39/51] Hash: Fix smart pointer macro check. [SVN r79527] --- hash/test/hash_std_smart_ptr_test.cpp | 2 +- include/boost/functional/hash/extensions.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hash/test/hash_std_smart_ptr_test.cpp b/hash/test/hash_std_smart_ptr_test.cpp index 83e705b..7452585 100644 --- a/hash/test/hash_std_smart_ptr_test.cpp +++ b/hash/test/hash_std_smart_ptr_test.cpp @@ -14,7 +14,7 @@ #include #include "./compile_time.hpp" -#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_TUPLE) +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_SMART_PTR) #define TEST_SMART_PTRS #include #endif diff --git a/include/boost/functional/hash/extensions.hpp b/include/boost/functional/hash/extensions.hpp index dc59b45..4358736 100644 --- a/include/boost/functional/hash/extensions.hpp +++ b/include/boost/functional/hash/extensions.hpp @@ -179,7 +179,7 @@ namespace boost #endif -#if !defined(BOOST_NO_CXX11_HDR_MEMORY) +#if !defined(BOOST_NO_CXX11_SMART_PTR) template inline std::size_t hash_value(std::shared_ptr const& x) { return boost::hash_value(x.get()); From d7589fdd711125169dcca649d811f2fc4756b520 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 22 Jul 2012 07:15:34 +0000 Subject: [PATCH 40/51] Compile error for deprecated header `boost/functional/detail/container_fwd.hpp`. [SVN r79652] --- hash/test/Jamfile.v2 | 2 +- hash/test/deprecated_container_fwd.cpp | 8 -------- .../boost/functional/detail/container_fwd.hpp | 19 +------------------ 3 files changed, 2 insertions(+), 27 deletions(-) diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index fc731d2..07df1a0 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -51,7 +51,7 @@ test-suite functional/hash [ run implicit_test.cpp ] [ run hash_no_ext_macro_1.cpp ] [ run hash_no_ext_macro_2.cpp ] - [ compile deprecated_container_fwd.cpp ] + [ compile-fail deprecated_container_fwd.cpp ] ; test-suite functional/hash_no_ext diff --git a/hash/test/deprecated_container_fwd.cpp b/hash/test/deprecated_container_fwd.cpp index 1c6e12b..8238bda 100644 --- a/hash/test/deprecated_container_fwd.cpp +++ b/hash/test/deprecated_container_fwd.cpp @@ -4,11 +4,3 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include - -typedef std::vector > int_vector; - -#include - -int main() { - int_vector x; -} diff --git a/include/boost/functional/detail/container_fwd.hpp b/include/boost/functional/detail/container_fwd.hpp index e2bf865..6970472 100644 --- a/include/boost/functional/detail/container_fwd.hpp +++ b/include/boost/functional/detail/container_fwd.hpp @@ -7,21 +7,4 @@ // This header is deprecated, I'll change the warning to an error in a future // release, and then later remove the header completely. -#if !defined(BOOST_FUNCTIONAL_DETAIL_CONTAINER_FWD_HPP) -#define BOOST_FUNCTIONAL_DETAIL_CONTAINER_FWD_HPP - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#if defined(__EDG__) -#elif defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__) -#pragma message("Warning: boost/functional/detail/container_fwd.hpp is deprecated, use boost/detail/container_fwd.hpp instead.") -#elif defined(__GNUC__) || defined(__HP_aCC) || \ - defined(__SUNPRO_CC) || defined(__IBMCPP__) -#warning "boost/functional/detail/container_fwd.hpp is deprecated, use boost/detail/container_fwd.hpp instead." -#endif - -#include - -#endif +#error "boost/functional/detail/container_fwd.hpp is deprecated, use boost/detail/container_fwd.hpp instead." From f34fb9d65908a94837e8fb977f27d6132aa5a554 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Wed, 25 Jul 2012 23:42:41 +0000 Subject: [PATCH 41/51] Hash: Fix links to examples. [SVN r79749] --- hash/doc/tutorial.qbk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hash/doc/tutorial.qbk b/hash/doc/tutorial.qbk index 916ab93..59067a7 100644 --- a/hash/doc/tutorial.qbk +++ b/hash/doc/tutorial.qbk @@ -206,7 +206,7 @@ header which forward declares [classref boost::hash], include the main header before instantiating [classref boost::hash]. When using a container that uses [classref boost::hash] it should do that for you, so your type will work fine with the boost hash containers. There's an example of this -in [@boost:/libs/unordered/examples/template.hpp template.hpp] and -[@boost:/libs/unordered/examples/template.cpp template.cpp]. +in [@boost:/libs/functional/hash/examples/template.hpp template.hpp] and +[@boost:/libs/functional/hash/examples/template.cpp template.cpp]. [endsect] From 75aeb563ae2c58ded54e96a442321983ff0fde13 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Tue, 14 Aug 2012 20:06:07 +0000 Subject: [PATCH 42/51] Hash: Remove C++11 forward declarations. It seems that on Visual C++ Dinkumware declares shared_ptr in std, but for Intel C++ it imports it from std::tr1. I was thinking of doing a macro check for this, but since we're close to release, just change it to always include the headers and never forward declare the C++11 classes, which is much safer. I might restore the forward declarations in the future, although I'm tempted not to. I'm not sure the improvement in compile time is worth the hassle. [SVN r80038] --- .../hash/detail/container_fwd_0x.hpp | 32 ++----------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/include/boost/functional/hash/detail/container_fwd_0x.hpp b/include/boost/functional/hash/detail/container_fwd_0x.hpp index 4e2dd7e..bed7730 100644 --- a/include/boost/functional/hash/detail/container_fwd_0x.hpp +++ b/include/boost/functional/hash/detail/container_fwd_0x.hpp @@ -11,45 +11,19 @@ // std::array #if !defined(BOOST_NO_CXX11_HDR_ARRAY) - // Don't forward declare std::array for Dinkumware, as it seems to be - // just 'using std::tr1::array'. -# if (defined(BOOST_DETAIL_NO_CONTAINER_FWD) && \ - !defined(BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD)) || \ - (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER) -# include -# else -namespace std { - template class array; -} -# endif +# include #endif // std::tuple #if !defined(BOOST_NO_CXX11_HDR_TUPLE) -# if (defined(BOOST_DETAIL_NO_CONTAINER_FWD) && \ - !defined(BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD)) || \ - defined(BOOST_NO_VARIADIC_TEMPLATES) -# include -# else -namespace std { - template class tuple; -} -# endif +# include #endif // std::shared_ptr/std::unique_ptr #if !defined(BOOST_NO_CXX11_HDR_MEMORY) -# if (defined(BOOST_DETAIL_NO_CONTAINER_FWD) && \ - !defined(BOOST_DETAIL_TEST_FORCE_CONTAINER_FWD)) -# include -# else -namespace std { - template class shared_ptr; - template class unique_ptr; -} -# endif +# include #endif #endif From b286131642a1ae75045be2895c8c3241ebabe85b Mon Sep 17 00:00:00 2001 From: Daniel James Date: Wed, 22 Aug 2012 11:40:27 +0000 Subject: [PATCH 43/51] Hash: Quick attempt at supporting enums. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Filip Konvička. [SVN r80139] --- hash/test/Jamfile.v2 | 1 + hash/test/hash_enum_test.cpp | 59 ++++++++++++++++++++++++++ include/boost/functional/hash/hash.hpp | 13 ++++++ 3 files changed, 73 insertions(+) create mode 100644 hash/test/hash_enum_test.cpp diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index 07df1a0..0f41d3e 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -22,6 +22,7 @@ test-suite functional/hash [ run hash_fwd_test_1.cpp ] [ run hash_fwd_test_2.cpp ] [ run hash_number_test.cpp ] + [ run hash_enum_test.cpp ] [ run hash_pointer_test.cpp ] [ run hash_function_pointer_test.cpp ] [ run hash_float_test.cpp ] diff --git a/hash/test/hash_enum_test.cpp b/hash/test/hash_enum_test.cpp new file mode 100644 index 0000000..d17b608 --- /dev/null +++ b/hash/test/hash_enum_test.cpp @@ -0,0 +1,59 @@ + +// Copyright 2012 Daniel James. +// 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 "./config.hpp" + +#ifdef TEST_STD_INCLUDES +# include +#else +# include +#endif + +#include + +#include +#include + +namespace test { + enum enum_override { enum_override1, enum_override2 }; + std::size_t hash_value(enum_override x) { return -896532; } + + enum enum1 { enum1a }; + enum enum2 { enum2a, enum2b }; + enum enum3 { enum3a = 574, enum3b }; + enum enum4 { enum4a = -12574, enum4b }; +} + +int main() { + boost::hash hash1; + boost::hash hash2; + boost::hash hash3; + boost::hash hash4; + + BOOST_TEST(hash1(test::enum1a) == hash1(test::enum1a)); + + BOOST_TEST(hash2(test::enum2a) == hash2(test::enum2a)); + BOOST_TEST(hash2(test::enum2a) != hash2(test::enum2b)); + BOOST_TEST(hash2(test::enum2b) == hash2(test::enum2b)); + + BOOST_TEST(hash3(test::enum3a) == hash3(test::enum3a)); + BOOST_TEST(hash3(test::enum3a) != hash3(test::enum3b)); + BOOST_TEST(hash3(test::enum3b) == hash3(test::enum3b)); + + BOOST_TEST(hash4(test::enum4a) == hash4(test::enum4a)); + BOOST_TEST(hash4(test::enum4a) != hash4(test::enum4b)); + BOOST_TEST(hash4(test::enum4b) == hash4(test::enum4b)); + + boost::hash hash_override; + + BOOST_TEST(hash_override(test::enum_override1) == + hash_override(test::enum_override1)); + BOOST_TEST(hash_override(test::enum_override1) == + hash_override(test::enum_override2)); + BOOST_TEST(hash_override(test::enum_override1) == + hash_override(test::enum_override1)); + + return boost::report_errors(); +} diff --git a/include/boost/functional/hash/hash.hpp b/include/boost/functional/hash/hash.hpp index c179fab..647fd68 100644 --- a/include/boost/functional/hash/hash.hpp +++ b/include/boost/functional/hash/hash.hpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #include @@ -90,6 +92,10 @@ namespace boost template typename boost::hash_detail::ulong_numbers::type hash_value(T); + template + typename boost::enable_if, std::size_t>::type + hash_value(T); + #if !BOOST_WORKAROUND(__DMC__, <= 0x848) template std::size_t hash_value(T* const&); #else @@ -179,6 +185,13 @@ namespace boost return hash_detail::hash_value_unsigned(v); } + template + typename boost::enable_if, std::size_t>::type + hash_value(T v) + { + return static_cast(v); + } + // Implementation by Alberto Barbati and Dave Harris. #if !BOOST_WORKAROUND(__DMC__, <= 0x848) template std::size_t hash_value(T* const& v) From 9fc50e56e54fc2f6f03daa5312d6ab1c2b7e14c2 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 23 Aug 2012 12:18:18 +0000 Subject: [PATCH 44/51] Hash: Clean up some unit tests. - Remove some unnecessary headers. - Try to fix warning in enum tests. - Compile tests + hash namespace in enum tests. [SVN r80154] --- hash/test/hash_enum_test.cpp | 22 +++++++++++++--------- hash/test/hash_function_pointer_test.cpp | 4 ---- hash/test/hash_number_test.cpp | 2 -- hash/test/hash_pointer_test.cpp | 4 ---- hash/test/hash_range_test.cpp | 3 --- hash/test/hash_string_test.cpp | 4 ---- 6 files changed, 13 insertions(+), 26 deletions(-) diff --git a/hash/test/hash_enum_test.cpp b/hash/test/hash_enum_test.cpp index d17b608..30444e5 100644 --- a/hash/test/hash_enum_test.cpp +++ b/hash/test/hash_enum_test.cpp @@ -12,13 +12,11 @@ #endif #include - -#include -#include +#include "./compile_time.hpp" namespace test { enum enum_override { enum_override1, enum_override2 }; - std::size_t hash_value(enum_override x) { return -896532; } + std::size_t hash_value(enum_override) { return 896532; } enum enum1 { enum1a }; enum enum2 { enum2a, enum2b }; @@ -27,10 +25,16 @@ namespace test { } int main() { - boost::hash hash1; - boost::hash hash2; - boost::hash hash3; - boost::hash hash4; + compile_time_tests((test::enum1*) 0); + compile_time_tests((test::enum2*) 0); + compile_time_tests((test::enum3*) 0); + compile_time_tests((test::enum4*) 0); + compile_time_tests((test::enum_override*) 0); + + HASH_NAMESPACE::hash hash1; + HASH_NAMESPACE::hash hash2; + HASH_NAMESPACE::hash hash3; + HASH_NAMESPACE::hash hash4; BOOST_TEST(hash1(test::enum1a) == hash1(test::enum1a)); @@ -46,7 +50,7 @@ int main() { BOOST_TEST(hash4(test::enum4a) != hash4(test::enum4b)); BOOST_TEST(hash4(test::enum4b) == hash4(test::enum4b)); - boost::hash hash_override; + HASH_NAMESPACE::hash hash_override; BOOST_TEST(hash_override(test::enum_override1) == hash_override(test::enum_override1)); diff --git a/hash/test/hash_function_pointer_test.cpp b/hash/test/hash_function_pointer_test.cpp index 73719e2..a73b718 100644 --- a/hash/test/hash_function_pointer_test.cpp +++ b/hash/test/hash_function_pointer_test.cpp @@ -12,10 +12,6 @@ #endif #include - -#include -#include - #include "./compile_time.hpp" void void_func1() { static int x = 1; ++x; } diff --git a/hash/test/hash_number_test.cpp b/hash/test/hash_number_test.cpp index b233c71..2645dfa 100644 --- a/hash/test/hash_number_test.cpp +++ b/hash/test/hash_number_test.cpp @@ -16,8 +16,6 @@ #include #include -#include -#include #include "./compile_time.hpp" diff --git a/hash/test/hash_pointer_test.cpp b/hash/test/hash_pointer_test.cpp index 5fcbc27..b255a28 100644 --- a/hash/test/hash_pointer_test.cpp +++ b/hash/test/hash_pointer_test.cpp @@ -12,11 +12,7 @@ #endif #include - #include -#include -#include - #include "./compile_time.hpp" void pointer_tests() diff --git a/hash/test/hash_range_test.cpp b/hash/test/hash_range_test.cpp index 8743e1e..f5fdb2a 100644 --- a/hash/test/hash_range_test.cpp +++ b/hash/test/hash_range_test.cpp @@ -18,10 +18,7 @@ int main() {} #endif #include - #include -#include -#include #include void hash_range_tests() diff --git a/hash/test/hash_string_test.cpp b/hash/test/hash_string_test.cpp index b3b8394..29ff28e 100644 --- a/hash/test/hash_string_test.cpp +++ b/hash/test/hash_string_test.cpp @@ -12,11 +12,7 @@ #endif #include - -#include -#include #include - #include "./compile_time.hpp" void string_tests() From 2f6cb78b80425ca13b6c8d72c52dcc4918fb43ec Mon Sep 17 00:00:00 2001 From: Daniel James Date: Fri, 24 Aug 2012 22:52:42 +0000 Subject: [PATCH 45/51] Hash: A single unified algorithm for hashing floats. Attempts to automatically use a binary hash for floats where it's known to work, and then use the generic hash algorithm as a fallback. [SVN r80177] --- hash/test/Jamfile.v2 | 15 +- .../functional/hash/detail/hash_float.hpp | 182 ++++++++++++++++-- .../hash/detail/hash_float_generic.hpp | 91 --------- .../functional/hash/detail/hash_float_x86.hpp | 56 ------ 4 files changed, 182 insertions(+), 162 deletions(-) delete mode 100644 include/boost/functional/hash/detail/hash_float_generic.hpp delete mode 100644 include/boost/functional/hash/detail/hash_float_x86.hpp diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index 0f41d3e..5b7c39a 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -1,5 +1,5 @@ -# Copyright 2005-2011 Daniel James. +# Copyright 2005-2012 Daniel James. # 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) @@ -66,4 +66,17 @@ test-suite functional/hash_no_ext [ run link_test.cpp link_test_2.cpp : : : BOOST_HASH_NO_EXTENSIONS : no_ext_link_test ] ; +# Tests to see if the floating point hash is using the binary hash. +# Not run normally because on some platforms these should fail. +test-suite functional/hash_no_generic_float + : + [ run hash_float_test.cpp + : : : BOOST_HASH_DETAIL_TEST_WITHOUT_GENERIC + : hash_float_test_no_generic ] + [ run hash_long_double_test.cpp + : : : BOOST_HASH_DETAIL_TEST_WITHOUT_GENERIC + : hash_long_double_test_no_generic ] + ; +explicit functional/hash_no_generic_float ; + build-project ../examples ; diff --git a/include/boost/functional/hash/detail/hash_float.hpp b/include/boost/functional/hash/detail/hash_float.hpp index 194be1c..7ccfb80 100644 --- a/include/boost/functional/hash/detail/hash_float.hpp +++ b/include/boost/functional/hash/detail/hash_float.hpp @@ -1,5 +1,5 @@ -// Copyright 2005-2009 Daniel James. +// Copyright 2005-2012 Daniel James. // 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) @@ -13,21 +13,19 @@ #include #include #include +#include #include #include #include +#include +#include -// Include hash implementation for the current platform. - -// Cygwn -#if defined(__CYGWIN__) -# if defined(__i386__) || defined(_M_IX86) -# include -# else -# include -# endif -#else -# include +#if defined(BOOST_MSVC) +#pragma warning(push) +#if BOOST_MSVC >= 1400 +#pragma warning(disable:6294) // Ill-defined for-loop: initial condition does + // not satisfy test. Loop body not executed +#endif #endif // Can we use fpclassify? @@ -50,6 +48,158 @@ # define BOOST_HASH_USE_FPCLASSIFY 0 #endif +namespace boost +{ + namespace hash_detail + { + inline void hash_float_combine(std::size_t& seed, std::size_t value) + { + seed ^= value + (seed<<6) + (seed>>2); + } + + //////////////////////////////////////////////////////////////////////// + // Binary hash function + // + // Only used for floats with known iec559 floats, and certain values in + // numeric_limits + + inline std::size_t hash_binary(char* ptr, std::size_t length) + { + std::size_t seed = 0; + + if (length >= sizeof(std::size_t)) { + seed = *(std::size_t*) ptr; + length -= sizeof(std::size_t); + ptr += sizeof(std::size_t); + + while(length >= sizeof(std::size_t)) { + hash_float_combine(seed, *(std::size_t*) ptr); + length -= sizeof(std::size_t); + ptr += sizeof(std::size_t); + } + } + + if (length > 0) { + std::size_t buffer = 0; + std::memcpy(&buffer, ptr, length); + hash_float_combine(seed, buffer); + } + + return seed; + } + + template + inline std::size_t float_hash_impl(Float v, + BOOST_DEDUCED_TYPENAME boost::enable_if_c< + std::numeric_limits::is_iec559 && + std::numeric_limits::digits == 24 && + std::numeric_limits::radix == 2 && + std::numeric_limits::max_exponent == 128, + int>::type + ) + { + boost::uint32_t* ptr = (boost::uint32_t*)&v; + return (std::size_t) *ptr; + } + + + template + inline std::size_t float_hash_impl(Float v, + BOOST_DEDUCED_TYPENAME boost::enable_if_c< + std::numeric_limits::is_iec559 && + std::numeric_limits::digits == 53 && + std::numeric_limits::radix == 2 && + std::numeric_limits::max_exponent == 1024, + int>::type + ) + { + return hash_binary((char*) &v, 8); + } + + template + inline std::size_t float_hash_impl(Float v, + BOOST_DEDUCED_TYPENAME boost::enable_if_c< + std::numeric_limits::is_iec559 && + std::numeric_limits::digits == 64 && + std::numeric_limits::radix == 2 && + std::numeric_limits::max_exponent == 16384, + int>::type + ) + { + return hash_binary((char*) &v, 10); + } + + template + inline std::size_t float_hash_impl(Float v, + BOOST_DEDUCED_TYPENAME boost::enable_if_c< + std::numeric_limits::is_iec559 && + std::numeric_limits::digits == 113 && + std::numeric_limits::radix == 2 && + std::numeric_limits::max_exponent == 16384, + int>::type + ) + { + return hash_binary((char*) &v, 16); + } + + //////////////////////////////////////////////////////////////////////// + // Portable hash function + // + // Used as a fallback when the binary hash function isn't supported. + + template + inline std::size_t float_hash_impl2(T v) + { + boost::hash_detail::call_frexp frexp; + boost::hash_detail::call_ldexp ldexp; + + int exp = 0; + + v = frexp(v, &exp); + + // A postive value is easier to hash, so combine the + // sign with the exponent and use the absolute value. + if(v < 0) { + v = -v; + exp += limits::max_exponent - + limits::min_exponent; + } + + v = ldexp(v, limits::digits); + std::size_t seed = static_cast(v); + v -= static_cast(seed); + + // ceiling(digits(T) * log2(radix(T))/ digits(size_t)) - 1; + std::size_t const length + = (limits::digits * + boost::static_log2::radix>::value + + limits::digits - 1) + / limits::digits; + + for(std::size_t i = 0; i != length; ++i) + { + v = ldexp(v, limits::digits); + std::size_t part = static_cast(v); + v -= static_cast(part); + hash_float_combine(seed, part); + } + + hash_float_combine(seed, exp); + + return seed; + } + +#if !defined(BOOST_HASH_DETAIL_TEST_WITHOUT_GENERIC) + template + inline std::size_t float_hash_impl(T v, ...) + { + typedef BOOST_DEDUCED_TYPENAME select_hash_type::type type; + return float_hash_impl2(static_cast(v)); + } +#endif + } +} + #if BOOST_HASH_USE_FPCLASSIFY #include @@ -71,7 +221,7 @@ namespace boost return (std::size_t)(-3); case FP_NORMAL: case FP_SUBNORMAL: - return float_hash_impl(v); + return float_hash_impl(v, 0); default: BOOST_ASSERT(0); return 0; @@ -103,7 +253,7 @@ namespace boost template inline std::size_t float_hash_value(T v) { - return boost::hash_detail::is_zero(v) ? 0 : float_hash_impl(v); + return boost::hash_detail::is_zero(v) ? 0 : float_hash_impl(v, 0); } } } @@ -112,4 +262,8 @@ namespace boost #undef BOOST_HASH_USE_FPCLASSIFY +#if defined(BOOST_MSVC) +#pragma warning(pop) +#endif + #endif diff --git a/include/boost/functional/hash/detail/hash_float_generic.hpp b/include/boost/functional/hash/detail/hash_float_generic.hpp deleted file mode 100644 index 1278c2f..0000000 --- a/include/boost/functional/hash/detail/hash_float_generic.hpp +++ /dev/null @@ -1,91 +0,0 @@ - -// Copyright 2005-2009 Daniel James. -// 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) - -// A general purpose hash function for non-zero floating point values. - -#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_GENERIC_HEADER) -#define BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_GENERIC_HEADER - -#include -#include -#include - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#if defined(BOOST_MSVC) -#pragma warning(push) -#if BOOST_MSVC >= 1400 -#pragma warning(disable:6294) // Ill-defined for-loop: initial condition does - // not satisfy test. Loop body not executed -#endif -#endif - -namespace boost -{ - namespace hash_detail - { - inline void hash_float_combine(std::size_t& seed, std::size_t value) - { - seed ^= value + (seed<<6) + (seed>>2); - } - - template - inline std::size_t float_hash_impl2(T v) - { - boost::hash_detail::call_frexp frexp; - boost::hash_detail::call_ldexp ldexp; - - int exp = 0; - - v = frexp(v, &exp); - - // A postive value is easier to hash, so combine the - // sign with the exponent and use the absolute value. - if(v < 0) { - v = -v; - exp += limits::max_exponent - - limits::min_exponent; - } - - v = ldexp(v, limits::digits); - std::size_t seed = static_cast(v); - v -= static_cast(seed); - - // ceiling(digits(T) * log2(radix(T))/ digits(size_t)) - 1; - std::size_t const length - = (limits::digits * - boost::static_log2::radix>::value - + limits::digits - 1) - / limits::digits; - - for(std::size_t i = 0; i != length; ++i) - { - v = ldexp(v, limits::digits); - std::size_t part = static_cast(v); - v -= static_cast(part); - hash_float_combine(seed, part); - } - - hash_float_combine(seed, exp); - - return seed; - } - - template - inline std::size_t float_hash_impl(T v) - { - typedef BOOST_DEDUCED_TYPENAME select_hash_type::type type; - return float_hash_impl2(static_cast(v)); - } - } -} - -#if defined(BOOST_MSVC) -#pragma warning(pop) -#endif - -#endif diff --git a/include/boost/functional/hash/detail/hash_float_x86.hpp b/include/boost/functional/hash/detail/hash_float_x86.hpp deleted file mode 100644 index b39bb0d..0000000 --- a/include/boost/functional/hash/detail/hash_float_x86.hpp +++ /dev/null @@ -1,56 +0,0 @@ - -// Copyright 2005-2009 Daniel James. -// 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) - -// A non-portable hash function form non-zero floats on x86. -// -// Even if you're on an x86 platform, this might not work if their floating -// point isn't set up as this expects. So this should only be used if it's -// absolutely certain that it will work. - -#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_X86_HEADER) -#define BOOST_FUNCTIONAL_HASH_DETAIL_HASH_FLOAT_X86_HEADER - -#include - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -namespace boost -{ - namespace hash_detail - { - inline void hash_float_combine(std::size_t& seed, std::size_t value) - { - seed ^= value + (seed<<6) + (seed>>2); - } - - inline std::size_t float_hash_impl(float v) - { - boost::uint32_t* ptr = (boost::uint32_t*)&v; - std::size_t seed = *ptr; - return seed; - } - - inline std::size_t float_hash_impl(double v) - { - boost::uint32_t* ptr = (boost::uint32_t*)&v; - std::size_t seed = *ptr++; - hash_float_combine(seed, *ptr); - return seed; - } - - inline std::size_t float_hash_impl(long double v) - { - boost::uint32_t* ptr = (boost::uint32_t*)&v; - std::size_t seed = *ptr++; - hash_float_combine(seed, *ptr++); - hash_float_combine(seed, *(boost::uint16_t*)ptr); - return seed; - } - } -} - -#endif From 945d78bc4fd6e99c39f51ad46be26c8b9707464f Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 25 Aug 2012 20:54:10 +0000 Subject: [PATCH 46/51] Hash: Avoid type punning warning. [SVN r80217] --- include/boost/functional/hash/detail/hash_float.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/functional/hash/detail/hash_float.hpp b/include/boost/functional/hash/detail/hash_float.hpp index 7ccfb80..3edc6ab 100644 --- a/include/boost/functional/hash/detail/hash_float.hpp +++ b/include/boost/functional/hash/detail/hash_float.hpp @@ -98,8 +98,7 @@ namespace boost int>::type ) { - boost::uint32_t* ptr = (boost::uint32_t*)&v; - return (std::size_t) *ptr; + return hash_binary((char*) &v, 4); } From 9ad9e2537c2a05a7e9818e9b1065767fb0a9e844 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Tue, 28 Aug 2012 17:43:05 +0000 Subject: [PATCH 47/51] Remove deprecated header `boost/functional/detail/container_fwd.hpp` [SVN r80288] --- hash/test/Jamfile.v2 | 1 - hash/test/deprecated_container_fwd.cpp | 6 ------ include/boost/functional/detail/container_fwd.hpp | 10 ---------- 3 files changed, 17 deletions(-) delete mode 100644 hash/test/deprecated_container_fwd.cpp delete mode 100644 include/boost/functional/detail/container_fwd.hpp diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index 5b7c39a..34b69e6 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -52,7 +52,6 @@ test-suite functional/hash [ run implicit_test.cpp ] [ run hash_no_ext_macro_1.cpp ] [ run hash_no_ext_macro_2.cpp ] - [ compile-fail deprecated_container_fwd.cpp ] ; test-suite functional/hash_no_ext diff --git a/hash/test/deprecated_container_fwd.cpp b/hash/test/deprecated_container_fwd.cpp deleted file mode 100644 index 8238bda..0000000 --- a/hash/test/deprecated_container_fwd.cpp +++ /dev/null @@ -1,6 +0,0 @@ - -// Copyright 2012 Daniel James. -// 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 diff --git a/include/boost/functional/detail/container_fwd.hpp b/include/boost/functional/detail/container_fwd.hpp deleted file mode 100644 index 6970472..0000000 --- a/include/boost/functional/detail/container_fwd.hpp +++ /dev/null @@ -1,10 +0,0 @@ - -// Copyright 2005-2012 Daniel James. -// 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) - -// Forwarding header for container_fwd.hpp's new location. -// This header is deprecated, I'll change the warning to an error in a future -// release, and then later remove the header completely. - -#error "boost/functional/detail/container_fwd.hpp is deprecated, use boost/detail/container_fwd.hpp instead." From 7b3efa91b9c8c9addc7602ef19a0544fda7acda4 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 30 Sep 2012 11:56:13 +0000 Subject: [PATCH 48/51] Hash: Update change log [SVN r80777] --- hash/doc/changes.qbk | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hash/doc/changes.qbk b/hash/doc/changes.qbk index 3aa3dee..c98bd86 100644 --- a/hash/doc/changes.qbk +++ b/hash/doc/changes.qbk @@ -132,4 +132,17 @@ * Add deprecation warning to the long deprecated `boost/functional/detail/container_fwd.hpp`. +[h2 Boost 1.51.0] + +* Support the standard smart pointers. +* `hash_value` now implemented using SFINAE to avoid implicit casts to built + in types when calling it. +* Updated to use the new config macros. + +[h2 Boost 1.52.0] + +* Restore `enum` support, which was accidentally removed in the last version. +* New floating point hasher - will hash the binary representation on more + platforms, which should be faster. + [endsect] From 9c2c4bb1fa7b0dfab6b771ccc49eceb83774d203 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 31 Oct 2012 17:14:43 +0000 Subject: [PATCH 49/51] Narrower 'using'; Refs #7470 [SVN r81122] --- include/boost/functional/hash/detail/hash_float.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/functional/hash/detail/hash_float.hpp b/include/boost/functional/hash/detail/hash_float.hpp index 3edc6ab..5fcac60 100644 --- a/include/boost/functional/hash/detail/hash_float.hpp +++ b/include/boost/functional/hash/detail/hash_float.hpp @@ -210,7 +210,7 @@ namespace boost template inline std::size_t float_hash_value(T v) { - using namespace std; + using namespace std::fpclassify; switch (fpclassify(v)) { case FP_ZERO: return 0; From 376d6bd5eb5a86444f9ddb2bb5e80720794765ac Mon Sep 17 00:00:00 2001 From: Daniel James Date: Wed, 31 Oct 2012 19:05:25 +0000 Subject: [PATCH 50/51] Hash: Revert r81122. Refs #7470. I'll get back to this later, it probably requires compiler specific changes. [SVN r81124] --- include/boost/functional/hash/detail/hash_float.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/functional/hash/detail/hash_float.hpp b/include/boost/functional/hash/detail/hash_float.hpp index 5fcac60..3edc6ab 100644 --- a/include/boost/functional/hash/detail/hash_float.hpp +++ b/include/boost/functional/hash/detail/hash_float.hpp @@ -210,7 +210,7 @@ namespace boost template inline std::size_t float_hash_value(T v) { - using namespace std::fpclassify; + using namespace std; switch (fpclassify(v)) { case FP_ZERO: return 0; From 06fe6a9cbac06e197997d72bd373d59ec3e29fb8 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 5 Nov 2012 18:33:54 +0000 Subject: [PATCH 51/51] Hash: Extra test to check different platform's floating point functions. [SVN r81210] --- hash/test/extra/Jamfile.v2 | 13 ++++++ hash/test/extra/check_float_funcs.cpp | 58 +++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 hash/test/extra/Jamfile.v2 create mode 100644 hash/test/extra/check_float_funcs.cpp diff --git a/hash/test/extra/Jamfile.v2 b/hash/test/extra/Jamfile.v2 new file mode 100644 index 0000000..243c1b1 --- /dev/null +++ b/hash/test/extra/Jamfile.v2 @@ -0,0 +1,13 @@ + +# Copyright 2012 Daniel James. +# 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) + +import testing ; + +build-project .. ; + +test-suite functional/hash/config + : + [ compile check_float_funcs.cpp ] + ; \ No newline at end of file diff --git a/hash/test/extra/check_float_funcs.cpp b/hash/test/extra/check_float_funcs.cpp new file mode 100644 index 0000000..a937082 --- /dev/null +++ b/hash/test/extra/check_float_funcs.cpp @@ -0,0 +1,58 @@ + +// Copyright 2012 Daniel James. +// 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 +#include +#include +#include + +namespace test +{ + template + struct check_return_type + { + template + static void equals(T2) + { + BOOST_STATIC_ASSERT((boost::is_same::value)); + } + + template + static void equals_ref(T2&) + { + BOOST_STATIC_ASSERT((boost::is_same::value)); + } + + template + static void convertible(T2) + { + BOOST_STATIC_ASSERT((boost::is_convertible::value)); + } + }; +} + +int main() { + float f = 0; + double d = 0; + long double l = 0; + + test::check_return_type::equals(std::ldexp(f, 0)); + test::check_return_type::equals(std::ldexp(d, 0)); + test::check_return_type::equals(std::ldexp(l, 0)); + + int dummy = 0; + + test::check_return_type::equals(std::frexp(f, &dummy)); + test::check_return_type::equals(std::frexp(d, &dummy)); + test::check_return_type::equals(std::frexp(l, &dummy)); + +#if BOOST_HASH_USE_FPCLASSIFY + + int (*fpc1)(float) = std::fpclassify; + int (*fpc2)(double) = std::fpclassify; + int (*fpc3)(long double) = std::fpclassify; + +#endif +} \ No newline at end of file