Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76364 - in sandbox/closure: . boost/closure/aux_ boost/closure/aux_/macro/code_ libs/closure/example libs/closure/test
From: lorcaminiti_at_[hidden]
Date: 2012-01-08 05:50:36


Author: lcaminiti
Date: 2012-01-08 05:50:35 EST (Sun, 08 Jan 2012)
New Revision: 76364
URL: http://svn.boost.org/trac/boost/changeset/76364

Log:
Removed recursive-- use (*this)(...) instead.
Added:
   sandbox/closure/Jamroot.jam
      - copied unchanged from r76352, /sandbox/closure/Jamroot.v2
   sandbox/closure/libs/closure/example/Jamfile.jam
      - copied, changed from r76352, /sandbox/closure/libs/closure/example/Jamfile.v2
   sandbox/closure/libs/closure/example/profile_boost_closure_inline.cpp (contents, props changed)
   sandbox/closure/libs/closure/example/profile_local_functor.cpp (contents, props changed)
   sandbox/closure/libs/closure/test/Jamfile.jam
      - copied unchanged from r76350, /sandbox/closure/libs/closure/test/Jamfile.v2
Removed:
   sandbox/closure/Jamroot.v2
   sandbox/closure/libs/closure/example/Jamfile.v2
   sandbox/closure/libs/closure/test/Jamfile.v2
Text files modified:
   sandbox/closure/boost/closure/aux_/function.hpp | 4 -
   sandbox/closure/boost/closure/aux_/macro/code_/end.hpp | 127 +++++----------------------------------
   sandbox/closure/libs/closure/example/Jamfile.jam | 10 +++
   sandbox/closure/libs/closure/example/profile_boost_phoenix.cpp | 2
   4 files changed, 28 insertions(+), 115 deletions(-)

Deleted: sandbox/closure/Jamroot.v2
==============================================================================
--- sandbox/closure/Jamroot.v2 2012-01-08 05:50:35 EST (Sun, 08 Jan 2012)
+++ (empty file)
@@ -1,17 +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).
-
-import os ;
-local BOOST_ROOT = [ os.environ BOOST_ROOT ] ;
-
-use-project boost : $(BOOST_ROOT) ;
-
-project : requirements
- <include>"."
- <include>$(BOOST_ROOT)
- <define>BOOST_PP_VARIADICS # @todo remove this...
-;
-

Modified: sandbox/closure/boost/closure/aux_/function.hpp
==============================================================================
--- sandbox/closure/boost/closure/aux_/function.hpp (original)
+++ sandbox/closure/boost/closure/aux_/function.hpp 2012-01-08 05:50:35 EST (Sun, 08 Jan 2012)
@@ -253,7 +253,6 @@
 #endif
         BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_CLOSURE_AUX_defaults),
                 BOOST_CLOSURE_AUX_call_init, ~)
- unused_ = 0; // To avoid a GCC uninitialized variable error.
     }
     
     // Result operator(Arg1, ..., ArgN-1, ArgN) -- iff defaults >= 0
@@ -270,9 +269,6 @@
 #endif
     BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_CLOSURE_AUX_defaults), // INC no dflt.
             BOOST_CLOSURE_AUX_call_decl, ~)
- // run-time: this unused void* member variable allows for compiler
- // optimizations (at least on MSVC it reduces invocation time of about 50%)
- void* unused_; /** @todo do I really need this? */
 };
 
 # undef BOOST_CLOSURE_AUX_defaults

Modified: sandbox/closure/boost/closure/aux_/macro/code_/end.hpp
==============================================================================
--- sandbox/closure/boost/closure/aux_/macro/code_/end.hpp (original)
+++ sandbox/closure/boost/closure/aux_/macro/code_/end.hpp 2012-01-08 05:50:35 EST (Sun, 08 Jan 2012)
@@ -12,75 +12,38 @@
 #include <boost/closure/aux_/function.hpp>
 #include <boost/closure/aux_/macro/closure.hpp>
 #include <boost/closure/aux_/macro/code_/functor.hpp>
