Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71702 - in sandbox/local: boost/local boost/local/aux_ boost/local/aux_/function_macros/code_ libs/local/doc/qbk libs/local/example
From: lorcaminiti_at_[hidden]
Date: 2011-05-03 16:07:25


Author: lcaminiti
Date: 2011-05-03 16:07:24 EDT (Tue, 03 May 2011)
New Revision: 71702
URL: http://svn.boost.org/trac/boost/changeset/71702

Log:
Made it compile on MSVC and GCC.
Text files modified:
   sandbox/local/boost/local/aux_/function.hpp | 14 ++++-
   sandbox/local/boost/local/aux_/function_macros/code_/functor.hpp | 8 ++-
   sandbox/local/boost/local/function.hpp | 96 ----------------------------------------
   sandbox/local/libs/local/doc/qbk/release_notes.qbk | 4 +
   sandbox/local/libs/local/example/tparam_trick.cpp | 23 ++++-----
   5 files changed, 31 insertions(+), 114 deletions(-)

Modified: sandbox/local/boost/local/aux_/function.hpp
==============================================================================
--- sandbox/local/boost/local/aux_/function.hpp (original)
+++ sandbox/local/boost/local/aux_/function.hpp 2011-05-03 16:07:24 EDT (Tue, 03 May 2011)
@@ -80,6 +80,15 @@
                         BOOST_LOCAL_AUX_arg_name, ~)); \
     }
 
+namespace boost { namespace local { namespace aux {
+
+template<typename F, size_t defaults = 0>
+class function {
+ // Empty template cannot be used directly (only via its specializations).
+};
+
+}}} // namespace boost::loca::aux
+
 // Iteration within the namespace.
 # define BOOST_PP_ITERATION_PARAMS_1 \
                 (3, (0, BOOST_LOCAL_CONFIG_FUNCTION_ARITY_MAX, \
@@ -114,8 +123,7 @@
 #elif BOOST_PP_ITERATION_DEPTH() == 2
 # define BOOST_LOCAL_AUX_defaults BOOST_PP_FRAME_ITERATION(2)
 
-// Specializations of boost::local::function so not in aux namespace.
-namespace boost { namespace local {
+namespace boost { namespace local { namespace aux {
 
 template<typename R
     BOOST_PP_COMMA_IF(BOOST_LOCAL_AUX_arity)
@@ -174,7 +182,7 @@
     void* unused_;
 };
 
-}} // namespace boost::local
+}}} // namespace boost::local::aux
 
 # undef BOOST_LOCAL_AUX_defaults
 

Modified: sandbox/local/boost/local/aux_/function_macros/code_/functor.hpp
==============================================================================
--- sandbox/local/boost/local/aux_/function_macros/code_/functor.hpp (original)
+++ sandbox/local/boost/local/aux_/function_macros/code_/functor.hpp 2011-05-03 16:07:24 EDT (Tue, 03 May 2011)
@@ -14,8 +14,8 @@
 #include "../../preprocessor/sign/params_bind.hpp"
 #include "../../scope_exit/scope_exit.hpp" // Use this lib's ScopeExit impl.
 #include "../../type_traits/add_pointed_const.hpp"
+#include "../../function.hpp"
 #include "../../../config.hpp"
-#include "../../../function.hpp"
 #include <boost/detail/preprocessor/keyword/auto.hpp>
 #include <boost/detail/preprocessor/keyword/register.hpp>
 #include <boost/type_traits.hpp>
@@ -44,10 +44,12 @@
     BOOST_PP_CAT(arg, i)
 
 // i: 1 for 1st param, 2 for 2nd, ... (start from 1 not 0).
-#define BOOST_LOCAL_AUX_FUNCTION_CODE_FUNCTOR_UNBIND_ARG_TYPE_(i) \
+#define BOOST_LOCAL_AUX_FUNCTION_CODE_FUNCTOR_UNBIND_ARG_TYPE_( \
+ typename_keyword, i) \
     /* the parameter type must be accessed using function traits from */ \
     /* function type because it is not available to the macro syntax */ \
     /* separately from the parameter name */ \
+ typename_keyword \
     BOOST_PP_CAT(BOOST_PP_CAT(::boost::function_traits< \
             BOOST_LOCAL_AUX_SYMBOL_FUNCTION_TYPE>::arg, i), _type) \
 
