$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r76552 - in sandbox/closure: boost/closure/aux_/preprocessor/traits/decl_sign_ boost/functional boost/functional/detail libs/closure/example libs/functional libs/functional/test
From: lorcaminiti_at_[hidden]
Date: 2012-01-17 10:19:23
Author: lcaminiti
Date: 2012-01-17 10:19:21 EST (Tue, 17 Jan 2012)
New Revision: 76552
URL: http://svn.boost.org/trac/boost/changeset/76552
Log:
Adding overload and make_overload to Boost.Functional.
Added:
   sandbox/closure/boost/functional/config.hpp   (contents, props changed)
   sandbox/closure/boost/functional/detail/function_type.hpp   (contents, props changed)
   sandbox/closure/libs/closure/example/add_lambda.cpp   (contents, props changed)
   sandbox/closure/libs/closure/example/gcc_lambda.cpp   (contents, props changed)
   sandbox/closure/libs/closure/example/gcc_lambda.hpp   (contents, props changed)
   sandbox/closure/libs/closure/example/gcc_lambda_cpp11.cpp   (contents, props changed)
   sandbox/closure/libs/functional/
   sandbox/closure/libs/functional/test/
   sandbox/closure/libs/functional/test/overload.cpp   (contents, props changed)
Removed:
   sandbox/closure/boost/closure/aux_/preprocessor/traits/decl_sign_/is_void.hpp