-#include <boost/closure/detail/preprocessor/keyword/recursive.hpp>
 #include <boost/closure/detail/preprocessor/keyword/inline.hpp>
 #include <boost/typeof/typeof.hpp>
 #include <boost/preprocessor/logical/bitor.hpp>
-#include <boost/preprocessor/control/expr_iif.hpp>
 #include <boost/preprocessor/control/iif.hpp>
-#include <boost/preprocessor/tuple/rem.hpp>
 
 // PRIVATE //
 
-// Close functor.
-
-#define BOOST_CLOSURE_AUX_CODE_END_INIT_RECURSION_FUNC_ \
- BOOST_CLOSURE_AUX_SYMBOL( (init_recursion) )
-
-#define BOOST_CLOSURE_AUX_CODE_END_RECURSIVE_FUNC_( \
- is_recursive, local_function_name) \
- BOOST_PP_IIF(is_recursive, \
- local_function_name \
- , \
- BOOST_CLOSURE_AUX_SYMBOL( (non_recursive) ) \
- )
+#define BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_PTR_ \
+ BOOST_CLOSURE_AUX_SYMBOL( (functor_ptr) )
 
 #define BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_(id, \
- local_function_name, is_recursive, \
- local_functor_name, nonlocal_functor_name) \
+ local_function_name, local_functor_name, nonlocal_functor_name) \
     /* `PARAMS() { ... }` expandsion here -- still within functor class */ \
     /* class functor ## __LINE__ { ... */ \
     public: \
- /* member var with function name for recursive calls; must be */ \
- /* `public` because is it also used by this macro but outside */ \
- /* the functor class to deduce the functor type; it cannot be */ \
- /* `const` because it is init after construction (because */ \
- /* constructor doesn't know local function name) */ \
- /* run-time: even when optimizing, recursive calls cannot be */ \
- /* optimized (i.e., they must be via the non-local functor) */ \
- /* because this cannot be a mem ref because its name is not known */ \
- /* by the constructor so it cannot be set by the mem init list */ \
- BOOST_CLOSURE_AUX_CODE_FUNCTOR_TYPE \
- BOOST_CLOSURE_AUX_CODE_END_RECURSIVE_FUNC_(is_recursive, \
- local_function_name); \
- BOOST_PP_EXPR_IIF(is_recursive, \
- /* run-time: the `init_recursion()` function cannot be called */ \
- /* by the constructor to allow for compiler optimization */ \
- /* (inlining) so it must be public */ \
- inline void BOOST_CLOSURE_AUX_CODE_END_INIT_RECURSION_FUNC_( \
- BOOST_CLOSURE_AUX_CODE_FUNCTOR_TYPE& functor) { \
- local_function_name = functor; \
- } \
- ) \
+ /* LIMITATION: member var used to deduce functor type using TYPEOF */ \
+ /* (so it must be public, ptr to always allow for default init); */ \
+ /* unfortunately, this introduces a dependency with Boost.Typeof */ \
+ /* that cannot be removed even when all binds and result types are */ \
+ /* explicitly specified but this is necessary because the functor */ \
+ /* type is known to the CLOSURE macro which must pass it to the */ \
+ /* END macro that is defined on a different line */ \
+ BOOST_CLOSURE_AUX_CODE_FUNCTOR_TYPE* \
+ BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_PTR_; \
     /* local functor can be passed as tparam only on C++11 (faster) */ \
     } local_functor_name(BOOST_CLOSURE_AUX_CLOSURE_ARGS_VAR.value); \
     /* non-local functor can always be passed as tparam (but slower) */ \
- BOOST_TYPEOF(local_functor_name. \
- BOOST_CLOSURE_AUX_CODE_END_RECURSIVE_FUNC_(is_recursive, \
- local_function_name)) \
+ BOOST_TYPEOF(*(local_functor_name.BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_PTR_))\
             nonlocal_functor_name; \