@@ -57,7 +59,7 @@
     typename_keyword \
     ::boost::call_traits< \
             BOOST_LOCAL_AUX_FUNCTION_CODE_FUNCTOR_UNBIND_ARG_TYPE_( \
- BOOST_PP_INC(i))>::param_type \
+ typename_keyword, BOOST_PP_INC(i))>::param_type \
     BOOST_LOCAL_AUX_FUNCTION_CODE_FUNCTOR_UNBIND_ARG_NAME_(BOOST_PP_INC(i))
 
 #define BOOST_LOCAL_AUX_FUNCTION_CODE_FUNCTOR_UNBIND_ARG_NAME_ENUM_( \

Modified: sandbox/local/boost/local/function.hpp
==============================================================================
--- sandbox/local/boost/local/function.hpp (original)
+++ sandbox/local/boost/local/function.hpp 2011-05-03 16:07:24 EDT (Tue, 03 May 2011)
@@ -202,101 +202,5 @@
 #define BOOST_LOCAL_FUNCTION_NAME(name) \
     BOOST_LOCAL_AUX_FUNCTION_NAME(name)
 
-namespace boost { namespace local {
-
-/**
- * @brief Functor with support for default function parameters.
- *
- * This template defines several specializations to handle a generic number
- * of function parameters some of which can have default values.
- * The number of supported function parameters <c>N</c> goes from <c>0</c> (for
- * a function with no parameter) to a maximum of
- * @RefMacro{BOOST_LOCAL_CONFIG_FUNCTION_ARITY_MAX}.
- *
- * Each template specialization defines call operators <c>operator()(...)</c>
- * with a different set of parameters to handle the number of default
- * parameters specified by <c>defaults</c> (see @RefSect2{Advanced_Topics,
- * Advanced Topics} section):
- * @code
- * template<typename Result, typename Arg1, ..., typename ArgN, size_t defaults = 0>
- * class function<Result (Arg1, ..., ArgN), defaults> {
- * public:
- * Result operator()(Arg1, ..., ArgN-2, ArgN-1, ArgN);
- * // Call operators to handle default parameters:
- * Result operator()(Arg1, ..., ArgN-2, ArgN-1); // iff defaults >= 1
- * Result operator()(Arg1, ..., ArgN-2); // iff defaults >= 2
- * ... // etc
- *
- * // Default and copy constructors, and assignment operator.
- * function();
- * function(local_function_type<F, defaults> local_function);
- * function& operator=(local_function_type<F, defaults> local_function);
- * };
- * @endcode
- * Where:
- * - <c>Result</c> is the function result type.
- * It can be <c>void</c>.
- * - <c>ArgN</c> is the last function parameter type, <c>ArgN-1</c> is the
- * second last function parameter type, etc.
- * These are all optional: None is specified for a function with no
- * parameter; Only <c>Arg1</c> is specified for a function with only one
- * parameter; Etc.
- * - The operator <c>Result operator()(Arg1, ..., ArgN-2, ArgN-1)</c> is
- * declared if and only if there are one or more default parameters
- * (<c>defaults >= 1</c>), the operator
- * <c>Result operator()(Arg1, ..., ArgN-2)</c> is defined if and only if
- * there are two or more default parameters (<c>defaults >= 2</c>), etc.
- * - <c>local_function_type<F, defaults></c> is an internal (i.e.,
- * implementation specific) type for a local function with a signature
- * matching <c>F</c> and with a number of default parameters equal to
- * <c>defaults</c>.
- * - The default constructor allows to constructor this functor without
- * assigning it to any function. A run-time error is generated if the call
- * operator <c>operator()</c> is invoked for a functor not assigned to any
- * function.
- * - The copy constructor and assignment operator <c>operator=</c> allow to
- * assign this functor to a local function with a signature matching <c>F</c>
- * and with a number of default parameters equal to <c>defaults</c>.
- *
- * @Warning Programmers must make sure that the local function assigned to this
- * functor survives the scope of the functor (otherwise the functor will be
- * invalid and its use will generate a run-time error as usual with C++
- * functors).
- *
- * @Params
- * @Param{F,
- * The function type specifying function signature expressed using the same
- * syntax as Boost.Function's preferred syntax:
- * <c>F = Result (Arg1\, ...\, ArgN)</c>.
- * }
- * @Param{defaults,
- * The number of the function default parameters in
- * <c>[0\,</c>
- * @RefMacro{BOOST_LOCAL_CONFIG_FUNCTION_ARITY_MAX}<c>]</c>.
- * As usual in C++\, default parameters are counted starting from the last
- * parameter:
- * <c>defaults = 0</c> means that no parameter is optional\,
- * <c>defaults = 1</c> means that the last parameter is optional\,
- * <c>defaults = 2</c> means that the last two parameters are optional\, etc.
- * }
- * @EndParams
- *
- * @Note This functor is similar to Boost.Funciton's <c>boost::function<></c>
- * but it also supports eventual default parameters.
- *
- * @See @RefSect2{Advanced_Topics, Advanced Topics} section,
- * @RefMacro{BOOST_LOCAL_CONFIG_FUNCTION_ARITY_MAX},
- * @RefMacro{BOOST_LOCAL_FUNCTION_PARAMS},
- * @RefMacro{BOOST_LOCAL_FUNCTION_NAME},
- * <a href='http://www.boost.org/doc/libs/release/doc/html/function.html'>Boost.Function</a>.
- */
-template<typename F, size_t defaults = 0> // Defaults count is opt.
-struct function {}; // Empty so never used directly.
-
-}} // namespace boost::local
-
-// Template specializations (must be #included here after the above template).
-#include "aux_/function.hpp"
-
 #endif // #include guard
 