Deleted: sandbox/closure/boost/closure/aux_/preprocessor/traits/decl_sign_/is_void.hpp
==============================================================================
--- sandbox/closure/boost/closure/aux_/preprocessor/traits/decl_sign_/is_void.hpp	2012-01-17 10:19:21 EST (Tue, 17 Jan 2012)
+++ (empty file)
@@ -1,54 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-#ifndef BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID_HPP_
-#define BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID_HPP_
-
-#include <boost/closure/config.hpp>
-#include <boost/closure/detail/preprocessor/keyword/void.hpp>
-#include <boost/preprocessor/detail/is_unary.hpp>
-#include <boost/preprocessor/control/iif.hpp>
-#include <boost/preprocessor/facilities/is_empty.hpp>
-#include <boost/preprocessor/facilities/empty.hpp>
-#include <boost/preprocessor/seq/seq.hpp> // For `SEQ_HEAD`.
-
-// PRIVATE //
-
-#if defined(BOOST_CLOSURE_CONFIG_COMPLIANT)
-#   define BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID_TOKEN_ALLOW_EMPTY_ 0
-#else
-#   define BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID_TOKEN_ALLOW_EMPTY_ 1
-#endif
-
-#define BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID_TOKEN_(sign) \
-    BOOST_PP_IIF(BOOST_PP_IS_EMPTY(sign), \
-        /* handles empty params `()` as no params (C99 only) */ \
-        BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID_TOKEN_ALLOW_EMPTY_ \
-        BOOST_PP_EMPTY \
-    , \
-        BOOST_CLOSURE_DETAIL_PP_KEYWORD_IS_VOID_FRONT \
-    )(sign)
-
-#define BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID_SEQ_(sign) \
-    BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID_TOKEN_(BOOST_PP_SEQ_HEAD( \
-            sign))
-
-// PUBLIC //
-
-// Check is specified parenthesized sign empty (or void) list.
-// Expand to 1 iff sign is empty (C99 only), or `void` (supported also
-// for C++ but similar to unparenthesized sign syntax for C99), or `(void)`
-// (parenthesized sign syntax for C++).
-#define BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID(sign) \
-    BOOST_PP_IIF(BOOST_PP_IS_UNARY(sign), \
-        /* it's a pp-seq */ \
-        BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID_SEQ_ \
-    , /* else, it's a token */ \
-        BOOST_CLOSURE_AUX_PP_DECL_TRAITS_SIGN_IS_VOID_TOKEN_ \
-    )(sign)
-
-#endif // #include guard
-
Added: sandbox/closure/boost/functional/config.hpp
==============================================================================
--- (empty file)
+++ sandbox/closure/boost/functional/config.hpp	2012-01-17 10:19:21 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,14 @@
+
+#ifndef BOOST_FUNCTIONAL_CONFIG_HPP_
+#define BOOST_FUNCTIONAL_CONFIG_HPP_
+
+#ifndef BOOST_FUNCTIONAL_CONFIG_ARITY_MAX 
+#define BOOST_FUNCTIONAL_CONFIG_ARITY_MAX 5
+#endif
+
+#ifndef BOOST_FUNCTIONAL_CONFIG_OVERLOAD_MAX
+#define BOOST_FUNCTIONAL_CONFIG_OVERLOAD_MAX 5
+#endif
+
+#endif // #include guard
+
Added: sandbox/closure/boost/functional/detail/function_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/closure/boost/functional/detail/function_type.hpp	2012-01-17 10:19:21 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,67 @@
+
+#ifndef BOOST_FUNCTIONAL_DETAIL_FUNCTION_TYPE_HPP_
+#define BOOST_FUNCTIONAL_DETAIL_FUNCTION_TYPE_HPP_
+
+#include <boost/function_types/is_function.hpp>
+#include <boost/function_types/is_function_pointer.hpp>
+#include <boost/function_types/is_function_reference.hpp>
+#include <boost/function_types/function_type.hpp>
+#include <boost/function_types/parameter_types.hpp>
+#include <boost/function_types/result_type.hpp>
+#include <boost/type_traits/remove_pointer.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/pop_front.hpp>
+#include <boost/mpl/push_front.hpp>
+#include <boost/typeof/typeof.hpp>
+
+namespace boost { namespace functional { namespace detail {
+
+// Requires: F is a monomorphic functor (i.e., has non-template `operator()`).
+// Returns: F's function type `result_type (arg1_type, arg2_type, ...)`.
+// It does not assume F typedef result_type, arg1_type, ... but needs typeof.
+template<typename F>
+class functor_type {
+    typedef BOOST_TYPEOF_TPL(&(F::operator())) call_ptr;
+public:
+    typedef
+        typename boost::function_types::function_type<
+            typename boost::mpl::push_front<
+                  typename boost::mpl::pop_front< // Remove functor type (1st).
+                    typename boost::function_types::parameter_types<
+                            call_ptr>::type
+                  >::type
+                , typename boost::function_types::result_type<call_ptr>::type
+            >::type
+        >::type
+    type;
+};
+
+// Requires: F is a function type, pointer, reference, or monomorphic functor.
+// Returns: F's function type `result_type (arg1_type, arg2_type, ...)`.
+template<typename F>
+struct function_type {
+    typedef
+        typename boost::mpl::if_<boost::function_types::is_function<F>,
+            boost::mpl::identity<F>
+        ,
+            typename boost::mpl::if_<boost::function_types::
+                    is_function_pointer<F>,
+                boost::remove_pointer<F>
+            ,
+                typename boost::mpl::if_<boost::function_types::
+                        is_function_reference<F>,
+                    boost::remove_reference<F>
+                , // Requires, it's a functor.
+                    functor_type<F>
+                >::type
+            >::type
+        >::type
+    ::type type;
+};
+
+} } } // namespace
+
+#endif // #include guard
+
Added: sandbox/closure/libs/closure/example/add_lambda.cpp
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/closure/example/add_lambda.cpp	2012-01-17 10:19:21 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,22 @@
+
+//[example_add_lambda_cpp
+#include <boost/closure.hpp>
+#include <algorithm>
+#include <cstdlib>
+
+int main(void) {
+    int sum = 0, factor = 10;
+    
+    auto add = [factor, &sum](int num) {
+        sum += factor * num;
+    };
+    
+    add(1); // Call the lambda function.
+
+    int nums[] = {2, 3};
+    std::for_each(nums, nums + 2, add); // Pass the lambda to an algorithm.
+
+    return (sum == 60) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+//]
+
Added: sandbox/closure/libs/closure/example/gcc_lambda.cpp
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/closure/example/gcc_lambda.cpp	2012-01-17 10:19:21 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,21 @@
+
+//[example_add_cpp
+#include <gcc_lambda.hpp>
+#include <algorithm>
+#include <cstdlib>
+
+int main(void) {
+    int val = 2;
+    int nums[] = {1, 2, 3};
+    int* end = nums + 3;
+
+    int* iter = std::find_if(nums, end,
+        GCC_LAMBDA(const bind val, int num, return bool) {
+            return num == val;
+        } GCC_LAMDA_END
+    );
+
+    return (iter != end) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+//]
+
Added: sandbox/closure/libs/closure/example/gcc_lambda.hpp
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/closure/example/gcc_lambda.hpp	2012-01-17 10:19:21 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,34 @@
+
+//[example_gcc_lambda_hpp
+// Header: gcc_lambda.hpp
+#ifndef GCC_LAMBDA_HPP_
+#define GCC_LAMBDA_HPP_
+
+#include <boost/closure.hpp>
+
+// PUBLIC //
+
+// void | [const] bind[&] var_ | type_ name_ [, default value_] | return type_
+#define GCC_LAMBDA(...) \
+    ({ /* open a GCC expression statement (GCC extension only) */ \
+        BOOST_CLOSURE(GCC_LAMBDA_RETURN_( \
+                BOOST_CLOSURE_DETAIL_PP_VARIADIC_TO_SEQ(__VA_ARGS__)))
+
+#define GCC_LAMBDA_END \
+        BOOST_CLOSURE_END(BOOST_PP_CAT(gcc_lambda_, __LINE__)) \
+        BOOST_PP_CAT(gcc_lambda, __LINE__); /* expr stmt returns the lambda */ \
+    }) /* close the GCC expression statement (GCC extension only) */
+
+// PRIVATE //
+
+#define GCC_LAMBDA_RETURN_(sign_seq) \
+    BOOST_PP_IIF(BOOST_CLOSURE_DETAIL_PP_KEYWORD_IS_RETURN_FRONT( \
+            BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_REVERSE(sign_seq))), \
+        sign_seq /* keep result type specified by user */ \
+    , \
+        sign_seq (return void) /* automatically void if no return specified */ \
+    )
+
+#endif // #include guard
+//]
+
Added: sandbox/closure/libs/closure/example/gcc_lambda_cpp11.cpp
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/closure/example/gcc_lambda_cpp11.cpp	2012-01-17 10:19:21 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,20 @@
+
+//[example_add_cpp
+#include <algorithm>
+#include <cstdlib>
+
+int main(void) {
+    int val = 2;
+    int nums[] = {1, 2, 3};
+    int* end = nums + 3;
+
+    int* iter = std::find_if(nums, end, 
+        [val](int num) -> bool {
+            return num == val;
+        }
+    );
+
+    return (iter != end) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+//]
+
Added: sandbox/closure/libs/functional/test/overload.cpp
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/functional/test/overload.cpp	2012-01-17 10:19:21 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,58 @@
+
+#include <boost/functional/overload.hpp>
+#include <boost/function.hpp>
+#define BOOST_TEST_MODULE TestOverload
+#include <boost/test/unit_test.hpp>
+#include <string>
+
+//[test_overload_make_func
+template<typename F>
+void check(F identity) {
+    BOOST_CHECK( identity("abc") == "abc" );
+    BOOST_CHECK( identity(123) == 123 );
+    BOOST_CHECK( identity(1.23) == 1.23 );
+}
+//]
+
+//[test_overload_decls
+const std::string& identity_s(const std::string& x) { return x; }
+int identity_i(int x) { return x; }
+double identity_d_impl(double x) { return x; }
+boost::function<double (double)> identity_d = identity_d_impl;
+//]
+
+BOOST_AUTO_TEST_CASE( test_overload ) {
+    //[test_overload_funcs
+    BOOST_CHECK( identity_s("abc") == "abc" );
+    BOOST_CHECK( identity_i(123) == 123 );
+    BOOST_CHECK( identity_d(1.23) == 1.23 );
+    //]
+
+    {
+        //[test_overload_tpl
+        boost::functional::overload<
+              const std::string& (const std::string&)
+            , int (int)
+            , double (double)
+        > identity(identity_s, identity_i, identity_d);
+        BOOST_CHECK( identity("abc") == "abc" );
+        BOOST_CHECK( identity(123) == 123 );
+        BOOST_CHECK( identity(1.23) == 1.23 );
+        //]
+    }
+    
+    {
+        //[test_overload_make_var
+        BOOST_AUTO(identity, boost::functional::make_overload(
+                identity_s, identity_i, identity_d));
+        BOOST_CHECK( identity("abc") == "abc" );
+        BOOST_CHECK( identity(123) == 123 );
+        BOOST_CHECK( identity(1.23) == 1.23 );
+        //]
+    }
+
+    //[test_overload_make_func_call
+    check(boost::functional::make_overload(identity_s, identity_i, identity_d));
+    //]
+}
+