- /* the order of the following 2 function calls cannot be changed */ \
- /* because init_recursion uses the local_functor so the local_functor */ \
- /* must be init first */ \
+ /* initialization */ \
     local_functor_name.BOOST_CLOSURE_AUX_FUNCTION_INIT_CALL_FUNC( \
- &local_functor_name, nonlocal_functor_name); \
- BOOST_PP_EXPR_IIF(is_recursive, \
- /* init recursion causes MSVC to not optimize local function not */ \
- /* even when local functor is used as template parameter so no */ \
- /* recursion unless all inlining optimizations are specified off */ \
- local_functor_name.BOOST_CLOSURE_AUX_CODE_END_INIT_RECURSION_FUNC_( \
- nonlocal_functor_name); \
- )
+ &local_functor_name, nonlocal_functor_name);
 
 #define BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_VAR_(local_function_name) \
     BOOST_CLOSURE_AUX_SYMBOL( (local_function_name) )
@@ -90,10 +53,6 @@
 // Passed at tparam: Yes (on all C++). Inlineable: No. Recursive: No.
 #define BOOST_CLOSURE_AUX_CODE_END_(local_function_name) \
     BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_(__LINE__, local_function_name, \
- /* local function is not recursive (because recursion and its */ \
- /* initialization cannot be inlined even on C++11, */ \
- /* so this allows optimization at least on C++11) */ \
- 0 /* not recursive */ , \
             /* local functor */ \
             BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_VAR_(local_function_name), \
             /* local function declared as non-local functor -- but it can */ \
@@ -106,9 +65,6 @@
 // Passed at tparam: Only on C++11. Inlineable: Yes. Recursive: No.
 #define BOOST_CLOSURE_AUX_CODE_END_INLINE_(local_function_name) \
     BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_(__LINE__, local_function_name, \
- /* inlined local function is never recursive (because recursion */ \
- /* and its initialization cannot be inlined)*/ \
- 0 /* not recursive */ , \
             /* inlined local function declared as local functor (maybe */ \
             /* inlined even by non C++11 -- but it can be passed as */ \
             /* template parameter only on C++11 */ \
@@ -116,26 +72,13 @@
             /* non-local functor */ \
             BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_VAR_(local_function_name))
 
-// This is slower on all compilers (C++11 and non) because recursion and its
-// initialization can never be inlined.
-// Passed at tparam: Yes. Inlineable: No. Recursive: Yes.
-#define BOOST_CLOSURE_AUX_CODE_END_RECURSIVE_(local_function_name) \
- BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_(__LINE__, local_function_name, \
- /* recursive local function -- but it cannot be inlined */ \
- 1 /* recursive */ , \
- /* local functor */ \
- BOOST_CLOSURE_AUX_CODE_END_FUNCTOR_VAR_(local_function_name), \
- /* local function declared as non-local functor -- but it can */ \
- /* be inlined only by C++11 */ \
- local_function_name)
-
-// Dispatch optional inline and recursive.
+// PUBLIC //
 
 // Inlined local functions are specified by `..._NAME(inline name)`.
 // They have more chances to be inlined for faster run-times by some compilers
 // (for example by GCC but not by MSVC). C++11 compilers can always inline
 // local functions even if they are not explicitly specified inline.
-#define BOOST_CLOSURE_AUX_CODE_END_MAYBE_INLINE_(qualified_name) \
+#define BOOST_CLOSURE_AUX_CODE_END(qualified_name) \
     BOOST_PP_IIF(BOOST_PP_BITOR( \
             BOOST_CLOSURE_AUX_CONFIG_LOCAL_TYPES_AS_TEMPLATE_PARAMS_01, \
             BOOST_CLOSURE_DETAIL_PP_KEYWORD_IS_INLINE_FRONT(qualified_name)), \
@@ -149,41 +92,5 @@
         BOOST_CLOSURE_AUX_CODE_END_ \
     )(BOOST_CLOSURE_DETAIL_PP_KEYWORD_INLINE_REMOVE_FRONT(qualified_name))
 
-// Expand to 1 iff `recursive name` or `recursive inline name` or
-// `inline recursive name`.
-#define BOOST_CLOSURE_AUX_CODE_END_IS_RECURSIVE_(qualified_name) \
- BOOST_CLOSURE_DETAIL_PP_KEYWORD_IS_RECURSIVE_FRONT( \
- BOOST_CLOSURE_DETAIL_PP_KEYWORD_INLINE_REMOVE_FRONT( \
- qualified_name \
- ))
-
-// Revmoes `recursive`, `inline recursive`, and `recursive inline` from front.
-#define BOOST_CLOSURE_AUX_CODE_END_REMOVE_RECURSIVE_AND_INLINE_( \
- qualified_name) \
- BOOST_CLOSURE_DETAIL_PP_KEYWORD_RECURSIVE_REMOVE_FRONT( \
- BOOST_CLOSURE_DETAIL_PP_KEYWORD_INLINE_REMOVE_FRONT( \
- BOOST_CLOSURE_DETAIL_PP_KEYWORD_RECURSIVE_REMOVE_FRONT( \
- qualified_name \
- )))
-
-#define BOOST_CLOSURE_AUX_CODE_END_RECURSIVE_REMOVE_(qualified_name) \
- BOOST_PP_IIF(BOOST_CLOSURE_AUX_CODE_END_IS_RECURSIVE_(qualified_name), \
- BOOST_CLOSURE_AUX_CODE_END_REMOVE_RECURSIVE_AND_INLINE_ \
- , \
- BOOST_PP_TUPLE_REM(1) /* might be `name` or `inline name` */ \
- )(qualified_name)
-
-// PUBLIC //
-
-// Recursive local function are specified by `..._NAME(recursive name)`.
-// They can never be inlined for faster run-time (not even by C++11 compilers).
-#define BOOST_CLOSURE_AUX_CODE_END(qualified_name) \
- BOOST_PP_IIF(BOOST_CLOSURE_AUX_CODE_END_IS_RECURSIVE_(qualified_name), \
- /* recursion can never be inlined (not even on C++11) */ \
- BOOST_CLOSURE_AUX_CODE_END_RECURSIVE_ \
- , \
- BOOST_CLOSURE_AUX_CODE_END_MAYBE_INLINE_ \
- )(BOOST_CLOSURE_AUX_CODE_END_RECURSIVE_REMOVE_(qualified_name))
-
 #endif // #include guard
 