Modified: sandbox/local/libs/local/doc/qbk/release_notes.qbk
==============================================================================
--- sandbox/local/libs/local/doc/qbk/release_notes.qbk (original)
+++ sandbox/local/libs/local/doc/qbk/release_notes.qbk 2011-05-03 16:07:24 EDT (Tue, 03 May 2011)
@@ -31,8 +31,12 @@
 # Remove all references (docs, doxy, examples, etc) to local::function.
 Make local::function local::aux::function and use boost::function instead.
 
+# Verify compilation and run-times on all compilers one last time.
+
 # Rework factorial_impl and Implementation section.
 
+# Finalize Acknowledge section.
+
 [endsect]
 
 [endsect]

Modified: sandbox/local/libs/local/example/tparam_trick.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.cpp (original)
+++ sandbox/local/libs/local/example/tparam_trick.cpp 2011-05-03 16:07:24 EDT (Tue, 03 May 2011)
@@ -11,31 +11,30 @@
 struct casting_func {
     explicit casting_func(void* obj, void (*call)(void*, const double&)):
             obj_(obj), call_(call) {}
- inline void operator()(const double& num)
- { call_(obj_, num); } // function pointer call cannot be inlined
+ // Unfortunately, function pointer call is not inlined.
+ inline void operator()(const double& num) { call_(obj_, num); }
 private:
     void* obj_;
     void (*call_)(void*, const double&);
 };
 
 // Virtual Functor Trick
-struct func_interface {
- inline virtual void operator()(const double&)
- = 0; // virtual call cannot be inlined
-};
 struct virtual_func {
- explicit virtual_func(func_interface& func): func_(&func) {}
- inline void operator()(const double& num)
- { (*func_)(num); }
+ struct interface {
+ // Unfortunately, virtual function call is not inlined.
+ inline virtual void operator()(const double&) {}
+ };
+ explicit virtual_func(interface& func): func_(&func) {}
+ inline void operator()(const double& num) { (*func_)(num); }
 private:
- func_interface* func_;
+ interface* func_;
 };
 
 int main() {
     double sum = 0.0;
     int factor = 10;
 
- struct local_add : func_interface {
+ struct local_add : virtual_func::interface {
         explicit local_add(double& _sum, const int& _factor):
                 sum_(_sum), factor_(_factor) {}
         inline void operator()(const double& num) {
@@ -59,7 +58,7 @@
     std::vector<double> v(10);
     std::fill(v.begin(), v.end(), 1.0);
     
-// std::for_each(v.begin(), v.end(), add_local); // Error but OK on C++03.
+// std::for_each(v.begin(), v.end(), add_local); // Error but OK on C++0x.
     std::for_each(v.begin(), v.end(), add_casting); // OK.
     std::for_each(v.begin(), v.end(), add_virtual); // OK.
 


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