Copied: sandbox/closure/libs/closure/example/Jamfile.jam (from r76352, /sandbox/closure/libs/closure/example/Jamfile.v2)
==============================================================================
--- /sandbox/closure/libs/closure/example/Jamfile.v2 (original)
+++ sandbox/closure/libs/closure/example/Jamfile.jam 2012-01-08 05:50:35 EST (Sun, 08 Jan 2012)
@@ -4,6 +4,16 @@
     <library>/boost/system//boost_system
     <link>static
 ;
+exe profile_boost_closure_inline : profile_boost_closure_inline.cpp :
+ <library>/boost/chrono//boost_chrono
+ <library>/boost/system//boost_system
+ <link>static
+;
+exe profile_local_functor : profile_local_functor.cpp :
+ <library>/boost/chrono//boost_chrono
+ <library>/boost/system//boost_system
+ <link>static
+;
 exe profile_boost_phoenix : profile_boost_phoenix.cpp :
     <library>/boost/chrono//boost_chrono
     <library>/boost/system//boost_system

Deleted: sandbox/closure/libs/closure/example/Jamfile.v2
==============================================================================
--- sandbox/closure/libs/closure/example/Jamfile.v2 2012-01-08 05:50:35 EST (Sun, 08 Jan 2012)
+++ (empty file)
@@ -1,12 +0,0 @@
-
-exe profile_boost_closure : profile_boost_closure.cpp :
- <library>/boost/chrono//boost_chrono
- <library>/boost/system//boost_system
- <link>static
-;
-exe profile_boost_phoenix : profile_boost_phoenix.cpp :
- <library>/boost/chrono//boost_chrono
- <library>/boost/system//boost_system
- <link>static
-;
-

Added: sandbox/closure/libs/closure/example/profile_boost_closure_inline.cpp
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/closure/example/profile_boost_closure_inline.cpp 2012-01-08 05:50:35 EST (Sun, 08 Jan 2012)
@@ -0,0 +1,45 @@
+
+// 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).
+
+//[example_profile_boost_closure_inline_cpp
+#include <boost/closure.hpp>
+#include <boost/chrono.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include "profile_helpers.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned long size = 0, trials = 0;
+ profile::args(argc, argv, size, trials);
+
+ double sum = 0.0;
+ int factor = 1;
+
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ void BOOST_CLOSURE(const double& num, bind& sum, const bind& factor) {
+ sum += factor * num;
+ } BOOST_CLOSURE_END(inline add) // inlined
+ boost::chrono::duration<double> decl_sec =
+ boost::chrono::system_clock::now() - start;
+
+ std::vector<double> v(size);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ boost::chrono::duration<double> trials_sec;
+ for(unsigned long i = 0; i < trials; ++i) {
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ for (unsigned long j = 0; j < v.size(); ++j) add(v[j]); // No for_each.
+ trials_sec += boost::chrono::system_clock::now() - start;
+ }
+
+ profile::print(size, trials, sum, trials_sec.count(), decl_sec.count());
+ return 0;
+}
+//]
+

Modified: sandbox/closure/libs/closure/example/profile_boost_phoenix.cpp
==============================================================================
--- sandbox/closure/libs/closure/example/profile_boost_phoenix.cpp (original)
+++ sandbox/closure/libs/closure/example/profile_boost_phoenix.cpp 2012-01-08 05:50:35 EST (Sun, 08 Jan 2012)
@@ -5,11 +5,11 @@
 // copy at http://www.boost.org/LICENSE_1_0.txt).
 
 //[example_profile_boost_phoenix_cpp
-#include <boost/chrono.hpp>
 #include <boost/spirit/home/phoenix/statement/sequence.hpp>
 #include <boost/spirit/home/phoenix/core/reference.hpp>
 #include <boost/spirit/home/phoenix/core/argument.hpp>
 #include <boost/spirit/home/phoenix/operator/arithmetic.hpp>
+#include <boost/chrono.hpp>
 #include <iostream>
 #include <vector>
 #include <algorithm>

Added: sandbox/closure/libs/closure/example/profile_local_functor.cpp
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/closure/example/profile_local_functor.cpp 2012-01-08 05:50:35 EST (Sun, 08 Jan 2012)
@@ -0,0 +1,51 @@
+
+// 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).
+
+//[example_profile_local_functor_cpp
+#include <boost/chrono.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include "profile_helpers.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned long size = 0, trials = 0;
+ profile::args(argc, argv, size, trials);
+
+ double sum = 0.0;
+ int factor = 1;
+
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ struct local_add {
+ local_add(double& _sum, const int& _factor):
+ sum(_sum), factor(_factor) {}
+ inline void operator()(const double& num) {
+ sum += factor * num;
+ }
+ private:
+ double& sum;
+ const int& factor;
+ } add(sum, factor);
+ boost::chrono::duration<double> decl_sec =
+ boost::chrono::system_clock::now() - start;
+
+ std::vector<double> v(size);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ boost::chrono::duration<double> trials_sec;
+ for(unsigned long i = 0; i < trials; ++i) {
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ for (unsigned long j = 0; j < v.size(); ++j) add(v[j]); // No for_each.
+ trials_sec += boost::chrono::system_clock::now() - start;
+ }
+
+ profile::print(size, trials, sum, trials_sec.count(), decl_sec.count());
+ return 0;
+}
+//]
+

Deleted: sandbox/closure/libs/closure/test/Jamfile.v2
==============================================================================
--- sandbox/closure/libs/closure/test/Jamfile.v2 2012-01-08 05:50:35 EST (Sun, 08 Jan 2012)
+++ (empty file)
@@ -1,11 +0,0 @@
-
-import testing ;
-
-test-suite boost_closure_test :
- [ run return_inc.cpp /boost//unit_test_framework ]
- [ run return_this.cpp /boost//unit_test_framework ]
- [ run return_derivative.cpp /boost//unit_test_framework ]
- [ run return_setget.cpp /boost//unit_test_framework ]
- [ run return_factorial.cpp /boost//unit_test_framework ]
-;
-


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk