|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76681 - in sandbox/local_function: boost boost/local_function boost/local_function/aux_ libs/local_function/doc libs/local_function/doc/html libs/local_function/doc/html/boost_localfunction libs/local_function/example libs/local_function/test
From: lorcaminiti_at_[hidden]
Date: 2012-01-25 09:21:00
Author: lcaminiti
Date: 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
New Revision: 76681
URL: http://svn.boost.org/trac/boost/changeset/76681
Log:
Upd.
Added:
sandbox/local_function/libs/local_function/test/add_params.cpp
- copied, changed from r76631, /sandbox/local_function/libs/local_function/test/add_nobind.cpp
sandbox/local_function/libs/local_function/test/ten_void.cpp
- copied, changed from r76631, /sandbox/local_function/libs/local_function/test/ten.cpp
Removed:
sandbox/local_function/libs/local_function/test/add_nobind.cpp
sandbox/local_function/libs/local_function/test/ten.cpp
Text files modified:
sandbox/local_function/boost/local_function.hpp | 436 +++++++-------
sandbox/local_function/boost/local_function/aux_/function.hpp | 19
sandbox/local_function/boost/local_function/config.hpp | 69 +
sandbox/local_function/boost/scope_exit.hpp | 10
sandbox/local_function/libs/local_function/doc/Jamfile.v2 | 27
sandbox/local_function/libs/local_function/doc/acknowledgements.qbk | 7
sandbox/local_function/libs/local_function/doc/advanced_topics.qbk | 163 ++---
sandbox/local_function/libs/local_function/doc/alternatives.qbk | 10
sandbox/local_function/libs/local_function/doc/bibliography.qbk | 2
sandbox/local_function/libs/local_function/doc/examples.qbk | 90 ++
sandbox/local_function/libs/local_function/doc/getting_started.qbk | 29
sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Acknowledgments.html | 17
sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Advanced_Topics.html | 383 +++++++-----
sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Alternatives.html | 1142 +++++++++++++++++++--------------------
sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Bibliography.html | 5
sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Examples.html | 245 ++++++-
sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Getting_Started.html | 79 +-
sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Implementation.html | 161 ++--
sandbox/local_function/libs/local_function/doc/html/boost_localfunction/No_Variadic_Macros.html | 97 +-
sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Release_Notes.html | 18
sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Tutorial.html | 215 ++++---
sandbox/local_function/libs/local_function/doc/html/index.html | 110 +-
sandbox/local_function/libs/local_function/doc/implementation.qbk | 24
sandbox/local_function/libs/local_function/doc/introduction.qbk | 18
sandbox/local_function/libs/local_function/doc/local_function.qbk | 42
sandbox/local_function/libs/local_function/doc/no_variadic_macros.qbk | 8
sandbox/local_function/libs/local_function/doc/release_notes.qbk | 4
sandbox/local_function/libs/local_function/doc/tutorial.qbk | 70 +-
sandbox/local_function/libs/local_function/example/Jamfile.v2 | 3
sandbox/local_function/libs/local_function/example/const_block.cpp | 2
sandbox/local_function/libs/local_function/example/impl_tparam_tricks.cpp | 2
sandbox/local_function/libs/local_function/test/Jamfile.v2 | 9
sandbox/local_function/libs/local_function/test/add.cpp | 10
sandbox/local_function/libs/local_function/test/add_lambda.cpp | 12
sandbox/local_function/libs/local_function/test/add_params.cpp | 6
sandbox/local_function/libs/local_function/test/factorial.cpp | 2
sandbox/local_function/libs/local_function/test/ten_void.cpp | 6
37 files changed, 1919 insertions(+), 1633 deletions(-)
Modified: sandbox/local_function/boost/local_function.hpp
==============================================================================
--- sandbox/local_function/boost/local_function.hpp (original)
+++ sandbox/local_function/boost/local_function.hpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -4,15 +4,10 @@
// License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
// copy at http://www.boost.org/LICENSE_1_0.txt).
-/** @file
-_at_brief Local functions allows to program functions locally within the scope
-where they are needed.
-*/
-
#ifndef BOOST_LOCAL_FUNCTION_HPP_
#define BOOST_LOCAL_FUNCTION_HPP_
-#ifndef DOXY
+#ifndef DOXYGEN
#include <boost/local_function/aux_/macro/decl.hpp>
#include <boost/local_function/aux_/macro/name.hpp>
@@ -56,231 +51,246 @@
)
#endif // VARIADIC
-#define BOOST_LOCAL_FUNCTION_NAME(qualified_name) \
- BOOST_LOCAL_FUNCTION_AUX_NAME(qualified_name)
+#define BOOST_LOCAL_FUNCTION_NAME(qualified_function_name) \
+ BOOST_LOCAL_FUNCTION_AUX_NAME(qualified_function_name)
#define BOOST_LOCAL_FUNCTION_TYPEOF(bound_variable_name) \
BOOST_LOCAL_FUNCTION_AUX_TYPEOF_TYPE(bound_variable_name)
// DOCUMENTATION //
-#else // DOXY
+#else // DOXYGEN
+
+/** @file
+@brief Local functions allow to program functions locally, directly within the
+scope where they are needed.
+*/
/**
- * @brief This macro is used to declare the local function parameters.
- *
- * This macro must be used within a declarative context, it must follow the
- * local function result type, it must be followed by the local function body
- * code and then by the @RefMacro{BOOST_LOCAL_FUNCTION_NAME} macro (see the
- * @RefSect{Tutorial} and @RefSect2{Advanced_Topics, Advanced Topics}
- * sections):
- * @code
- * { // Some declarative context.
- * ...
- * result_type BOOST_LOCAL_FUNCTION_PARAMS(parameters) {
- * ... // Body code.
- * } BOOST_LOCAL_FUNCTION_NAME(name)
- * ...
- * }
- * @endcode
- *
- * As usual, exceptions specifications can be optionally programmed before the
- * body code block (but the specifications will only apply the body code and
- * not to the library code automatically generated by the macro expansion,
- * see @RefSect2{Advanced_Topics, Advanced Topics}).
- *
- * Within templates, the special macro
- * @RefMacro{BOOST_LOCAL_FUNCTION_PARAMS_TPL} must be used instead of
- * @RefMacro{BOOST_LOCAL_FUNCTION_PARAMS}.
- *
- * @Params
- * @Param{parameters,
- * On all C++ compilers\, the <em>sequencing macro syntax</em> defined by the
- * following grammar is used to specify the local function parameters:
- * @code
- * parameters:
- * void_list | parameter_list
- * void_list:
- * (void)
- * parameter_list:
- * (parameter1) (parameter2) ...
- * parameter:
- * normal_parameter | bound_parameter
- * normal_parameter:
- * [auto | register] parameter_type parameter_name
- * [default_parameter_value]
- * default_parameter_value:
- * (default_value)
- * default_value:
- * default default_vale_expression
- * bound_parameter:
- * [const] bind [(variable_type)] [&] variable_name
- * @endcode
- * Where the following lexical conventions have been used:
- * <c>token1 | token2</c> means either <c>token1</c> or <c>token2</c>;
- * <c>[token]</c> means either <c>token</c> or nothing (i.e.\, <c>token</c> is
- * optional).
- *
- * On C99 and later compilers that support variadic macros\, the above
- * grammar can be modified as follow to define the <em>variadic macro
- * syntax</em> that can also be used to specify the local functions
- * parameters:
- * @code
- * void_list:
- * void
- * parameter_list:
- * parameter1\, parameter2\, ...
- * default_parameter_value:
- * \, default_value
- * @endcode
- * Note that the variadic macro syntax uses commas <c>\,</c> instead of
- * parenthesis <c>()</c> to separate the parameters and therefore resembles
- * the usual C++ function parameter declaration syntax more closely than the
- * sequencing macro syntax. However\, the variadic macro syntax will only work
- * on C++ compilers that support variadic macros so it should be used with
- * care in order to avoid portability issues.
- *
- * Finally\, on C++ compilers that support empty macro parameters\, the above
- * grammars can be modified as follow to define the <em>empty macro
- * syntax</em> that can can also be used to specify an empty parameter list:
- * @code
- * void_list:
- * ()
- * @endcode
- * Note that the empty macro parameter syntax uses the usual C++ syntax to
- * specify empty function parameter list but it will only work on compilers
- * that support empty macro parameters so it should be used with care in order
- * to avoid portability issues.
- * }
- * @EndParams
- *
- * When the object <c>this</c> is specified as the name of the variable to
- * bind, the body must use the special name <c>this_</c> to access the bound
- * object.
- * The special name <c>this_</c> is defined by the configuration macro
- * @RefMacro{BOOST_LOCAL_CONFIG_THIS_PARAM_NAME}.
- *
- * The number of local function parameters (excluding bound variables) is
- * specified by the configuration macro
- * @RefMacro{BOOST_LOCAL_CONFIG_FUNCTION_ARITY_MAX}.
- * Both the variadic and empty macro syntaxes are always disabled when the
- * configuration macro @RefMacro{BOOST_LOCAL_CONFIG_COMPLIANT} is defined.
- *
- * @Note Local functions are functors so they can be assigned to other functors
- * like <c>boost::function</c> (see Boost.Function).
- *
- * @Note This macro cannot be used multiple times on the same line because it
- * internally uses the line number <c>__LINE__</c> to generate unique
- * identifiers.
- *
- * @See @RefSect{Tutorial} section, @RefSect2{Advanced_Topics, Advanced Topics}
- * section, @RefMacro{BOOST_LOCAL_FUNCTION_PARAMS_TPL},
- * @RefMacro{BOOST_LOCAL_FUNCTION_NAME},
- * @RefMacro{BOOST_LOCAL_CONFIG_THIS_PARAM_NAME},
- * @RefMacro{BOOST_LOCAL_CONFIG_FUNCTION_ARITY_MAX},
- * @RefMacro{BOOST_LOCAL_CONFIG_COMPLIANT}, Boost.Function.
- */
+@brief This macro is used to start a local function declaration.
+
+This macro must be used within a declarative context, it must follow the local
+function result type, it must be followed by the local function body code, and
+then by the @RefMacro{BOOST_LOCAL_FUNCTION_NAME} macro (see the
+@RefSect{Tutorial} and @RefSectId{Advanced_Topics, Advanced Topics} sections):
+@code
+{ // Some declarative context.
+ ...
+ result_type BOOST_LOCAL_FUNCTION(declarations) {
+ ... // Body code.
+ } BOOST_LOCAL_FUNCTION_NAME(qualified_function_name)
+ ...
+}
+@endcode
+
+As usual, exceptions specifications can be optionally programmed just after the
+macro and before the body code block <c>{ ... }</c> (but the exception
+specifications will only apply to the body code and not to the library code
+automatically generated by the macro expansion, see the
+@RefSectId{Advanced_Topics, Advanced Topics} section).
+
+Within templates, the special macro @RefMacro{BOOST_LOCAL_FUNCTION_TPL} must be
+used instead of_at_RefMacro{BOOST_LOCAL_FUNCTION}.
+
+@Params
+@Param{declarations,
+On compilers that support variadic macros\, the parameter declarations are
+defined by the following grammar:
+@code
+ declarations:
+ void | declaration_tuple | declaration_sequence
+ declaration_tuple:
+ declaration\, declaration\, ...
+ declaration_sequence:
+ (declaration) (declaration) ...
+ declaration:
+ bound_variable | parameter | default_value | result_type
+ bound_variable:
+ [const] bind [(variable_type)] [&] variable_name
+ parameter:
+ [auto | register] parameter_type parameter_name
+ default_value:
+ default parameter_default_value
+ result_type:
+ return function_result_type
+@endcode
+On compilers that do not support variadic macros\, <c>declaration_tuple</c>
+cannot be used:
+@code
+ declarations:
+ void | declaration_sequence
+@endcode
+
+(Lexical conventions: <c>token1 | token2</c> means either <c>token1</c> or
+<c>token2</c>; <c>[token]</c> means either <c>token</c> or nothing;
+<c>{expression}</c> means the token resulting from the expression.)
+}
+@EndParams
+
+Note that on compilers that support variadic macros, commas can be used to
+separate the declarations resembling more closely the usual C++ function
+declaration syntax.
+This is the preferred syntax.
+However, for portability, on all C++ compilers (with and without variadic
+macros) the same library macros also accept parameter declarations specified as
+a Boost.Preprocessor sequence separated by round parenthesis <c>()</c>.
+
+When binding the object <c>this</c>, the special symbol <c>this_</c> needs to
+be used instead of <c>this</c> as the name of the variable to bind and also
+within the local function body to access the object.
+(Mistakenly using <c>this</c> instead of <c>this_</c> might not always result in a compiler error and will in general lead to undefined behaviour.)
+
+The result type must either be specified just before the macro or within the
+macro declarations prefixed by <c>return</c> (but not in both places).
+
+The maximum number of local function parameters (excluding bound variables) is
+specified by the configuration macro
+@RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX}.
+The maximum number of bound variables is specified by the configuration macro
+@RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX}.
+
+@Note Local functions are functors so they can be assigned to other functors
+like <c>boost::function</c> (see Boost.Function).
+
+@Note This macro cannot be used multiple times on the same line (because it
+internally uses the line number <c>__LINE__</c> to generate unique
+identifiers).
+
+@See @RefSect{Tutorial} section,
+@RefSectId{Advanced_Topics, Advanced Topics} section,
+@RefMacro{BOOST_LOCAL_FUNCTION_TPL},
+@RefMacro{BOOST_LOCAL_FUNCTION_NAME},
+@RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX},
+@RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX}.
+*/
#define BOOST_LOCAL_FUNCTION(declarations)
/**
- * @brief This macro is the same as @RefMacro{BOOST_LOCAL_FUNCTION_PARAMS} but
- * it must be used when declaring local functions within templates.
- *
- * @See @RefMacro{BOOST_LOCAL_FUNCTION_PARAMS}, @RefSect{Tutorial} section.
- */
+@brief This macro is used to start a local function declaration within templates.
+
+This macro must be used instead of @RefMacro{BOOST_LOCAL_FUNCTION} when declaring a local function within a template.
+A part from that, this macro has the exact same syntax as @RefMacro{BOOST_LOCAL_FUNCTION} (see @RefMacro{BOOST_LOCAL_FUNCTION} for more information):
+@code
+{ // Some declarative context with a template.
+ ...
+ result_type BOOST_LOCAL_FUNCTION_TPL(declarations) {
+ ... // Body code.
+ } BOOST_LOCAL_FUNCTION_NAME(qualified_function_name)
+ ...
+}
+@endcode
+
+@Note C++03 does not allow to use <c>typename</c> outside templates.
+This library internally manipulates types, these operations require
+<c>typename</c> but only within templates so this macro is used to indicate to
+the library when the enclosing scope is a template.
+
+@See @RefSect{Tutorial} section, @RefMacro{BOOST_LOCAL_FUNCTION},
+@RefMacro{BOOST_LOCAL_FUNCTION_NAME}.
+*/
#define BOOST_LOCAL_FUNCTION_TPL(declarations)
/**
- * @brief This macro is used to specify the local function name.
- *
- * This macro must follow the local function body code block <c>{ ... }</c> as
- * shown in the @RefMacro{BOOST_LOCAL_FUNCTION_PARAMS} documentation.
- *
- * The local function name can be prefixed by the "keyword" <c>inline</c>
- * (see the @RefSect2{Advanced_Topics, Advanced Topics} section):
- * @code
- * ... BOOST_LOCAL_FUNCTION_NAME(inline name)
- * @endcode
- * This increases the chances that the compiler will be able to inline the
- * local function calls (thus reducing their run-time).
- * However, inlined local functions cannot be passed as template parameters or
- * assigned to other functors like <c>boost::function</c> (that is true on
- * C++03 compilers, see @RefMacro{BOOST_LOCAL_CONFIG_COMPLIANT}, but inlined
- * local functions can instead be passed as template parameters on C++11
- * compilers).
- * On C++11 compilers, there is no need to declare a local function lined
- * because this library will automatically use C++11 specific features to
- * inline the local function while always allowing to pass it as a template
- * parameter.
- *
- * The local function name can also be prefixed by the "keyword"
- * <c>recursive</c> (see the @RefSect2{Advanced_Topics, Advanced Topics}
- * section):
- * @code
- * ... BOOST_LOCAL_FUNCTION_NAME(recursive name)
- * @endcode
- * This allows the local function to recursively call itself from its body (as
- * usual in C++).
- * However, compilers have not been observed to be able to inline recursive
- * local function calls (not even when the recursive local function is also
- * declared inlined).
- *
- * @Params
- * @Param{name,
- * The name of the local function.
- * The local function name can be prefixed by the "keyword" <c>inline</c> to
- * declare the local function inlined or by the "keyword" <c>recursive</c> to
- * declare the local function recursive (see the @RefSect2{Advanced_Topics\,
- * Advanced Topics} section).
- * The local function name cannot be the name of an operator
- * <c>operator...</c> and it cannot be the same name of another local function
- * declared within the same enclosing scope (use the
- * @RefClass{boost::local::function::overload} functor to overload local
- * functions\, see the @RefSect2{Advanced_Topics\, Advanced Topics} section).
- * }
- * @EndParams
- *
- * @See @RefMacro{BOOST_LOCAL_FUNCTION_PARAMS}, @RefSect{Tutorial} section,
- * @RefSect2{Advanced_Topics, Advanced Topics} section,
- * @RefMacro{BOOST_LOCAL_CONFIG_COMPLIANT}.
- */
-#define BOOST_LOCAL_FUNCTION_END(name)
+@brief This macro is used to end a local function declaration specifying its
+name.
+
+This macro must follow the local function body code block <c>{ ... }</c>:
+@code
+{ // Some declarative context.
+ ...
+ result_type BOOST_LOCAL_FUNCTION(declarations) {
+ ... // Body code.
+ } BOOST_LOCAL_FUNCTION_NAME(qualified_function_name)
+ ...
+}
+@endcode
+
+@Params
+@Param{qualified_function_name,
+The name of the local function optionally qualified as follow:
+@code
+qualified_function_name:
+ [inline] [recursive] name
+@endcode
+(Lexical conventions: <c>token1 | token2</c> means either <c>token1</c> or
+<c>token2</c>; <c>[token]</c> means either <c>token</c> or nothing;
+<c>{expression}</c> means the token resulting from the expression.)
+}
+@EndParams
+
+The local function name can be qualified by prefixing it with the "keyword"
+<c>inline</c> (see the @RefSectId{Advanced_Topics, Advanced Topics} section):
+<c>BOOST_LOCAL_FUNCTION_NAME(inline name)</c>.
+This increases the chances that the compiler will be able to inline the local
+function calls (thus reducing run-time).
+However, inlined local functions cannot be passed as template parameters (e.g., to <c>std::for_each</c>) or assigned to other functors (e.g., to
+<c>boost::function</c>).
+That is true on C++03 compilers but inlined local functions can instead be
+passed as template parameters on C++11 compilers.
+On C++11 compilers, there is no need to declare a local function lined because
+this library will automatically use C++11 specific features to inline the local
+function while always allowing to pass it as a template parameter.
+
+The local function name can also be qualified by prefixing it with the
+"keyword" <c>recursive</c> (see the
+@RefSectId{Advanced_Topics, Advanced Topics} section):
+<c>BOOST_LOCAL_FUNCTION_NAME(recursive name)</c>.
+This allows the local function to recursively call itself from its body (as
+usual in C++).
+However, compilers have not been observed to be able to inline recursive
+local function calls (not even when the recursive local function is also
+declared inline: <c>BOOST_LOCAL_FUNCTION(inline recursive name)</c>).
+
+@Note The local function name cannot be the name of an operator
+<c>operator...</c> and it cannot be the same name of another local function
+declared within the same enclosing scope (the <c>boost::overloaded_function</c>
+functor can be used to overload local functions, see
+Boost.Functional/OverloadedFunction and the
+@RefSectId{Advanced_Topics, Advanced Topics} section).
+
+@See @RefMacro{BOOST_LOCAL_FUNCTION}, @RefSect{Tutorial} section,
+@RefSectId{Advanced_Topics, Advanced Topics} section.
+*/
+#define BOOST_LOCAL_FUNCTION_NAME(qualified_function_name)
/**
- * @brief This macro expands to the fully qualified type of a variable bound
- * to to local functions, local blocks, and local exits.
- *
- * The type is fully qualified in that it contains the extra constant and
- * reference qualifiers when they are specified for binding by constant and by
- * reference.
- * For example, if a variable named <c>t</c> of type <c>T</c> is:
- * @li Bound by value using <c>bind t</c> then
- * <c>BOOST_LOCAL_TYPEOF(t)</c> is <c>T</c>.
- * @li Bound by constant value using <c>const bind t</c>
- * then <c>BOOST_LOCAL_TYPEOF(t)</c> is <c>const T</c>.
- * @li Bound by reference using <c>bind& t</c>
- * then <c>BOOST_LOCAL_TYPEOF(t)</c> is <c>T&</c>.
- * @li Bound by constant reference using <c>const bind& t</c>
- * then <c>BOOST_LOCAL_TYPEOF(t)</c> is <c>const T&</c>.
- *
- * Within local functions, local blocks, and local exits, this macro can be
- * used to deduce the bound variable types to declare local variables, check
- * concepts (using Boost.ConceptCheck), etc (see @RefSect2{Advanced_Topics,
- * Advanced Topics} section).
- *
- * @Params
- * @Param{bound_variable_name,
- * The name of the bound variable for which the type is being deduced.
- * }
- * @EndParams
- *
- * @See @RefMacro{BOOST_LOCAL_FUNCTION_PARAMS}, @RefMacro{BOOST_LOCAL_BLOCK},
- * @RefMacro{BOOST_LOCAL_EXIT}, @RefSect2{Advanced_Topics, Advanced Topics}
- * section.
- */
+@brief This macro expands to the type of the specified bound variable.
+
+The type returned by the macro is fully qualified in that it contains the extra
+constant and reference qualifiers when the specified variable was bound by
+constant and by reference.
+
+@Params
+@Param{bound_variable_name,
+The name of one of the local function's bound variables.
+}
+@EndParams
+
+For example, if a variable named <c>t</c> of type <c>T</c> is:
+@li Bound by value using <c>bind t</c> then
+<c>BOOST_LOCAL_FUNCTION_TYPEOF(t)</c> is <c>T</c>.
+@li Bound by constant value using <c>const bind t</c> then
+<c>BOOST_LOCAL_FUNCTION_TYPEOF(t)</c> is <c>const T</c>.
+@li Bound by reference using <c>bind& t</c> then
+<c>BOOST_LOCAL_FUNCTION_TYPEOF(t)</c> is <c>T&</c>.
+@li Bound by constant reference using <c>const bind& t</c> then
+<c>BOOST_LOCAL_FUNCTION_TYPEOF(t)</c> is <c>const T&</c>.
+
+This macro can be used within the local functions body to refer to the bound
+variable types so to declare local variables, check concepts (using
+Boost.ConceptCheck), etc (see @RefSectId{Advanced_Topics, Advanced Topics}
+section).
+This way the local function can be programmed entirely without explicitly
+specifying the bound variable types thus facilitating maintenance (e.g., if
+the type of a bound variable changes in the enclosing scope, the local function
+code does not have to change).
+
+@See @RefMacro{BOOST_LOCAL_FUNCTION},
+@RefSectId{Advanced_Topics, Advanced Topics} section.
+*/
#define BOOST_LOCAL_FUNCTION_TYPEOF(bound_variable_name)
-#endif // DOXY
+#endif // DOXYGEN
#endif // #include guard
Modified: sandbox/local_function/boost/local_function/aux_/function.hpp
==============================================================================
--- sandbox/local_function/boost/local_function/aux_/function.hpp (original)
+++ sandbox/local_function/boost/local_function/aux_/function.hpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -12,12 +12,16 @@
# include <boost/local_function/aux_/config.hpp>
# include <boost/local_function/aux_/member.hpp>
# include <boost/call_traits.hpp>
+# include <boost/typeof/typeof.hpp>
+# include <boost/config.hpp>
# include <boost/preprocessor/iteration/iterate.hpp>
# include <boost/preprocessor/repetition/repeat.hpp>
# include <boost/preprocessor/repetition/enum.hpp>
# include <boost/preprocessor/punctuation/comma_if.hpp>
+# include <boost/preprocessor/arithmetic/add.hpp>
# include <boost/preprocessor/arithmetic/sub.hpp>
# include <boost/preprocessor/arithmetic/inc.hpp>
+# include <boost/preprocessor/control/iif.hpp>
# include <boost/preprocessor/cat.hpp>
// PRIVATE //
@@ -176,6 +180,18 @@
} } } // namespace
+// Register type for type-of emu (NAME use TYPEOF to deduce this fctor type).
+#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::local_function::aux::function,
+ BOOST_PP_ADD(2, // F and defaults tparams.
+ BOOST_PP_IIF(BOOST_LOCAL_FUNCTION_AUX_CONFIG_LOCALS_AS_TPARAMS_01,
+ 0 // No additional tparam.
+ ,
+ BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX // Bind tparams.
+ )
+ )
+)
+
#undef BOOST_LOCAL_FUNCTION_AUX_arg_type
#undef BOOST_LOCAL_FUNCTION_AUX_arg_typedef
#undef BOOST_LOCAL_FUNCTION_AUX_comma_arg_tparam
@@ -253,8 +269,7 @@
public:
// Provide public type interface following Boost.Function names
// (traits must be defined in both this and the local functor).
- /** @todo use BOOST_STATIC_CONST or similar */
- enum { arity = BOOST_LOCAL_FUNCTION_AUX_arity };
+ BOOST_STATIC_CONSTANT(size_t, arity = BOOST_LOCAL_FUNCTION_AUX_arity);
typedef R result_type;
BOOST_PP_REPEAT(BOOST_LOCAL_FUNCTION_AUX_arity,
BOOST_LOCAL_FUNCTION_AUX_arg_typedef, ~)
Modified: sandbox/local_function/boost/local_function/config.hpp
==============================================================================
--- sandbox/local_function/boost/local_function/config.hpp (original)
+++ sandbox/local_function/boost/local_function/config.hpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -4,40 +4,59 @@
// License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
// copy at http://www.boost.org/LICENSE_1_0.txt).
-/** @file
- * @brief Configuration macros allow to change the behaviour of this library
- * at compile-time.
- */
-
#ifndef BOOST_LOCAL_FUNCTION_CONFIG_HPP_
#define BOOST_LOCAL_FUNCTION_CONFIG_HPP_
-// User defined.
+#ifndef DOXYGEN
-/**
- * @brief Maximum number of function parameters supported for the local
- * functions.
- *
- * If programmers leave this configuration macro undefined, its default
- * value is <c>5</c>.
- *
- * This only applies to the number of local function parameters and not to the
- * number of bound variables in scope (the limit on the number of bound
- * variables is instead the maximum size allowed for a Boost.Preprocessor
- * sequence).
- *
- * @Warning Increasing this number will increase compilation time.
- *
- * @See @RefSect{Tutorial} section, @RefSect2{Getting_Started, Getting Started}
- * section.
- */
#ifndef BOOST_LOCAL_FUNCTION_CONFIG_FUNCTION_ARITY_MAX
-# define BOOST_LOCAL_FUNCTION_CONFIG_FUNCTION_ARITY_MAX 5
+#define BOOST_LOCAL_FUNCTION_CONFIG_FUNCTION_ARITY_MAX 5
#endif
#ifndef BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX
-# define BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX 10
+#define BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX 10
#endif
+#else // DOXYGEN
+
+/** @file
+@brief Configuration macros allow to change the behaviour of this library at
+compile-time.
+*/
+
+/**
+@brief Maximum number of parameters supported by local functions.
+
+If programmers leave this configuration macro undefined, its default
+value is <c>5</c> (increasing this number might increase compilation time).
+When defined by programmers, this macro must be a non-negative integer number.
+
+@Note This macro specifies the maximum number of local function parameters
+excluding bound variables (which are instead specified by
+@RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX}).
+
+@See @RefSect{Tutorial} section, @RefSectId{Getting_Started, Getting Started}
+section, @RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX}.
+*/
+#define BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX
+
+/**
+@brief Maximum number of bound variables supported by local functions.
+
+If programmers leave this configuration macro undefined, its default
+value is <c>10</c> (increasing this number might increase compilation time).
+When defined by programmers, this macro must be a non-negative integer number.
+
+@Note This macro specifies the maximum number of bound variables excluding
+local function parameters (which are instead specified by
+@RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX}).
+
+@See @RefSect{Tutorial} section, @RefSectId{Getting_Started, Getting Started}
+section, @RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX}.
+*/
+#define BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX
+
+#endif // DOXYGEN
+
#endif // #include guard
Modified: sandbox/local_function/boost/scope_exit.hpp
==============================================================================
--- sandbox/local_function/boost/scope_exit.hpp (original)
+++ sandbox/local_function/boost/scope_exit.hpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -674,6 +674,11 @@
capture:
[&]variable | this_ | this
@endcode
+
+(Where the following lexical conventions are adopted: <c>token1 | token2</c>
+means either <c>token1</c> or <c>token2</c>; <c>[token]</c> means either
+<c>token</c> or nothing; <c>{expression}</c> means the token resulting from the
+expression.)
}
@EndParams
@@ -778,6 +783,11 @@
capture:
[&]variable | this_ | this
@endcode
+
+(Where the following lexical conventions are adopted: <c>token1 | token2</c>
+means either <c>token1</c> or <c>token2</c>; <c>[token]</c> means either
+<c>token</c> or nothing; <c>{expression}</c> means the token resulting from the
+expression.)
}
@EndParams
Modified: sandbox/local_function/libs/local_function/doc/Jamfile.v2
==============================================================================
--- sandbox/local_function/libs/local_function/doc/Jamfile.v2 (original)
+++ sandbox/local_function/libs/local_function/doc/Jamfile.v2 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -7,29 +7,26 @@
import quickbook ;
using boostbook ;
-doxygen reference
+doxygen reference :
+ ../../../boost/local_function.hpp
+ ../../../boost/local_function/config.hpp
:
- ../../../boost/local_function.hpp
- ../../../boost/local_function/config.hpp
- :
- <doxygen:param>QUIET=YES
- <doxygen:param>WARN_IF_UNDOCUMENTED=NO
- <doxygen:param>HIDE_UNDOC_MEMBERS=YES
- <doxygen:param>HIDE_UNDOC_CLASSES=YES
- <doxygen:param>ALIASES=" Params=\"<b>Parameters:</b> <table border="0">\" Param{2}=\"<tr><td><b><tt>\\1</tt></b></td><td>\\2</td></tr>\" EndParams=\"</table>\" Returns=\"<b>Returns:</b>\" Note=\"<b>Note:</b>\" Warning=\"<b>Warning:</b>\" See=\"<b>See:</b>\" RefSect{1}=\"\\xmlonly<link linkend='local_function.\\1'>\\1</link>\\endxmlonly\" RefSectId{2}=\"\\xmlonly<link linkend='local_function.\\1'>\\2</link>\\endxmlonly\" RefClass{1}=\"\\xmlonly<computeroutput><classname alt='\\1'>\\1</classname></computeroutput>\\endxmlonly\" RefFunc{1}=\"\\xmlonly<computeroutput><functionname alt='\\1'>\\1</functionname></computeroutput>\\endxmlonly\" RefMacro{1}=\"\\xmlonly<computeroutput><macroname alt='\\1'>\\1</macroname></computeroutput>\\endxmlonly\" "
-
- # Extract Doxygen that comments non-variant macros.
- <doxygen:param>PREDEFINED="DOXY"
- <reftitle>"Reference"
- ;
+ <reftitle>"Reference"
+ <doxygen:param>PREDEFINED="DOXYGEN"
+ <doxygen:param>QUIET=YES
+ <doxygen:param>WARN_IF_UNDOCUMENTED=NO
+ <doxygen:param>HIDE_UNDOC_MEMBERS=YES
+ <doxygen:param>HIDE_UNDOC_CLASSES=YES
+ <doxygen:param>ALIASES=" Params=\"<b>Parameters:</b> <table border="0">\" Param{2}=\"<tr><td><b><tt>\\1</tt></b></td><td>\\2</td></tr>\" EndParams=\"</table>\" Returns=\"<b>Returns:</b>\" Note=\"<b>Note:</b>\" Warning=\"<b>Warning:</b>\" See=\"<b>See:</b>\" RefSect{1}=\"\\xmlonly<link linkend='boost_localfunction.\\1'>\\1</link>\\endxmlonly\" RefSectId{2}=\"\\xmlonly<link linkend='boost_localfunction.\\1'>\\2</link>\\endxmlonly\" RefClass{1}=\"\\xmlonly<computeroutput><classname alt='\\1'>\\1</classname></computeroutput>\\endxmlonly\" RefFunc{1}=\"\\xmlonly<computeroutput><functionname alt='\\1'>\\1</functionname></computeroutput>\\endxmlonly\" RefMacro{1}=\"\\xmlonly<computeroutput><macroname alt='\\1'>\\1</macroname></computeroutput>\\endxmlonly\" "
+;
xml doc : local_function.qbk :
<dependency>introduction.qbk
<dependency>getting_started.qbk
<dependency>tutorial.qbk
<dependency>advanced_topics.qbk
-# <dependency>reference
<dependency>examples.qbk
+ <dependency>reference
<dependency>alternatives.qbk
<dependency>no_variadic_macros.qbk
<dependency>implementation.qbk
Modified: sandbox/local_function/libs/local_function/doc/acknowledgements.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/acknowledgements.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/acknowledgements.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -6,7 +6,9 @@
[section:Acknowledgments Acknowledgments]
-This section attempts to recognize the contributions of /all/ the different people that participated directly or indirectly to the design and development of this library.
+@todo add thanks from the review
+
+This section aims to recognize the contributions of /all/ the different people that participated directly or indirectly to the design and development of this library.
Many thanks to Steven Watanabe and Vicente Botet for suggesting to me to use __Boost_ScopeExit__ binding to [@http://boost.2283326.n4.nabble.com/contract-diff-n1962-tt2671482.html#none emulate local functions].
Many thanks to Alexander Nasonov for clarifying how __Boost_ScopeExit__ binding could be used to implement local functions and for some [@http://thread.gmane.org/gmane.comp.lib.boost.devel/168612 early work] in this direction.
@@ -15,8 +17,7 @@
Thanks to David Abrahams, Vicente Botet, et al. for suggesting to provide the [@http://lists.boost.org/Archives/boost/2011/02/176712.php variadic macro syntax] on compilers that support variadic macros.
-Thanks to Pierre Morcello for suggesting to use `return;` to exit local blocks (in the context of a discussion about a possible [@http://lists.boost.org/Archives/boost/2009/09/156012.php Boost.Breakable] library).
-Thanks to Pierre also for sharing some code that experimented with implementing local functions using __Boost_ScopeExit__ binding (even if this library was not developed using such a code).
+Thanks to Pierre Morcello for sharing some code that experimented with implementing local functions using __Boost_ScopeExit__ binding (even if this library is not based on such a code).
Thanks to John Bytheway for checking the authors' virtual functor technique that originally allowed this library to pass local functions as template parameters.
Modified: sandbox/local_function/libs/local_function/doc/advanced_topics.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/advanced_topics.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/advanced_topics.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -6,8 +6,7 @@
[section:Advanced_Topics Advanced Topics]
-This section illustrates advanced usages of this library.
-At the end of this section there is also a list of knwon limitations of this library.
+This section illustrates advanced usages of this library (at the bottom there is also a list of known limitations of the library).
[section Default Parameters]
@@ -18,17 +17,17 @@
The assignment symbol `=` cannot be used to specify default parameter values because default values are not part of the parameter type so they cannot be handled using template metaprogamming.
Default parameter values need to be separated from the rest of the parameter declaration using the preprocessor.
Specifically, this library needs to use preprocessor mataprogramming to remove default values when constructing the local function type and then to count the number of default values to provide the correct set of call operators for the local functor.
-Therefore, the symbol `=` cannot be used because it cannot be handled by preprocessor metaprogramming (specifically, such a non-alphanumeric symbol cannot be detected by preprocessor metaprogramming because it cannot be concatenated by the preprocessor).
+Therefore, the symbol `=` cannot be used because it cannot be handled by preprocessor metaprogramming (non-alphanumeric symbols cannot be detected by preprocessor metaprogramming because it cannot be concatenated by the preprocessor).
]
The keyword `default` is used instead:
``[^/parameter-type parameter-name/]``, default`` [^/parameter-default-value/]``, ...
-For example, let's program a local function `add(x, y)` where the second parameter `y` is optional and has a default value of `2` (see also [@../../test/add_default.cpp `"add_default.cpp"`]):
+For example, let's program a local function `add(x, y)` where the second parameter `y` is optional and has a default value of `2` (see also [@../../test/add_default.cpp =add_default.cpp=]):
[test_add_default]
-Programmers can define a `WITH_DEFAULT` macro similar to the following if they think it improves readability over the syntax above (see also [@../../test/add_with_default.cpp `"add_with_default.cpp"`]):
+Programmers can define a `WITH_DEFAULT` macro similar to the following if they think it improves readability over the above syntax (see also [@../../test/add_with_default.cpp =add_with_default.cpp=]):
[footnote
The authors do not personally find the use of the `WITH_DEFAULT` macro more readable and they prefer to use the `default` "keyword" directly.
Furthermore, `WITH_DEFAULT` need to be defined differently for compilers without variadic macros `#define WITH_DEFAULT (default)` so it can only be defined by programmers based on the syntax they decide to use.
@@ -45,9 +44,8 @@
Therefore, using commas within the local function parameters and bindings will generate (cryptic) preprocessor errors unless they are wrapped with an extra set of round parenthesis `()` as explained here.
[note
-Macro parameters with commas which are already wrapped by round parenthesis `()` are fine (function calls, etc).
-However, macro parameters with commas that are not wrapped by round parenthesis need to be wrapped by an extra set of round parenthesis `()` as described here.
Also macro parameters with commas wrapped by angular parenthesis `<>` (templates, etc) or square parenthesis `[]` (multidimensional array access, etc) need to be wrapped by the extra round parenthesis `()` as explained here (this is because the preprocessor only recognizes the round parenthesis and it does not recognize angular, square, or any other type of parenthesis).
+However, macro parameters with commas which are already wrapped by round parenthesis `()` are fine (function calls, some value expressions, etc).
]
In addition, local function parameter types cannot start with non-alphanumeric symbols (alphanumeric symbols are `A-Z`, `a-z`, and `0-9`).
@@ -62,8 +60,8 @@
void BOOST_LOCAL_FUNCTION(
const std::map<std::string, size_t>& m, // (1) Error.
::sign_t sign, // (2) Error.
- const size_t& factor, default
- key_size<std::string, size_t>::value, // (3) Error.
+ const size_t& factor,
+ default key_sizeof<std::string, size_t>::value, // (3) Error.
const std::string& separator, default cat(":", " ") // (4) OK.
) {
...
@@ -71,34 +69,43 @@
[*(1)] The parameter type `const std::map<std::string, size_t>&` contains a comma `,` after the first template parameter `std::string`.
This comma is not wrapped by any round parenthesis `()` thus it will cause a preprocessor error.
-The __Boost_Utility__ macro `BOOST_IDENTITY_TYPE(`/parenthesized-type/`)` from the header `"boost/utility/identity_type.hpp"` can be used to wrap a type within extra parenthesis `()` so to overcome this issue:
+[footnote
+The preprocessor always interprets unwrapped commas as separating macro parameters.
+Thus in this case the comma will indicate to the preprocessor that the first macro parameter is `const std::map<std::tring`, the second macro parameter is `size_t>& m`, etc instead of passing `const std::map<std::string, size_t>& m` as a single macro parameter.
+]
+The __Boost_Utility__ macro `BOOST_IDENTITY_TYPE(`/parenthesized-type/`)` from the header =boost/utility/identity_type.hpp= can be used to wrap a type within extra parenthesis `()` so to overcome this issue:
#include <boost/utility/identity_type.hpp>
void BOOST_LOCAL_FUNCTION(
- BOOST_IDENTITY_TYPE((const std::map<std::string, size_t>&)) m, // OK.
+ BOOST_IDENTITY_TYPE((const std::map<std::string, size_t>&)) m, // OK.
...
) {
...
} BOOST_LOCAL_FUNCTION_NAME(f)
This macro expands to an expression that evaluates (at compile-time) exactly to the specified type.
-Note that a total of two set of parenthesis `()` are needed: The parenthesis to invoke the `BOOST_IDENTITY_TYPE(..)` macro plus the parenthesis to wrap the type expression (and therefore any comma `,` that it contains) passed as parameter to the `BOOST_IDENTITY_TYPE((...)` macro.
+Note that a total of two set of parenthesis `()` are needed: The parenthesis to invoke the `BOOST_IDENTITY_TYPE(...)` macro plus the parenthesis to wrap the type expression (and therefore any comma `,` that it contains) passed as parameter to the `BOOST_IDENTITY_TYPE((...))` macro.
[footnote
*Rationale.*
Using variadic macros, this extra set of parenthesis could be eliminated requiring only the parenthesis to invoke the `BOOST_IDENTITY_TYPE` macro.
However, this feature is currently not implemented and the double parenthesis are always needed when invoking this macro.
]
-Finally, the `BOOST_IDENTITY_TYPE` macro must be prefixed by the `typename` keyword as in `typename BOOST_IDENTITY_TYPE(`/parenthesized-type/`)` when used within [macroref BOOST_LOCAL_FUNCTION_TPL] for templates.
+Finally, the `BOOST_IDENTITY_TYPE` macro must be prefixed by the `typename` keyword:
+
+ typename BOOST_IDENTITY_TYPE(``/parenthesized-type/``)
+
+When used together with the [macroref BOOST_LOCAL_FUNCTION_TPL] macro within templates.
[note
Often, there might be better ways to overcome this limitation that lead to code which is more readable than the one using the `BOOST_IDENTITY_TYPE` macro.
-For example, in this case a `typedef` could have been used in the enclosing scope to obtain the following valid and perhaps more readable code:
]
+For example, in this case a `typedef` could have been used in the enclosing scope to obtain the following valid and perhaps more readable code:
+
typedef std::map<std::string, size_t> map_type;
void BOOST_LOCAL_FUNCTION(
- const map_type& m, // OK.
+ const map_type& m, // OK (and more readable).
...
) BOOST_LOCAL_FUNCTION_NAME(f)
@@ -115,25 +122,26 @@
[note
Often, there might be better ways to overcome this limitation that lead to code which is more readable than the one using the `BOOST_IDENTITY_TYPE` macro.
-For example, in this case the symbols `::` could have been simply dropped to obtain the following valid and perhaps more readable code:
]
+For example, in this case the symbols `::` could have been simply dropped to obtain the following valid and perhaps more readable code:
+
void BOOST_LOCAL_FUNCTION(
...
- sign_t sign, // OK.
+ sign_t sign, // OK (and more readable).
...
) {
...
} BOOST_LOCAL_FUNCTION_NAME(f)
-[*(3)] The default parameter value `key_size<std::string, size_t>::value` contains a comma `,` after the first template parameter `std::string`.
+[*(3)] The default parameter value `key_sizeof<std::string, size_t>::value` contains a comma `,` after the first template parameter `std::string`.
Again, this comma is not wrapped by any parenthesis `()` so it will cause a preprocessor error.
Because this is a value expression (and not a type expression), it can be simply wrapped within an extra set of round parenthesis `()`:
void BOOST_LOCAL_FUNCTION(
...
- const size_t& factor, default
- (key_size<std::string, size_t>::value), // OK.
+ const size_t& factor,
+ default (key_sizeof<std::string, size_t>::value), // OK.
...
) {
...
@@ -141,13 +149,17 @@
[*(4)] The default parameter value `cat(":", " ")` is instead fine because it contains a comma `,` which is already wrapped by the parenthesis `()` of the function call `cat(...)`.
+Consider the following complete example (see also [@../../test/macro_commas.cpp =macro_commas.cpp=]):
+
+[test_macro_commas]
+
[endsect]
[section Assigning and Returning]
Local functions are function objects so it is possible to assign them to other functors like __Boost_Function__ `boost::function` in order to store the local function into a variable, pass it as a parameter to another function, or return it from the enclosing function.
-For example (see also [@../../test/return_assign.cpp `"return_assign.cpp"`]):
+For example (see also [@../../test/return_assign.cpp =return_assign.cpp=]):
[test_return_assign]
@@ -155,13 +167,12 @@
[important
As with __CPP11_lambda__ functions, programmers are responsible to ensure that bound references are valid in any scope where the local function object is called.
+(This might be tricky to verify in a program when local functions are returned and called outside the local scope of their declaration.)
]
-This might be tricky to verify in a program so in general it is better to never bind by reference when a local function is returned by the enclosing scope to a different scope (see a few examples on this topic in the __Examples__ section).
-
In addition, a local function can bind and call another local function.
Local functions should always be bound by constant reference `const bind&` to avoid unnecessary copies.
-For example, the following local function `inc_sum` binds the local function `inc` so `inc_sum` can call `inc` (see aslo [@../../test/transform.cpp `"transform.cpp"`]):
+For example, the following local function `inc_sum` binds the local function `inc` so `inc_sum` can call `inc` (see aslo [@../../test/transform.cpp =transform.cpp=]):
[test_transform]
@@ -170,7 +181,7 @@
[section Nesting]
It is possible to nest local functions into one another.
-For example (see also [@../../test/nesting.cpp `"nesting.cpp"`]):
+For example (see also [@../../test/nesting.cpp =nesting.cpp=]):
[test_nesting]
@@ -178,23 +189,20 @@
[section Deducing Bound Types (concepts, etc)]
-This library never requires to explicitly specify the type of the bound variables.
+This library never requires to explicitly specify the type of bound variables.
From within local functions, programmers can access the type of a bound variable using the following macro:
BOOST_LOCAL_FUNCTION_TYPEOF(``/bound-variable-name/``)
The [macroref BOOST_LOCAL_FUNCTION_TYPEOF] macro expands to a type expression that evaluates (at compile-time) to the fully qualified type of the bound variable with the specified name.
-
-[note
This type expression is fully qualified in the sense that it will be constant if the variable is bound by constant `const bind[&]` and it will also be a reference is the variable is bound by reference `[const] bind&` (if needed, programmers can strip away the `const` and `&` qualifiers using `boost::remove_const` and `boost::remove_reference`, see __Boost_TypeTraits__).
-]
-The deduced bound type can be used within the body to declare a local variable, to check concepts, etc.
-For example (see also [@../../test/typeof.cpp `"typeof.cpp"`] and [@../../test/addable.hpp `"addable.hpp"`]):
+The deduced bound type can be used within the body to check concepts, declare local variables, etc.
+For example (see also [@../../test/typeof.cpp =typeof.cpp=] and [@../../test/addable.hpp =addable.hpp=]):
[test_typeof]
-Within templates, [macroref BOOST_LOCAL_FUNCTION_TYPEOF] does not require to be prefixed by the `typename` keyword but eventual type manipulations need the `typename` prefix as usual (see also [@../../test/typeof_template.cpp `"typeof_template.cpp"`] and [@../../test/addable.hpp `"addable.hpp"`]):
+Within templates, [macroref BOOST_LOCAL_FUNCTION_TYPEOF] does not require to be prefixed by the `typename` keyword but eventual type manipulations need the `typename` prefix as usual (see also [@../../test/typeof_template.cpp =typeof_template.cpp=] and [@../../test/addable.hpp =addable.hpp=]):
[test_typeof_template]
@@ -202,37 +210,39 @@
[section Specifying Types]
-While not required, it is possible to explicitly specify the type of a bound variable so the library will not internally use __Boost_Typeof__ to automatically deduce the type.
+While not required, it is possible to explicitly specify the type of a bound variable so the library will not internally use __Boost_Typeof__ to automatically deduce such a type.
When specified, the bound variable type must follow the `bind` "keyword" and it must be wrapped within round parenthesis `()`:
bind(``/variable-type/``) ``/variable-name/`` // Bind by value with explicit type.
bind(``/variable-type/``)& ``/variable-name/`` // Bind by reference with explicit type.
const bind(``/variable-type/``) ``/variable-name/`` // Bind by constant value with explicit type.
const bind(``/variable-type/``)& ``/variable-name/`` // Bind by constant reference with explicit type.
- bind(``/class-type/``*) this_ // Bind object `this` with type.
- const bind(``/class-type/``*) this_ // Bind object `this` by constant with type.
+ bind(``/class-type/``*) this_ // Bind object `this` with explicit type.
+ const bind(``/class-type/``*) this_ // Bind object `this` by constant with explicit type.
Note that within the local function body it is always possible to abstract the access to the type of a bound variable using [macroref BOOST_LOCAL_FUNCTION_TYPEOF] (even when the bound variable type is explicitly specified).
-The library also needs to use __Boost_Typeof__ to determine the local function result type because this type specified outside the [macroref BOOST_LOCAL_FUNCTION] macro.
-Thus it is also possible to specify the local function result type as one of the [macroref BOOST_LOCAL_FUNCTION] macro parameters prefixed by `return` so the library will not use __Boost_Typeof__ to deduce it:
+The library also uses __Boost_Typeof__ to determine the local function result type (because this type specified outside the [macroref BOOST_LOCAL_FUNCTION] macro).
+Thus it is also possible to specify the local function result type as one of the [macroref BOOST_LOCAL_FUNCTION] macro parameters prefixed by `return` so the library will not use __Boost_Typeof__ to deduce the result type:
BOOST_LOCAL_FUNCTION_TYPE(return ``[^/result-type/]``, ...)
-The following example specifies the type of all bound variables and of the local function result (see also [@../../test/add_typed.cpp `"add_typed.cpp"`]):
+Note that the result type must be specified only once either before the macro (without the `return` prefix) or as one of the macro parameters (with the `return` prefix).
+As usual, the result type can always be `void` to declare a function returning nothing (so `return void` is allowed when the result type is specified as one of the macro parameters).
+
+The following example specifies the type of all bound variables and of the local function result (see also [@../../test/add_typed.cpp =add_typed.cpp=]):
[footnote
-In the examples of this documentation, we specify bound variables, function parameters, and result type in this order because that is the order used by __CPP11_lambda__ functions.
+In the examples of this documentation, we specify bound variables, function parameters, and result type in this order because this is the order used by __CPP11_lambda__ functions.
However, the library accepts bound variables, function parameters, and the result type in any order.
]
[test_add_typed]
Unless necessary, it is recommended to not specify the bound variable and result types.
-Let the library deduce these types so the local function syntax is more concise and the local function declaration will not have to change if a bound variable type changes (facilitating maintenance).
+Let the library deduce these types so the local function syntax will be more concise and the local function declaration will not have to change if a bound variable type changes (facilitating maintenance).
[note
-Even when the result type and all bound variable types are explicitly specified, the library implementation still internally uses __Boost_Typeof__ to deduce the local function object type (see the __Implementation__ section).
-However, this type is automatically registered with __Boost_Typeof__ by this library so programmers will never be required to perform explicit __Boost_Typeof__ registrations when they specify all result and bound variable types.
+Unfortunately, the current implementation implementation still internally uses __Boost_Typeof__ once to deduce the local function object type (see the __Implementation__ section) even when all bound variable and result types are explicitly specified.
]
[endsect]
@@ -250,6 +260,8 @@
* On __CPP03__ compliant compilers, inlined local functions always have a run-time comparable to their equivalent implementation that uses local functors (see the __Alternatives__ section).
However, inlined local functions have the important limitation that they cannot be assigned to other functors (like `boost::function`) and they cannot be passed as template parameters.
+* On __CPP11__ compilers, `inline` has no effect because this library will automatically generate code that uses __CPP11__ specific features to inline the local function calls whenever possible even if the local function is not declared inline.
+Furthermore, non __CPP11__ local functions can always be passes as template parameters even when they are declared inline.
[footnote
*Rationale.*
This library uses an indirect function call via a function pointer in order to pass the local function as a template parameter (see the __Implementation__ section).
@@ -257,14 +269,12 @@
Therefore, inlined local functions do not use such indirect function pointer call (so they are more likely to be optimized) but because of that they cannot be passed as template parameters.
The indirect function pointer call is needed on __CPP03__ but it is not needed on __CPP11__ (see __N2657__) thus this library automatically generates local function calls that can be inlined on __CPP11__ compilers (even when the local function is not declared inline).
]
-* On __CPP11__ compilers, `inline` has no effect because this library will automatically generate code that uses __CPP11__ specific features to inline the local function calls whenever possible even if the local function is not declared inline.
-Furthermore, non __CPP11__ local functions can always be passes as template parameters even when they are declared inline.
[important
-It is recommended to not declare a local function inlined unless it is strictly necessary for optimizing pure __CPP03__ compliant code (because in all other cases this library will automatically take advantage of __CPP11__ features to optimize the local function calls while always allowing to pass the local function as a template parameter).
+It is recommended to not declare a local function inline unless it is strictly necessary for optimizing pure __CPP03__ compliant code (because in all other cases this library will automatically take advantage of __CPP11__ features to optimize the local function calls while always allowing to pass the local function as a template parameter).
]
-For example, the following local function is declared inlined (thus a for-loop needs to be used for portability instead of passing the local function as a template parameter to the `std::for_each` algorithm, see also [@../../test/add_inline.cpp `"add_inline.cpp"`]):
+For example, the following local function is declared inline (thus a for-loop needs to be used for portability instead of passing the local function as a template parameter to the `std::for_each` algorithm, see also [@../../test/add_inline.cpp =add_inline.cpp=]):
[test_add_inline]
@@ -273,36 +283,36 @@
[section Recursion]
Local functions can be declared [@http://en.wikipedia.org/wiki/Recursion_(computer_science)#Recursive_procedures recursive] so a local function can recursively call itself from its body (as usual with C++ functions).
-A local function is declared recursive by prefixing the local function name passed to [macroref BOOST_LOCAL_FUNCTION_NAME] macro with the "keyword" `recursive`:
+A local function is declared recursive by prefixing the local function name passed to [macroref BOOST_LOCAL_FUNCTION_NAME] macro with the "keyword" `recursive` (thus `recursive` is not a valid local function name):
``/result-type/`` BOOST_LOCAL_FUNCTION(``/parameters/``) {
... // Body.
} BOOST_LOCAL_FUNCTION_NAME(recursive ``/name/``) // Recursive.
-For example, the following local function is used to recursively calculate the factorials of all the numbers in the specified vector (see also [@../../test/factorial.cpp `"factorial.cpp"`]):
+For example, the following local function is used to recursively calculate the factorials of all the numbers in the specified vector (see also [@../../test/factorial.cpp =factorial.cpp=]):
[test_factorial]
-Compilers have not been observed to be able to inline recursive local function calls (not even when the recursive local function is also declared inline).
+Compilers have not been observed to be able to inline recursive local function calls (not even when the recursive local function is also declared inline as in `BOOST_LOCAL_FUNCTION_NAME(inline recursive factorial)`).
[warning
-Recursive local functions should never be assigned to another functor object or called outside their declaration scope.
-Therefore, if a local function is assigned to `boost::function`, returned from the enclosing function, and called in a different scope, the result in undefined behaviour (which will likely generate a run-time error).
+Recursive local functions should never be called outside their declaration scope.
+If a local function is returned from the enclosing function and called in a different scope, the behaviour is undefined (and it will likely result in a run-time error).
[footnote
*Rationale.*
-This limitation comes from the fact that a global functor used to pass the local function as a template parameter (and eventually use it outside its declarations scope) does not know the local function name so the local function name used for recursive call cannot be set in the global functor.
-This limitation and preventing the possibility for inlining is also the reason why local function are not recursive unless programmers explicitly declare them `recursive`.
+This limitation comes from the fact that the global functor used to pass the local function as a template parameter (and eventually returned outside the declarations scope) does not know the local function name so the local function name used for recursive call cannot be set in the global functor.
+This limitation together with preventing the possibility for inlining are the reasons why local functions do not allow for recursion unless programmers explicitly declare them `recursive`.
]
-This is not a limitation with respect to __CPP11_lambda__ functions because lambdas can never call themselves recursively (in other words, there is no recursive lambda function that can successfully be called outside its declaration scope because there is no recursive lambda function period).
+This is not a limitation with respect to __CPP11_lambda__ functions because lambdas can never call themselves recursively (in other words, there is no recursive lambda function that can successfully be called outside its declaration scope because there is no recursive lambda function at all).
]
[endsect]
[section Overloading]
-It is possible to overload local functions using __Boost_FunctionalOverloadedFunction__ `boost::overloaded_function` from the header `"boost/functional/overloaded_function.hpp"` (see the __Boost_FunctionalOverloadedFunction__ documentation for more detail).
+It is possible to overload local functions using the `boost::overloaded_function` functor of __Boost_FunctionalOverloadedFunction__ from the header =boost/functional/overloaded_function.hpp= (see the __Boost_FunctionalOverloadedFunction__ documentation for details).
-In the following example, the overloaded function object `add` can be called with signatures from either the local function `add_s`, or the local function `add_d`, or the local function `add_d` with its extra default parameter, or the function pointer `add_i` (see also [@../../test/overload.cpp `"overload.cpp"`]):
+In the following example, the overloaded function object `add` can be called with signatures from either the local function `add_s`, or the local function `add_d`, or the local function `add_d` with its extra default parameter, or the function pointer `add_i` (see also [@../../test/overload.cpp =overload.cpp=]):
[test_overload]
@@ -317,7 +327,7 @@
For example, even if the body code is specified to throw no exception using `throw () { ... }`, the execution of the library code automatically generated by the macros could still throw (if there is no memory, etc).
]
-For example (see also [@../../test/add_except.cpp `"add_except.cpp"`]):
+For example (see also [@../../test/add_except.cpp =add_except.cpp=]):
[test_add_except]
@@ -339,7 +349,7 @@
register ``/parameter-type parameter-name/``
-For example (see also [@../../test/add_classifiers.cpp `"add_classifiers.cpp"`]):
+For example (see also [@../../test/add_classifiers.cpp =add_classifiers.cpp=]):
[test_add_classifiers]
@@ -404,7 +414,7 @@
[
[ [^/function-name/] ]
[ Yes ]
- [ Local functions are named and they can call themselves recursively but they cannot be overloaded and they cannot be operators (see the __Tutorial__ and __Advanced_Topics__ sections). ]
+ [ Local functions are named and they can call themselves recursively but they cannot be operators (see the __Tutorial__ and __Advanced_Topics__ sections). ]
]
[
[ [^/parameter-list/] ]
@@ -432,42 +442,17 @@
This is the because a local function name must be a valid local variable name (the local variable to hold the local functor) and operators cannot be used as local variable names.
]
-For example, the following code will *not* compile:
+For example, the following code will not compile:
- void f() {
- struct point {
- double x;
- double y;
- };
-
- bool BOOST_LOCAL_FUNCTION(const point& p, const point& q) {
- return p.x == q.x && p.y == q.y;
- ) BOOST_LOCAL_FUNCTION_NAME(operator==) // Error: Cannot use `operator==`.
-
- ...
- }
+[test_operator_err]
[h5 Goto]
-It is not possible to jump with a `goto` from within a local function, local block, or local exit to a label defined in the enclosing scope.
-
-For example, the following will *not* compile:
-
- int f() {
- void BOOST_LOCAL_FUNCTION(bool error) {
- if (error) goto failure; // Error: Cannot jump to enclosing label `failure`.
- else goto success; // Ok: Can jump within enclosing scope.
-
- success:
- ...
- } BOOST_LOCAL_FUNCTION_NAME(f)
+It is not possible to jump with a `goto` from within a local function to a label defined in the enclosing scope.
- f(true);
+For example, the following will not compile:
- return 0;
- failure:
- return -1;
- }
+[test_goto_err]
[endsect]
Modified: sandbox/local_function/libs/local_function/doc/alternatives.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/alternatives.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/alternatives.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -4,11 +4,11 @@
[/ License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a ]
[/ copy at http://www.boost.org/LICENSE_1_0.txt). ]
-[section:Alternatives Appendix: Alternatives]
+[section:Alternatives Annex: Alternatives]
This section compares the features offered by this library with similar features offered by other libraries and by the new __CPP11__ standard.
-[section Features]
+[h5 Features]
The following table compares local function features.
@@ -144,9 +144,7 @@
[add_using_boost_phoenix_cpp]
-[endsect]
-
-[section Performances]
+[h5 Performances]
The following tables compare run-times, compile-times, and binary sizes for the different alternatives presented so far for local functions.
@@ -236,5 +234,3 @@
[endsect]
-[endsect]
-
Modified: sandbox/local_function/libs/local_function/doc/bibliography.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/bibliography.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/bibliography.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -8,6 +8,8 @@
This section lists all the bibliographic references cited by this documentation.
+@todo complete this
+
__N2511__ Alisdair Meredith. /Named Lambdas and Local Functions./ The C++ Standards Committee, document no. N2511=08-0021, 2008.
__N2529__ Jaakko Jarvi, John Freeman, Lawrence Crowl. /Lambda Expressions and Closures: Wording for Monomorphic Lambdas (Revision 3)./ The C++ Standards Committee, document no. N2529=08-0039, 2008.
Modified: sandbox/local_function/libs/local_function/doc/examples.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/examples.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/examples.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -4,38 +4,38 @@
[/ License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a ]
[/ copy at http://www.boost.org/LICENSE_1_0.txt). ]
-[section:Examples Appendix: Examples]
+[section:Examples Examples]
-This sections lists some (interesting) examples that use this library features.
+This sections lists some examples that use this library features.
[section GCC Lambdas (Without C++11)]
-Combing local functions with the [@http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html statement expression] GCC extension, it is possible to implement lambda functions for GCC compilers even without __CPP11__ support.
+Combing local functions with the [@http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html statement expression] extension of GCC compilers, it is possible to implement lambda functions for GCC compilers even without __CPP11__ support.
[warning
This code only works on compilers that support the statement expression GCC extension or that support __CPP11_lambda__ functions.
]
-For example (see also [@../../example/gcc_lambda.cpp `"gcc_lambda.cpp"`] and [@../../example/gcc_lambda_cpp11.cpp `"gcc_lambda_cpp11.cpp"`]):
+For example (see also [@../../example/gcc_lambda.cpp =gcc_lambda.cpp=] and [@../../example/gcc_lambda_cpp11.cpp =gcc_lambda_cpp11.cpp=]):
[table
[ [With Local Functions (GCC only)] [C++11 Lambdas] ]
[ [[example_gcc_lambda]] [[example_gcc_lambda_cpp11]] ]
]
-The macros are defined in [@../../example/gcc_lambda.hpp `"gcc_lambda.hpp"`].
+Where the macros are defined in [@../../example/gcc_lambda.hpp =gcc_lambda.hpp=].
-This is possible because GCC statement expressions allow to put declaration statements within expressions and therefore to declare a local function within an expression.
-The macros automatically detect if the compiler supports __CPP11_lambda__ functions in which case the implementation uses native lambdas instead of local functions.
+This is possible because GCC statement expressions allow to use declaration statements within expressions and therefore to declare a local function within an expression.
+The macros automatically detect if the compiler supports __CPP11_lambda__ functions in which case the implementation uses native lambdas instead of local functions in statement expressions.
However, __CPP11_lambda__ functions do not support constant binding so it is best to only use `const bind variable` (same as __CPP11_lambda__ `=variable`) and `bind& variable` (same as __CPP11_lambda__ `&variable`) because these have the exact same semantic between the local function and native lambda implementation.
Unfortunately, the __CPP11_lambda__ short-hand binds `&` and `=` (which automatically bind all variables in scope either by reference or value) are not supported by the macros because they are not supported by the local function implementation.
-Finally, the result type `return `[^/result-type/] is optional and it is assumed `void` when it is not specified (as with __CPP11_lambda__ functions).
+Finally, the result type `return `[^/result-type/] is optional and it is assumed `void` when it is not specified (same as with __CPP11_lambda__ functions).
[endsect]
[section Constant Blocks]
-It is possible to use local functions to check assertions between variables that are constant within the assertion expression.
+It is possible to use local functions to check assertions between variables that are made constant within the asserted expression.
This is advantageous because assertions are not supposed to change the state of the program and ideally the compiler will not compile assertions that modify variables.
For example, consider the following assertion where by mistake we programmed `operator=` instead of `operator==`:
@@ -44,27 +44,30 @@
assert(x = y); // Mistakenly `=` instead of `==`.
Ideally this code will not compile instead this example not only compiles but the assertion even passes the run-time check and no error is generated at all.
-The __N1613__ paper introduced the idea of a /const-block/ which could be used to wrap the assertion above and catch the mistake at compile-time.
-Similarly to __N1613__ const-blocks, the following code will generate a compile-time error when `operator=` is mistakenly used instead of `operator==` because both `x` and `y` are constants within the block of code performing the assertion (see also [@../../example/const_block.cpp `"const_block.cpp"`]):
+The __N1613__ paper introduced the idea of a /const-block/ which could be used to wrap the assertion above and catch the programming error at compile-time.
+Similarly, the following code will generate a compile-time error when `operator=` is mistakenly used instead of `operator==` because both `x` and `y` are made constants (using local functions) within the block of code performing the assertion (see also [@../../example/const_block.cpp =const_block.cpp=]):
[table
[ [With Local Functions] [N1613 Constant Block] ]
[ [[example_const_block]] [``
int x = 1, y = 2;
- const { // Constant block.
- assert(x = y); // Compiler error.
+ const { // Constant block.
+ assert(x = y); // Compiler error.
}
``] ]
]
-The macros are defined in [@../../example/const_block.hpp `"const_block.hpp"`].
+Where the macros are defined in [@../../example/const_block.hpp =const_block.hpp=].
-The constant block macros are implemented using a local function which binds by constant reference `const bind&` all the specified variables, it executes the `assert` instruction in local function body, and the local function is then called immediately after it is defined.
+The constant block macros are implemented using a local function which binds by constant reference `const bind&` all the specified variables (so the variables are constant within the code block but they do not need to be `CopyConstructible` and no extra copy is performed).
+The local function executes the `assert` instruction its body which is called immediately after it is defined.
More in general, constant blocks can be used to evaluate any instruction (not just assertions) within a block were all specified variables are constant.
-Unfortunately, constant blocks cannot be implemented with __CPP11_lambda__ functions because these do not support constant binding.
-Ideally, __CPP11_lambda__ functions would allow to bind variables also using `const& variable` (constant reference) and `const&` (all variables by constant reference).
+Unfortunately, constant blocks cannot be implemented with __CPP11_lambda__ functions because these do not support constant binding (of course it is always possible to introduce extra constant variables `const int& const_x = x;` and use these variables in the assertion).
Variables bound by value using __CPP11_lambda__ functions (`variable`, `=variable`, and `=`) are constant but they are required to be `CopyConstructible` and they introduce potentially expensive copy operations.
+[footnote
+Ideally, __CPP11_lambda__ functions would allow to bind variables also using `const& variable` (constant reference) and `const&` (all variables by constant reference).
+]
[endsect]
@@ -77,7 +80,7 @@
__Boost_ScopeExit__ does not directly support constant binding (however, it is always possible to introduce an extra `const` local variable, assign it to the value to bind, and then bind the `const` variable so to effectively have constant binding with __Boost_ScopeExit__ as well).
In general, the authors recommend to use __Boost_ScopeExit__ instead of the code listed here whenever possible.
-The following example binds `p` by constant reference so this variable cannot be modified within the scope exit body but it is not copied and it will present the value it has at the exit of the enclosing scope and not at the scope exit declaration (see also [@../../example/scope_exit.cpp `"scope_exit.cpp"`]):
+The following example binds `p` by constant reference so this variable cannot be modified within the scope exit body but it is not copied and it will present the value it has at the exit of the enclosing scope and not at the scope exit declaration (see also [@../../example/scope_exit.cpp =scope_exit.cpp=]):
[table
[ [With Local Functions] [Boost.ScopeExit] ]
@@ -91,29 +94,62 @@
``] ]
]
-The macros are defined in [@../../example/scope_exit.hpp `"scope_exit.hpp"`].
+Where the macros are defined in [@../../example/scope_exit.hpp =scope_exit.hpp=].
-The scope exit macros are implemented by passing a local function to the constructor of the following object:
+The scope exit macros are implemented by passing a local function when constructing an object of the following class:
[example_scope_exit_object]
-The object variable is declared locally within the enclosing scope so the object destructor will be invoked at the exit of the enclosing scope and it will in turn call the local function.
+A local variable within the enclosing scope is used to hold the object so the destructor will be invoked at the exit of the enclosing scope and it will in turn call the local function executing the scope exit instructions.
The scope exit local function has no parameter and `void` result type but it supports binding and constant binding.
[endsect]
+[section Boost.Phoenix Functions]
+
+Local functions can be used to create __Boost_Phoenix__ functions.
+For example (see also [@../../example/boost_phoenix_local_factorial.cpp =boost_phoenix_local_factorial.cpp=] and [@../../example/boost_phoenix_factorial.cpp =boost_phoenix_factorial.cpp=]):
+
+[table
+ [ [Local Functions] [Global Functor] ]
+ [ [[example_boost_phoenix_local_factorial]] [[example_boost_phoenix_factorial]] ]
+]
+
+This is presented here mainly as a curiosity because __Boost_Phoenix__ functions created from local functions have the important limitation that they cannot be polymorphic.
+[footnote
+*Rationale.*
+Local functions can only be monomorphic because they are implemented using local classes and local classes cannot be templates in C++ (not even in __CPP11__).
+]
+Therefore, in many cases creating the __Boost_Phoenix__ function from global functors (possibly with the help of __Boost_Phoenix__ adaptor macros) might be a more valuable option.
+
+[endsect]
+
+[section Closures]
+
+A few more examples on how to return local functions to the calling scope (and the relative precautions to take) mainly adapted from examples of [@http://en.wikipedia.org/wiki/Closure_(computer_science) closures].
+
+[table
+ [ [Files] ]
+ [ [[@../../test/return_inc.cpp =return_inc.cpp=]] ]
+ [ [[@../../test/return_this.cpp =return_this.cpp=]] ]
+ [ [[@../../test/return_setget.cpp =return_setget.cpp=]] ]
+ [ [[@../../test/return_derivative.cpp =return_derivative.cpp=]] ]
+]
+
+[endsect]
+
[section GCC Nested Functions]
The GCC C compiler supports local functions under the name of [@http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html nested functions].
Nested functions are exclusively a C extension of the GCC compiler (they are not supported for C++ not even by the GCC compiler, and they are not part of any C or C++ standard, nor they are supported by other compilers like MSVC).
-The following examples are taken form the GCC nested function documentation but are programmed using this library:
+The following examples are taken form the GCC nested function documentation and programmed using this library:
[table
[ [Files] ]
- [ [[@../../example/gcc_square.cpp `"gcc_square.cpp"`]] ]
- [ [[@../../example/gcc_access.cpp `"gcc_access.cpp"`]] ]
- [ [[@../../example/gcc_store.cpp `"gcc_store.cpp"`]] ]
+ [ [[@../../example/gcc_square.cpp =gcc_square.cpp=]] ]
+ [ [[@../../example/gcc_access.cpp =gcc_access.cpp=]] ]
+ [ [[@../../example/gcc_store.cpp =gcc_store.cpp=]] ]
]
[endsect]
@@ -124,10 +160,10 @@
[table
[ [Files] [Notes] ]
- [ [[@../../example/n2550_find_if.cpp "n2550_find_if.cpp"]] [
+ [ [[@../../example/n2550_find_if.cpp =n2550_find_if.cpp=]] [
This example is adapted from __N2550__ (__CPP11_lambda__ functions): It passes a local function to the STL algorithm `std::find_if`.
] ]
- [ [[@../../example/n2529_this.cpp "n2529_this.cpp"]] [
+ [ [[@../../example/n2529_this.cpp =n2529_this.cpp=]] [
This example is adapted from __N2529__ (__CPP11_lambda__ functions): It binds the object in scope `this` to a local function.
] ]
]
Modified: sandbox/local_function/libs/local_function/doc/getting_started.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/getting_started.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/getting_started.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -6,21 +6,21 @@
[section:Getting_Started Getting Started]
-This section explains how to setup a system to use this library.
+This section explains how programmers can setup their system to use this library.
[section This Documentation]
Programmers should have enough knowledge to use this library after reading the __Introduction__, __Getting_Started__, and __Tutorial__ sections.
The __Advanced_Topics__ and __Reference__ sections can be consulted at a later point to gain a more advanced knowledge of the library.
-All the other sections of this documentation are optional.
+All the other sections of this documentation can be considered optional.
Some footnotes are marked by the word "*Rationale*".
They explain reasons behind decisions made during the design and implementation of this library.
-In some of the examples presented in this documentation, the __Boost_Test__ macro `BOOST_CHECK` is used equivalently to `assert` and __Boost_Test__ `BOOST_AUTO_TEST_CASE` equivalently to `main`.
+In some of the examples presented in this documentation, the __Boost_Test__ macro `BOOST_CHECK` is used equivalently to `assert` and the __Boost_Test__ macro `BOOST_AUTO_TEST_CASE` is used equivalently to `main`.
[footnote
*Rationale.*
-Using __Boost_Test__ allows to add the documentation examples to the library regression test suite so to make sure that the listed examples always compile and run correctly.
+Using __Boost_Test__ allows to add the documentation examples to the library regression tests so to make sure that the listed examples always compile and run correctly.
]
[endsect]
@@ -31,19 +31,19 @@
As a consequence, this library is fairly demanding on compilers' compliance with the __CPP03__ standard.
At present, this library has been successfully compiled and tested on the following compilers and platforms:
-# GNU Compiler Collection (GCC) 4.5.1 (with and without __CPP11__ features enabled) on Ubuntu Linux 10.
-# GCC 4.3.4 on Cygwin.
+# GNU Compiler Collection (GCC) 4.5.1 on Ubuntu Linux 10.
+# GCC 4.3.4 and 4.5.3 (with and without __CPP11__ features enabled `-std=c++0x`) on Cygwin.
# Miscrosoft Visual Studio Compiler (MSVC) 8.0 on Windows XP and Windows 7.
-This library has not yet been tested on any other compiler or platform.
+This library has not yet been tested on any other compiler and platform.
[endsect]
[section Installation]
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 C++ compiler where to find the library header files (`-I` option for GCC, `/I` option for MSVC, etc) and they can start compiling the code that uses this library.
+Therefore there is no pre-compiled object file which needs to be installed or linked.
+Programmers can simply instruct the C++ compiler where to find the library header files (`-I` option for GCC, `/I` option for MSVC, etc) and they can start compiling code using this library.
This library implementation uses a number of __Boost__ libraries among which: __Boost_Preprocessor__, __Boost_ScopeExit__, __Boost_Typeof__, __Boost_TypeTraits__, and __Boost_MPL__.
These __Boost__ libraries must be properly installed on your system in order for this library to work.
@@ -52,24 +52,23 @@
[footnote
*Rationale.*
This library concatenates symbols specified by the programmers (e.g., the local function name) with other symbols (e.g., special prefixes or preprocessor line numbers) to make internal symbols with unique names to avoid name clashes.
-These symbols are separated by the letter "`X`" when they are concatenated so they read more easily during debugging.
-The underscore character "`_`" could not be used instead of the letter "`X`" because if the original symbols already contained a leading or trailing underscore, the concatenation could result in a symbol with double underscores "`__`" which is reserved by the C++ standard.
+These symbols are separated by the letter "`X`" when they are concatenated so they read more easily during debugging (the underscore character "`_`" could not be used instead of the letter "`X`" because if the original symbols already contained a leading or trailing underscore, the concatenation could result in a symbol with double underscores "`__`" which is reserved by the C++ standard).
The "aux" symbols are private to this library while the "detail" symbols can be used within Boost by other libraries but they are still not part of this library public API.
]
-* Any symbol defined by files within the `"boost/local_function/aux_/"` or `"boost/local_function/detail"` directories (these header files should not be directly included by programmers).
-* Any symbol prefixed by `BOOST_LOCAL_FUNCTION_AUX_...` or `BOOST_LOCAL_FUNCTION_DETAIL_...` (regardless of its namespace).
+* Any symbol defined by files within the =boost/local_function/aux_/= or =boost/local_function/detail/= directory (these header files should not be directly included by programmers).
* Any symbol within the `boost::local_function::aux` or `boost::local_function::detail` namespace.
* Any symbol prefixed by `boost_local_function_aux_...` or `boost_local_function_detail_...` (regardless of its namespace).
+* Any symbol prefixed by `BOOST_LOCAL_FUNCTION_AUX_...` or `BOOST_LOCAL_FUNCTION_DETAIL_...` (regardless of its namespace).
[endsect]
-[section Compile-Time Configuration]
+[section Configuration]
Some of the library behaviour can be changed at compile-time by defining special /configuration macros/.
If a configuration macro is left undefined, the library will use an appropriate default value for it.
-All configuration macros have names prefixed by `BOOST_LOCAL_CONFIG_...` (see the __Reference__ section).
+All configuration macros are defined in the header file [headerref boost/local_function/config.hpp].
It is strongly recommended not to change the library configuration macro definitions unless strictly necessary.
[endsect]
Modified: sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Acknowledgments.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Acknowledgments.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Acknowledgments.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -26,7 +26,10 @@
<a name="boost_localfunction.Acknowledgments"></a><a class="link" href="Acknowledgments.html" title="Acknowledgments">Acknowledgments</a>
</h2></div></div></div>
<p>
- This section attempts to recognize the contributions of <span class="emphasis"><em>all</em></span>
+ @todo add thanks from the review
+ </p>
+<p>
+ This section aims to recognize the contributions of <span class="emphasis"><em>all</em></span>
the different people that participated directly or indirectly to the design
and development of this library.
</p>
@@ -49,11 +52,9 @@
macro syntax</a> on compilers that support variadic macros.
</p>
<p>
- Thanks to Pierre Morcello for suggesting to use <code class="computeroutput"><span class="keyword">return</span><span class="special">;</span></code> to exit local blocks (in the context of a
- discussion about a possible Boost.Breakable
- library). Thanks to Pierre also for sharing some code that experimented with
- implementing local functions using Boost.ScopeExit
- binding (even if this library was not developed using such a code).
+ Thanks to Pierre Morcello for sharing some code that experimented with implementing
+ local functions using Boost.ScopeExit
+ binding (even if this library is not based on such a code).
</p>
<p>
Thanks to John Bytheway for checking the authors' virtual functor technique
@@ -69,7 +70,7 @@
</p>
<p>
Thanks to Steven Watanabe, Vicente Botet, Michael Caisse, Yechezkel Mett, Joel
- de Guzman, Thomas Heller, et al. for helping with the <a class="link" href="../">Alternatives</a>
+ de Guzman, Thomas Heller, et al. for helping with the <a class="link" href="Alternatives.html" title="Annex: Alternatives">Alternatives</a>
section and with the profiling of the different alternatives.
</p>
<p>
@@ -84,7 +85,7 @@
<td align="right"><div class="copyright-footer">Copyright © 2009-2012 Lorenzo
Caminiti<p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
Modified: sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Advanced_Topics.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Advanced_Topics.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Advanced_Topics.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -7,7 +7,7 @@
<link rel="home" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
<link rel="up" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
<link rel="prev" href="Tutorial.html" title="Tutorial">
-<link rel="next" href="Examples.html" title="Appendix: Examples">
+<link rel="next" href="Examples.html" title="Examples">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
@@ -49,8 +49,8 @@
(operators, etc)</a></span></dt>
</dl></div>
<p>
- This section illustrates advanced usages of this library. At the end of this
- section there is also a list of knwon limitations of this library.
+ This section illustrates advanced usages of this library (at the bottom there
+ is also a list of known limitations of the library).
</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
@@ -61,7 +61,7 @@
This library also allows to specify default values for the local function
parameters. However, the usual C++ syntax for default parameters that uses
the assignment symbol <code class="computeroutput"><span class="special">=</span></code> cannot
- be used. <sup>[<a name="boost_localfunction.Advanced_Topics.default_parameters.f0" href="#ftn.boost_localfunction.Advanced_Topics.default_parameters.f0" class="footnote">15</a>]</sup> The keyword <code class="computeroutput"><span class="keyword">default</span></code>
+ be used. <sup>[<a name="boost_localfunction.Advanced_Topics.default_parameters.f0" href="#ftn.boost_localfunction.Advanced_Topics.default_parameters.f0" class="footnote">17</a>]</sup> The keyword <code class="computeroutput"><span class="keyword">default</span></code>
is used instead:
</p>
<pre class="programlisting"><code class="literal"><span class="emphasis"><em>parameter-type parameter-name</em></span></code><span class="special">,</span> <span class="keyword">default</span> <code class="literal"><span class="emphasis"><em>parameter-default-value</em></span></code><span class="special">,</span> <span class="special">...</span>
@@ -71,7 +71,7 @@
<span class="identifier">y</span><span class="special">)</span></code>
where the second parameter <code class="computeroutput"><span class="identifier">y</span></code>
is optional and has a default value of <code class="computeroutput"><span class="number">2</span></code>
- (see also "add_default.cpp"
):
+ (see also add_default.cpp
):
</p>
<p>
</p>
@@ -86,8 +86,8 @@
<p>
Programmers can define a <code class="computeroutput"><span class="identifier">WITH_DEFAULT</span></code>
macro similar to the following if they think it improves readability over
- the syntax above (see also "add_with_default.cpp"
):
- <sup>[<a name="boost_localfunction.Advanced_Topics.default_parameters.f1" href="#ftn.boost_localfunction.Advanced_Topics.default_parameters.f1" class="footnote">16</a>]</sup>
+ the above syntax (see also add_with_default.cpp
):
+ <sup>[<a name="boost_localfunction.Advanced_Topics.default_parameters.f1" href="#ftn.boost_localfunction.Advanced_Topics.default_parameters.f1" class="footnote">18</a>]</sup>
</p>
<p>
</p>
@@ -123,22 +123,19 @@
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
- Macro parameters with commas which are already wrapped by round parenthesis
- <code class="computeroutput"><span class="special">()</span></code> are fine (function calls,
- etc). However, macro parameters with commas that are not wrapped by round
- parenthesis need to be wrapped by an extra set of round parenthesis <code class="computeroutput"><span class="special">()</span></code> as described here. Also macro parameters
- with commas wrapped by angular parenthesis <code class="computeroutput"><span class="special"><></span></code>
- (templates, etc) or square parenthesis <code class="computeroutput"><span class="special">[]</span></code>
- (multidimensional array access, etc) need to be wrapped by the extra round
- parenthesis <code class="computeroutput"><span class="special">()</span></code> as explained
- here (this is because the preprocessor only recognizes the round parenthesis
- and it does not recognize angular, square, or any other type of parenthesis).
+ Also macro parameters with commas wrapped by angular parenthesis <code class="computeroutput"><span class="special"><></span></code> (templates, etc) or square parenthesis
+ <code class="computeroutput"><span class="special">[]</span></code> (multidimensional array
+ access, etc) need to be wrapped by the extra round parenthesis <code class="computeroutput"><span class="special">()</span></code> as explained here (this is because the
+ preprocessor only recognizes the round parenthesis and it does not recognize
+ angular, square, or any other type of parenthesis). However, macro parameters
+ with commas which are already wrapped by round parenthesis <code class="computeroutput"><span class="special">()</span></code> are fine (function calls, some value
+ expressions, etc).
</p></td></tr>
</table></div>
<p>
In addition, local function parameter types cannot start with non-alphanumeric
symbols (alphanumeric symbols are <code class="computeroutput"><span class="identifier">A</span><span class="special">-</span><span class="identifier">Z</span></code>, <code class="computeroutput"><span class="identifier">a</span><span class="special">-</span><span class="identifier">z</span></code>,
- and <code class="computeroutput"><span class="number">0</span><span class="special">-</span><span class="number">9</span></code>). <sup>[<a name="boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" href="#ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" class="footnote">17</a>]</sup> The library will generate (cryptic) preprocessor errors if a
+ and <code class="computeroutput"><span class="number">0</span><span class="special">-</span><span class="number">9</span></code>). <sup>[<a name="boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" href="#ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" class="footnote">19</a>]</sup> The library will generate (cryptic) preprocessor errors if a
parameter type starts with a non-alphanumeric symbol.
</p>
<p>
@@ -147,8 +144,8 @@
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
<span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>&</span> <span class="identifier">m</span><span class="special">,</span> <span class="comment">// (1) Error.</span>
<span class="special">::</span><span class="identifier">sign_t</span> <span class="identifier">sign</span><span class="special">,</span> <span class="comment">// (2) Error.</span>
- <span class="keyword">const</span> <span class="identifier">size_t</span><span class="special">&</span> <span class="identifier">factor</span><span class="special">,</span> <span class="keyword">default</span>
- <span class="identifier">key_size</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>::</span><span class="identifier">value</span><span class="special">,</span> <span class="comment">// (3) Error.</span>
+ <span class="keyword">const</span> <span class="identifier">size_t</span><span class="special">&</span> <span class="identifier">factor</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="identifier">key_sizeof</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>::</span><span class="identifier">value</span><span class="special">,</span> <span class="comment">// (3) Error.</span>
<span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">separator</span><span class="special">,</span> <span class="keyword">default</span> <span class="identifier">cat</span><span class="special">(</span><span class="string">":"</span><span class="special">,</span> <span class="string">" "</span><span class="special">)</span> <span class="comment">// (4) OK.</span>
<span class="special">)</span> <span class="special">{</span>
<span class="special">...</span>
@@ -159,15 +156,15 @@
<span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>&</span></code> contains a comma <code class="computeroutput"><span class="special">,</span></code>
after the first template parameter <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span></code>.
This comma is not wrapped by any round parenthesis <code class="computeroutput"><span class="special">()</span></code>
- thus it will cause a preprocessor error. The Boost.Utility
- macro <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(</span></code><span class="emphasis"><em>parenthesized-type</em></span><code class="computeroutput"><span class="special">)</span></code> from the header <code class="computeroutput"><span class="string">"boost/utility/identity_type.hpp"</span></code>
+ thus it will cause a preprocessor error. <sup>[<a name="boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" href="#ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" class="footnote">20</a>]</sup> The Boost.Utility
+ macro <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(</span></code><span class="emphasis"><em>parenthesized-type</em></span><code class="computeroutput"><span class="special">)</span></code> from the header <code class="literal">boost/utility/identity_type.hpp</code>
can be used to wrap a type within extra parenthesis <code class="computeroutput"><span class="special">()</span></code>
so to overcome this issue:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">identity_type</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
- <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>&))</span> <span class="identifier">m</span><span class="special">,</span> <span class="comment">// OK.</span>
+ <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>&))</span> <span class="identifier">m</span><span class="special">,</span> <span class="comment">// OK.</span>
<span class="special">...</span>
<span class="special">)</span> <span class="special">{</span>
<span class="special">...</span>
@@ -176,13 +173,18 @@
<p>
This macro expands to an expression that evaluates (at compile-time) exactly
to the specified type. Note that a total of two set of parenthesis <code class="computeroutput"><span class="special">()</span></code> are needed: The parenthesis to invoke the
- <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(..)</span></code>
+ <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(...)</span></code>
macro plus the parenthesis to wrap the type expression (and therefore any
comma <code class="computeroutput"><span class="special">,</span></code> that it contains) passed
- as parameter to the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((...)</span></code> macro. <sup>[<a name="boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" href="#ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" class="footnote">18</a>]</sup> Finally, the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code>
+ as parameter to the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((...))</span></code> macro. <sup>[<a name="boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f2" href="#ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f2" class="footnote">21</a>]</sup> Finally, the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code>
macro must be prefixed by the <code class="computeroutput"><span class="keyword">typename</span></code>
- keyword as in <code class="computeroutput"><span class="keyword">typename</span> <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(</span></code><span class="emphasis"><em>parenthesized-type</em></span><code class="computeroutput"><span class="special">)</span></code> when used within <code class="computeroutput">BOOST_LOCAL_FUNCTION_TPL</code>
- for templates.
+ keyword:
+ </p>
+<pre class="programlisting"><span class="keyword">typename</span> <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(</span><span class="emphasis"><em>parenthesized-type</em></span><span class="special">)</span>
+</pre>
+<p>
+ When used together with the <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_TPL.html" title="Macro BOOST_LOCAL_FUNCTION_TPL">BOOST_LOCAL_FUNCTION_TPL</a></code>
+ macro within templates.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
@@ -192,14 +194,17 @@
<tr><td align="left" valign="top"><p>
Often, there might be better ways to overcome this limitation that lead
to code which is more readable than the one using the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code>
- macro. For example, in this case a <code class="computeroutput"><span class="keyword">typedef</span></code>
- could have been used in the enclosing scope to obtain the following valid
- and perhaps more readable code:
+ macro.
</p></td></tr>
</table></div>
+<p>
+ For example, in this case a <code class="computeroutput"><span class="keyword">typedef</span></code>
+ could have been used in the enclosing scope to obtain the following valid
+ and perhaps more readable code:
+ </p>
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">></span> <span class="identifier">map_type</span><span class="special">;</span>
<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
- <span class="keyword">const</span> <span class="identifier">map_type</span><span class="special">&</span> <span class="identifier">m</span><span class="special">,</span> <span class="comment">// OK.</span>
+ <span class="keyword">const</span> <span class="identifier">map_type</span><span class="special">&</span> <span class="identifier">m</span><span class="special">,</span> <span class="comment">// OK (and more readable).</span>
<span class="special">...</span>
<span class="special">)</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
</pre>
@@ -226,21 +231,24 @@
<tr><td align="left" valign="top"><p>
Often, there might be better ways to overcome this limitation that lead
to code which is more readable than the one using the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code>
- macro. For example, in this case the symbols <code class="computeroutput"><span class="special">::</span></code>
- could have been simply dropped to obtain the following valid and perhaps
- more readable code:
+ macro.
</p></td></tr>
</table></div>
+<p>
+ For example, in this case the symbols <code class="computeroutput"><span class="special">::</span></code>
+ could have been simply dropped to obtain the following valid and perhaps
+ more readable code:
+ </p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
<span class="special">...</span>
- <span class="identifier">sign_t</span> <span class="identifier">sign</span><span class="special">,</span> <span class="comment">// OK.</span>
+ <span class="identifier">sign_t</span> <span class="identifier">sign</span><span class="special">,</span> <span class="comment">// OK (and more readable).</span>
<span class="special">...</span>
<span class="special">)</span> <span class="special">{</span>
<span class="special">...</span>
<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
</pre>
<p>
- <span class="bold"><strong>(3)</strong></span> The default parameter value <code class="computeroutput"><span class="identifier">key_size</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>::</span><span class="identifier">value</span></code>
+ <span class="bold"><strong>(3)</strong></span> The default parameter value <code class="computeroutput"><span class="identifier">key_sizeof</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>::</span><span class="identifier">value</span></code>
contains a comma <code class="computeroutput"><span class="special">,</span></code> after the
first template parameter <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span></code>.
Again, this comma is not wrapped by any parenthesis <code class="computeroutput"><span class="special">()</span></code>
@@ -250,8 +258,8 @@
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
<span class="special">...</span>
- <span class="keyword">const</span> <span class="identifier">size_t</span><span class="special">&</span> <span class="identifier">factor</span><span class="special">,</span> <span class="keyword">default</span>
- <span class="special">(</span><span class="identifier">key_size</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>::</span><span class="identifier">value</span><span class="special">),</span> <span class="comment">// OK.</span>
+ <span class="keyword">const</span> <span class="identifier">size_t</span><span class="special">&</span> <span class="identifier">factor</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="special">(</span><span class="identifier">key_sizeof</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>::</span><span class="identifier">value</span><span class="special">),</span> <span class="comment">// OK.</span>
<span class="special">...</span>
<span class="special">)</span> <span class="special">{</span>
<span class="special">...</span>
@@ -263,6 +271,23 @@
the parenthesis <code class="computeroutput"><span class="special">()</span></code> of the function
call <code class="computeroutput"><span class="identifier">cat</span><span class="special">(...)</span></code>.
</p>
+<p>
+ Consider the following complete example (see also macro_commas.cpp
):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
+ <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>&))</span> <span class="identifier">m</span><span class="special">,</span>
+ <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((::</span><span class="identifier">sign_t</span><span class="special">))</span> <span class="identifier">sign</span><span class="special">,</span>
+ <span class="keyword">const</span> <span class="identifier">size_t</span><span class="special">&</span> <span class="identifier">factor</span><span class="special">,</span>
+ <span class="keyword">default</span> <span class="special">(</span><span class="identifier">key_sizeof</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>::</span><span class="identifier">value</span><span class="special">),</span>
+ <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">separator</span><span class="special">,</span> <span class="keyword">default</span> <span class="identifier">cat</span><span class="special">(</span><span class="string">":"</span><span class="special">,</span> <span class="string">" "</span><span class="special">)</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Do something...</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
+</pre>
+<p>
+ </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
@@ -277,7 +302,7 @@
from the enclosing function.
</p>
<p>
- For example (see also "return_assign.cpp"
):
+ For example (see also return_assign.cpp
):
</p>
<p>
</p>
@@ -318,19 +343,16 @@
As with <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
lambda</a> functions, programmers are responsible to ensure that bound
references are valid in any scope where the local function object is called.
+ (This might be tricky to verify in a program when local functions are returned
+ and called outside the local scope of their declaration.)
</p></td></tr>
</table></div>
<p>
- This might be tricky to verify in a program so in general it is better to
- never bind by reference when a local function is returned by the enclosing
- scope to a different scope (see a few examples on this topic in the <a class="link" href="../">Examples</a> section).
- </p>
-<p>
In addition, a local function can bind and call another local function. Local
functions should always be bound by constant reference <code class="computeroutput"><span class="keyword">const</span>
<span class="identifier">bind</span><span class="special">&</span></code>
to avoid unnecessary copies. For example, the following local function <code class="computeroutput"><span class="identifier">inc_sum</span></code> binds the local function <code class="computeroutput"><span class="identifier">inc</span></code> so <code class="computeroutput"><span class="identifier">inc_sum</span></code>
- can call <code class="computeroutput"><span class="identifier">inc</span></code> (see aslo "transform.cpp"
):
+ can call <code class="computeroutput"><span class="identifier">inc</span></code> (see aslo transform.cpp
):
</p>
<p>
</p>
@@ -366,7 +388,7 @@
</h3></div></div></div>
<p>
It is possible to nest local functions into one another. For example (see
- also "nesting.cpp"
):
+ also nesting.cpp
):
</p>
<p>
</p>
@@ -392,35 +414,30 @@
Bound Types (concepts, etc)</a>
</h3></div></div></div>
<p>
- This library never requires to explicitly specify the type of the bound variables.
+ This library never requires to explicitly specify the type of bound variables.
From within local functions, programmers can access the type of a bound variable
using the following macro:
</p>
<pre class="programlisting"><span class="identifier">BOOST_LOCAL_FUNCTION_TYPEOF</span><span class="special">(</span><span class="emphasis"><em>bound-variable-name</em></span><span class="special">)</span>
</pre>
<p>
- The <code class="computeroutput">BOOST_LOCAL_FUNCTION_TYPEOF</code>
+ The <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_TYPEOF.html" title="Macro BOOST_LOCAL_FUNCTION_TYPEOF">BOOST_LOCAL_FUNCTION_TYPEOF</a></code>
macro expands to a type expression that evaluates (at compile-time) to the
- fully qualified type of the bound variable with the specified name.
+ fully qualified type of the bound variable with the specified name. This
+ type expression is fully qualified in the sense that it will be constant
+ if the variable is bound by constant <code class="computeroutput"><span class="keyword">const</span>
+ <span class="identifier">bind</span><span class="special">[&]</span></code>
+ and it will also be a reference is the variable is bound by reference <code class="computeroutput"><span class="special">[</span><span class="keyword">const</span><span class="special">]</span>
+ <span class="identifier">bind</span><span class="special">&</span></code>
+ (if needed, programmers can strip away the <code class="computeroutput"><span class="keyword">const</span></code>
+ and <code class="computeroutput"><span class="special">&</span></code> qualifiers using
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_const</span></code> and <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_reference</span></code>,
+ see Boost.TypeTraits).
</p>
-<div class="note"><table border="0" summary="Note">
-<tr>
-<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
-<th align="left">Note</th>
-</tr>
-<tr><td align="left" valign="top"><p>
- This type expression is fully qualified in the sense that it will be constant
- if the variable is bound by constant <code class="computeroutput"><span class="keyword">const</span>
- <span class="identifier">bind</span><span class="special">[&]</span></code>
- and it will also be a reference is the variable is bound by reference
- <code class="computeroutput"><span class="special">[</span><span class="keyword">const</span><span class="special">]</span> <span class="identifier">bind</span><span class="special">&</span></code> (if needed, programmers can strip
- away the <code class="computeroutput"><span class="keyword">const</span></code> and <code class="computeroutput"><span class="special">&</span></code> qualifiers using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_const</span></code>
- and <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_reference</span></code>, see Boost.TypeTraits).
- </p></td></tr>
-</table></div>
<p>
- The deduced bound type can be used within the body to declare a local variable,
- to check concepts, etc. For example (see also "typeof.cpp"
and "addable.hpp"
):
+ The deduced bound type can be used within the body to check concepts, declare
+ local variables, etc. For example (see also typeof.cpp
+ and addable.hpp
):
</p>
<p>
</p>
@@ -441,11 +458,11 @@
<p>
</p>
<p>
- Within templates, <code class="computeroutput">BOOST_LOCAL_FUNCTION_TYPEOF</code>
+ Within templates, <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_TYPEOF.html" title="Macro BOOST_LOCAL_FUNCTION_TYPEOF">BOOST_LOCAL_FUNCTION_TYPEOF</a></code>
does not require to be prefixed by the <code class="computeroutput"><span class="keyword">typename</span></code>
keyword but eventual type manipulations need the <code class="computeroutput"><span class="keyword">typename</span></code>
- prefix as usual (see also "typeof_template.cpp"
and
- "addable.hpp"
):
+ prefix as usual (see also typeof_template.cpp
+ and addable.hpp
):
</p>
<p>
</p>
@@ -475,7 +492,7 @@
<p>
While not required, it is possible to explicitly specify the type of a bound
variable so the library will not internally use Boost.Typeof
- to automatically deduce the type. When specified, the bound variable type
+ to automatically deduce such a type. When specified, the bound variable type
must follow the <code class="computeroutput"><span class="identifier">bind</span></code> "keyword"
and it must be wrapped within round parenthesis <code class="computeroutput"><span class="special">()</span></code>:
</p>
@@ -483,29 +500,39 @@
<span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>variable-type</em></span><span class="special">)&</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by reference with explicit type.</span>
<span class="keyword">const</span> <span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>variable-type</em></span><span class="special">)</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by constant value with explicit type.</span>
<span class="keyword">const</span> <span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>variable-type</em></span><span class="special">)&</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by constant reference with explicit type.</span>
-<span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>class-type</em></span><span class="special">*)</span> <span class="identifier">this_</span> <span class="comment">// Bind object `this` with type.</span>
-<span class="keyword">const</span> <span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>class-type</em></span><span class="special">*)</span> <span class="identifier">this_</span> <span class="comment">// Bind object `this` by constant with type.</span>
+<span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>class-type</em></span><span class="special">*)</span> <span class="identifier">this_</span> <span class="comment">// Bind object `this` with explicit type.</span>
+<span class="keyword">const</span> <span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>class-type</em></span><span class="special">*)</span> <span class="identifier">this_</span> <span class="comment">// Bind object `this` by constant with explicit type.</span>
</pre>
<p>
Note that within the local function body it is always possible to abstract
- the access to the type of a bound variable using <code class="computeroutput">BOOST_LOCAL_FUNCTION_TYPEOF</code>
+ the access to the type of a bound variable using <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_TYPEOF.html" title="Macro BOOST_LOCAL_FUNCTION_TYPEOF">BOOST_LOCAL_FUNCTION_TYPEOF</a></code>
(even when the bound variable type is explicitly specified).
</p>
<p>
- The library also needs to use Boost.Typeof
- to determine the local function result type because this type specified outside
- the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
- macro. Thus it is also possible to specify the local function result type
- as one of the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
+ The library also uses Boost.Typeof
+ to determine the local function result type (because this type specified
+ outside the <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION.html" title="Macro BOOST_LOCAL_FUNCTION">BOOST_LOCAL_FUNCTION</a></code>
+ macro). Thus it is also possible to specify the local function result type
+ as one of the <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION.html" title="Macro BOOST_LOCAL_FUNCTION">BOOST_LOCAL_FUNCTION</a></code>
macro parameters prefixed by <code class="computeroutput"><span class="keyword">return</span></code>
so the library will not use Boost.Typeof
- to deduce it:
+ to deduce the result type:
</p>
<pre class="programlisting"><span class="identifier">BOOST_LOCAL_FUNCTION_TYPE</span><span class="special">(</span><span class="keyword">return</span> <code class="literal"><span class="emphasis"><em>result-type</em></span></code><span class="special">,</span> <span class="special">...)</span>
</pre>
<p>
+ Note that the result type must be specified only once either before the macro
+ (without the <code class="computeroutput"><span class="keyword">return</span></code> prefix)
+ or as one of the macro parameters (with the <code class="computeroutput"><span class="keyword">return</span></code>
+ prefix). As usual, the result type can always be <code class="computeroutput"><span class="keyword">void</span></code>
+ to declare a function returning nothing (so <code class="computeroutput"><span class="keyword">return</span>
+ <span class="keyword">void</span></code> is allowed when the result type
+ is specified as one of the macro parameters).
+ </p>
+<p>
The following example specifies the type of all bound variables and of the
- local function result (see also "add_typed.cpp"
): <sup>[<a name="boost_localfunction.Advanced_Topics.specifying_types.f0" href="#ftn.boost_localfunction.Advanced_Topics.specifying_types.f0" class="footnote">19</a>]</sup>
+ local function result (see also add_typed.cpp
):
+ <sup>[<a name="boost_localfunction.Advanced_Topics.specifying_types.f0" href="#ftn.boost_localfunction.Advanced_Topics.specifying_types.f0" class="footnote">22</a>]</sup>
</p>
<p>
</p>
@@ -531,8 +558,8 @@
<p>
Unless necessary, it is recommended to not specify the bound variable and
result types. Let the library deduce these types so the local function syntax
- is more concise and the local function declaration will not have to change
- if a bound variable type changes (facilitating maintenance).
+ will be more concise and the local function declaration will not have to
+ change if a bound variable type changes (facilitating maintenance).
</p>
<div class="note"><table border="0" summary="Note">
<tr>
@@ -540,13 +567,10 @@
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
- Even when the result type and all bound variable types are explicitly specified,
- the library implementation still internally uses Boost.Typeof
- to deduce the local function object type (see the <a class="link" href="../">Implementation</a>
- section). However, this type is automatically registered with Boost.Typeof
- by this library so programmers will never be required to perform explicit
- Boost.Typeof
- registrations when they specify all result and bound variable types.
+ Unfortunately, the current implementation implementation still internally
+ uses Boost.Typeof
+ once to deduce the local function object type (see the <a class="link" href="Implementation.html" title="Annex: Implementation">Implementation</a>
+ section) even when all bound variable and result types are explicitly specified.
</p></td></tr>
</table></div>
</div>
@@ -558,7 +582,7 @@
Local functions can be declared inline to increase the chances that the compiler
will be able to reduce the run-time of the local function call by inlining
the generated assembly code. A local function is declared inline by prefixing
- the local function name passed to the <code class="computeroutput">BOOST_LOCAL_FUNCTION_NAME</code>
+ the local function name passed to the <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_NAME.html" title="Macro BOOST_LOCAL_FUNCTION_NAME">BOOST_LOCAL_FUNCTION_NAME</a></code>
macro with the "keyword" <code class="computeroutput"><span class="keyword">inline</span></code>:
</p>
<pre class="programlisting"><span class="emphasis"><em>result-type</em></span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="emphasis"><em>parameters</em></span><span class="special">)</span> <span class="special">{</span>
@@ -573,10 +597,10 @@
On C++03
compliant compilers, inlined local functions always have a run-time comparable
to their equivalent implementation that uses local functors (see the
- <a class="link" href="../">Alternatives</a> section).
- However, inlined local functions have the important limitation that they
- cannot be assigned to other functors (like <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span></code>)
- and they cannot be passed as template parameters. <sup>[<a name="boost_localfunction.Advanced_Topics.inlining.f0" href="#ftn.boost_localfunction.Advanced_Topics.inlining.f0" class="footnote">20</a>]</sup>
+ <a class="link" href="Alternatives.html" title="Annex: Alternatives">Alternatives</a>
+ section). However, inlined local functions have the important limitation
+ that they cannot be assigned to other functors (like <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span></code>)
+ and they cannot be passed as template parameters.
</li>
<li class="listitem">
On C++11
@@ -586,7 +610,7 @@
features to inline the local function calls whenever possible even if
the local function is not declared inline. Furthermore, non C++11
local functions can always be passes as template parameters even when
- they are declared inline.
+ they are declared inline. <sup>[<a name="boost_localfunction.Advanced_Topics.inlining.f0" href="#ftn.boost_localfunction.Advanced_Topics.inlining.f0" class="footnote">23</a>]</sup>
</li>
</ul></div>
<div class="important"><table border="0" summary="Important">
@@ -595,8 +619,8 @@
<th align="left">Important</th>
</tr>
<tr><td align="left" valign="top"><p>
- It is recommended to not declare a local function inlined unless it is
- strictly necessary for optimizing pure C++03
+ It is recommended to not declare a local function inline unless it is strictly
+ necessary for optimizing pure C++03
compliant code (because in all other cases this library will automatically
take advantage of C++11
features to optimize the local function calls while always allowing to
@@ -604,10 +628,10 @@
</p></td></tr>
</table></div>
<p>
- For example, the following local function is declared inlined (thus a for-loop
+ For example, the following local function is declared inline (thus a for-loop
needs to be used for portability instead of passing the local function as
a template parameter to the <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code>
- algorithm, see also "add_inline.cpp"
):
+ algorithm, see also add_inline.cpp
):
</p>
<p>
</p>
@@ -633,8 +657,10 @@
Local functions can be declared recursive
so a local function can recursively call itself from its body (as usual with
C++ functions). A local function is declared recursive by prefixing the local
- function name passed to <code class="computeroutput">BOOST_LOCAL_FUNCTION_NAME</code>
- macro with the "keyword" <code class="computeroutput"><span class="identifier">recursive</span></code>:
+ function name passed to <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_NAME.html" title="Macro BOOST_LOCAL_FUNCTION_NAME">BOOST_LOCAL_FUNCTION_NAME</a></code>
+ macro with the "keyword" <code class="computeroutput"><span class="identifier">recursive</span></code>
+ (thus <code class="computeroutput"><span class="identifier">recursive</span></code> is not a
+ valid local function name):
</p>
<pre class="programlisting"><span class="emphasis"><em>result-type</em></span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="emphasis"><em>parameters</em></span><span class="special">)</span> <span class="special">{</span>
<span class="special">...</span> <span class="comment">// Body.</span>
@@ -642,7 +668,7 @@
</pre>
<p>
For example, the following local function is used to recursively calculate
- the factorials of all the numbers in the specified vector (see also "factorial.cpp"
):
+ the factorials of all the numbers in the specified vector (see also factorial.cpp
):
</p>
<p>
</p>
@@ -654,7 +680,7 @@
<span class="keyword">bool</span> <span class="identifier">recursion</span><span class="special">,</span> <span class="keyword">default</span> <span class="keyword">false</span><span class="special">)</span> <span class="special">{</span>
<span class="keyword">int</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
- <span class="keyword">if</span> <span class="special">(</span><span class="identifier">num</span> <span class="special"><</span> <span class="number">2</span> <span class="special">)</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">num</span> <span class="special"><=</span> <span class="number">0</span><span class="special">)</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
<span class="keyword">else</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">num</span> <span class="special">*</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">num</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span> <span class="keyword">true</span><span class="special">);</span> <span class="comment">// Recursive call.</span>
<span class="keyword">if</span> <span class="special">(!</span><span class="identifier">recursion</span><span class="special">)</span> <span class="identifier">this_</span><span class="special">-></span><span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">result</span><span class="special">);</span>
@@ -669,7 +695,9 @@
</p>
<p>
Compilers have not been observed to be able to inline recursive local function
- calls (not even when the recursive local function is also declared inline).
+ calls (not even when the recursive local function is also declared inline
+ as in <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="keyword">inline</span> <span class="identifier">recursive</span>
+ <span class="identifier">factorial</span><span class="special">)</span></code>).
</p>
<div class="warning"><table border="0" summary="Warning">
<tr>
@@ -677,15 +705,14 @@
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>
- Recursive local functions should never be assigned to another functor object
- or called outside their declaration scope. Therefore, if a local function
- is assigned to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span></code>, returned from the enclosing
- function, and called in a different scope, the result in undefined behaviour
- (which will likely generate a run-time error). <sup>[<a name="boost_localfunction.Advanced_Topics.recursion.f0" href="#ftn.boost_localfunction.Advanced_Topics.recursion.f0" class="footnote">21</a>]</sup> This is not a limitation with respect to <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ Recursive local functions should never be called outside their declaration
+ scope. If a local function is returned from the enclosing function and
+ called in a different scope, the behaviour is undefined (and it will likely
+ result in a run-time error). <sup>[<a name="boost_localfunction.Advanced_Topics.recursion.f0" href="#ftn.boost_localfunction.Advanced_Topics.recursion.f0" class="footnote">24</a>]</sup> This is not a limitation with respect to <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
lambda</a> functions because lambdas can never call themselves recursively
(in other words, there is no recursive lambda function that can successfully
be called outside its declaration scope because there is no recursive lambda
- function period).
+ function at all).
</p></td></tr>
</table></div>
</div>
@@ -694,15 +721,17 @@
<a name="boost_localfunction.Advanced_Topics.overloading"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.overloading" title="Overloading">Overloading</a>
</h3></div></div></div>
<p>
- It is possible to overload local functions using __Boost_FunctionalOverloadedFunction__
- <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">overloaded_function</span></code> from the header <code class="computeroutput"><span class="string">"boost/functional/overloaded_function.hpp"</span></code>
- (see the __Boost_FunctionalOverloadedFunction__ documentation for more detail).
+ It is possible to overload local functions using the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">overloaded_function</span></code>
+ functor of Boost.Functional/OverloadedFunction
+ from the header <code class="literal">boost/functional/overloaded_function.hpp</code>
+ (see the Boost.Functional/OverloadedFunction
+ documentation for details).
</p>
<p>
In the following example, the overloaded function object <code class="computeroutput"><span class="identifier">add</span></code>
can be called with signatures from either the local function <code class="computeroutput"><span class="identifier">add_s</span></code>, or the local function <code class="computeroutput"><span class="identifier">add_d</span></code>, or the local function <code class="computeroutput"><span class="identifier">add_d</span></code> with its extra default parameter,
or the function pointer <code class="computeroutput"><span class="identifier">add_i</span></code>
- (see also "overload.cpp"
):
+ (see also overload.cpp
):
</p>
<p>
</p>
@@ -743,7 +772,7 @@
</h3></div></div></div>
<p>
It is possible to program exception specifications for local functions by
- specifying them after the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
+ specifying them after the <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION.html" title="Macro BOOST_LOCAL_FUNCTION">BOOST_LOCAL_FUNCTION</a></code>
macro and before the body code block <code class="computeroutput"><span class="special">{</span>
<span class="special">...</span> <span class="special">}</span></code>.
</p>
@@ -762,7 +791,7 @@
</p></td></tr>
</table></div>
<p>
- For example (see also "add_except.cpp"
):
+ For example (see also add_except.cpp
):
</p>
<p>
</p>
@@ -787,7 +816,7 @@
<p>
Local function parameters support the storage classifiers as usual in C++03.
The <code class="computeroutput"><span class="keyword">auto</span></code> storage classifier
- is specified as: <sup>[<a name="boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" href="#ftn.boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" class="footnote">22</a>]</sup>
+ is specified as: <sup>[<a name="boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" href="#ftn.boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" class="footnote">25</a>]</sup>
</p>
<pre class="programlisting"><span class="keyword">auto</span> <span class="emphasis"><em>parameter-type parameter-name</em></span>
</pre>
@@ -798,7 +827,7 @@
<pre class="programlisting"><span class="keyword">register</span> <span class="emphasis"><em>parameter-type parameter-name</em></span>
</pre>
<p>
- For example (see also "add_classifiers.cpp"
):
+ For example (see also add_classifiers.cpp
):
</p>
<p>
</p>
@@ -984,7 +1013,7 @@
</td>
<td>
<p>
- This is supported (see the <a class="link" href="../">Tutorial</a>
+ This is supported (see the <a class="link" href="Tutorial.html" title="Tutorial">Tutorial</a>
section).
</p>
</td>
@@ -1003,8 +1032,9 @@
<td>
<p>
Local functions are named and they can call themselves recursively
- but they cannot be overloaded and they cannot be operators (see
- the <a class="link" href="../">Tutorial</a> and <a class="link" href="../">Advanced Topics</a> sections).
+ but they cannot be operators (see the <a class="link" href="Tutorial.html" title="Tutorial">Tutorial</a>
+ and <a class="link" href="Advanced_Topics.html" title="Advanced Topics">Advanced
+ Topics</a> sections).
</p>
</td>
</tr>
@@ -1024,9 +1054,9 @@
This is supported and it also supports the <code class="computeroutput"><span class="keyword">auto</span></code>
and <code class="computeroutput"><span class="keyword">register</span></code> storage
classifiers, default parameters, and binding of variables in scope
- (see the <a class="link" href="../">Tutorial</a> and
- <a class="link" href="../">Advanced Topics</a>
- sections).
+ (see the <a class="link" href="Tutorial.html" title="Tutorial">Tutorial</a>
+ and <a class="link" href="Advanced_Topics.html" title="Advanced Topics">Advanced
+ Topics</a> sections).
</p>
</td>
</tr>
@@ -1082,57 +1112,63 @@
</h6>
<p>
Local functions cannot be operators. Naming a local function <code class="computeroutput"><span class="keyword">operator</span><span class="special">...</span></code>
- will generate a compile-time error. <sup>[<a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" href="#ftn.boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" class="footnote">23</a>]</sup>
+ will generate a compile-time error. <sup>[<a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" href="#ftn.boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" class="footnote">26</a>]</sup>
</p>
<p>
- For example, the following code will <span class="bold"><strong>not</strong></span>
- compile:
+ For example, the following code will not compile:
</p>
-<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{</span>
- <span class="keyword">struct</span> <span class="identifier">point</span> <span class="special">{</span>
- <span class="keyword">double</span> <span class="identifier">x</span><span class="special">;</span>
- <span class="keyword">double</span> <span class="identifier">y</span><span class="special">;</span>
- <span class="special">};</span>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">point</span> <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">x</span><span class="special">;</span>
+ <span class="keyword">int</span> <span class="identifier">y</span><span class="special">;</span>
+<span class="special">};</span>
+<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_operator_err</span> <span class="special">)</span> <span class="special">{</span>
<span class="keyword">bool</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">point</span><span class="special">&</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">point</span><span class="special">&</span> <span class="identifier">q</span><span class="special">)</span> <span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">x</span> <span class="special">==</span> <span class="identifier">q</span><span class="special">.</span><span class="identifier">x</span> <span class="special">&&</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">y</span> <span class="special">==</span> <span class="identifier">q</span><span class="special">.</span><span class="identifier">y</span><span class="special">;</span>
- <span class="special">)</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="keyword">operator</span><span class="special">==)</span> <span class="comment">// Error: Cannot use `operator==`.</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="keyword">operator</span><span class="special">==)</span> <span class="comment">// Error: Cannot use `operator...`.</span>
- <span class="special">...</span>
+ <span class="identifier">point</span> <span class="identifier">a</span><span class="special">;</span> <span class="identifier">a</span><span class="special">.</span><span class="identifier">x</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">a</span><span class="special">.</span><span class="identifier">y</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
+ <span class="identifier">point</span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">a</span><span class="special">;</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span> <span class="special">);</span>
<span class="special">}</span>
</pre>
+<p>
+ </p>
<h6>
<a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_.h1"></a>
<span><a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_.goto"></a></span><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.limitations__operators__etc_.goto">Goto</a>
</h6>
<p>
It is not possible to jump with a <code class="computeroutput"><span class="keyword">goto</span></code>
- from within a local function, local block, or local exit to a label defined
- in the enclosing scope.
+ from within a local function to a label defined in the enclosing scope.
</p>
<p>
- For example, the following will <span class="bold"><strong>not</strong></span> compile:
+ For example, the following will not compile:
</p>
-<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{</span>
- <span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">error</span><span class="special">)</span> <span class="special">{</span>
- <span class="keyword">if</span> <span class="special">(</span><span class="identifier">error</span><span class="special">)</span> <span class="keyword">goto</span> <span class="identifier">failure</span><span class="special">;</span> <span class="comment">// Error: Cannot jump to enclosing label `failure`.</span>
- <span class="keyword">else</span> <span class="keyword">goto</span> <span class="identifier">success</span><span class="special">;</span> <span class="comment">// Ok: Can jump within enclosing scope.</span>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">error</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">bool</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span><span class="identifier">x</span> <span class="special"><=</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">goto</span> <span class="identifier">failure</span><span class="special">;</span> <span class="comment">// Error: Cannot jump to enclosing scope.</span>
+ <span class="keyword">else</span> <span class="keyword">goto</span> <span class="identifier">success</span><span class="special">;</span> <span class="comment">// OK: Can jump within local function.</span>
<span class="identifier">success</span><span class="special">:</span>
- <span class="special">...</span>
- <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
-
- <span class="identifier">f</span><span class="special">(</span><span class="keyword">true</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">validate</span><span class="special">)</span>
- <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
-<span class="identifier">failure</span><span class="special">:</span>
+ <span class="keyword">return</span> <span class="identifier">validate</span><span class="special">(</span><span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">);</span>
+<span class="identifier">faliure</span><span class="special">:</span>
<span class="keyword">return</span> <span class="special">-</span><span class="number">1</span><span class="special">;</span>
<span class="special">}</span>
</pre>
+<p>
+ </p>
</div>
<div class="footnotes">
<br><hr width="100" align="left">
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.default_parameters.f0" href="#boost_localfunction.Advanced_Topics.default_parameters.f0" class="para">15</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.default_parameters.f0" href="#boost_localfunction.Advanced_Topics.default_parameters.f0" class="para">17</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> The assignment symbol <code class="computeroutput"><span class="special">=</span></code> cannot be used to specify default parameter
values because default values are not part of the parameter type so they
cannot be handled using template metaprogamming. Default parameter values
@@ -1141,11 +1177,11 @@
to remove default values when constructing the local function type and
then to count the number of default values to provide the correct set of
call operators for the local functor. Therefore, the symbol <code class="computeroutput"><span class="special">=</span></code> cannot be used because it cannot be handled
- by preprocessor metaprogramming (specifically, such a non-alphanumeric
- symbol cannot be detected by preprocessor metaprogramming because it cannot
- be concatenated by the preprocessor).
+ by preprocessor metaprogramming (non-alphanumeric symbols cannot be detected
+ by preprocessor metaprogramming because it cannot be concatenated by the
+ preprocessor).
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.default_parameters.f1" href="#boost_localfunction.Advanced_Topics.default_parameters.f1" class="para">16</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.default_parameters.f1" href="#boost_localfunction.Advanced_Topics.default_parameters.f1" class="para">18</a>] </sup>
The authors do not personally find the use of the <code class="computeroutput"><span class="identifier">WITH_DEFAULT</span></code>
macro more readable and they prefer to use the <code class="computeroutput"><span class="keyword">default</span></code>
"keyword" directly. Furthermore, <code class="computeroutput"><span class="identifier">WITH_DEFAULT</span></code>
@@ -1153,7 +1189,7 @@
<span class="special">(</span><span class="keyword">default</span><span class="special">)</span></code> so it can only be defined by programmers
based on the syntax they decide to use.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" href="#boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" class="para">17</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" href="#boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" class="para">19</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> This limitation derives from
the fact that <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION</span></code>
uses preprocessor token concatenation <code class="literal">##</code> to inspect
@@ -1161,24 +1197,33 @@
variable) and the C++ preprocessor does not allow to concatenate non-alphanumeric
tokens.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" href="#boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" class="para">18</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" href="#boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" class="para">20</a>] </sup>
+ The preprocessor always interprets unwrapped commas as separating macro
+ parameters. Thus in this case the comma will indicate to the preprocessor
+ that the first macro parameter is <code class="computeroutput"><span class="keyword">const</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">tring</span></code>, the second macro parameter is
+ <code class="computeroutput"><span class="identifier">size_t</span><span class="special">>&</span>
+ <span class="identifier">m</span></code>, etc instead of passing <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">>&</span> <span class="identifier">m</span></code>
+ as a single macro parameter.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f2" href="#boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f2" class="para">21</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> Using variadic macros, this
extra set of parenthesis could be eliminated requiring only the parenthesis
to invoke the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code>
macro. However, this feature is currently not implemented and the double
parenthesis are always needed when invoking this macro.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.specifying_types.f0" href="#boost_localfunction.Advanced_Topics.specifying_types.f0" class="para">19</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.specifying_types.f0" href="#boost_localfunction.Advanced_Topics.specifying_types.f0" class="para">22</a>] </sup>
In the examples of this documentation, we specify bound variables, function
- parameters, and result type in this order because that is the order used
+ parameters, and result type in this order because this is the order used
by <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
lambda</a> functions. However, the library accepts bound variables,
function parameters, and the result type in any order.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.inlining.f0" href="#boost_localfunction.Advanced_Topics.inlining.f0" class="para">20</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.inlining.f0" href="#boost_localfunction.Advanced_Topics.inlining.f0" class="para">23</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> This library uses an indirect
function call via a function pointer in order to pass the local function
- as a template parameter (see the <a class="link" href="../">Implementation</a>
+ as a template parameter (see the <a class="link" href="Implementation.html" title="Annex: Implementation">Implementation</a>
section). No compiler has yet been observed to be able to inline function
calls when they use such indirect function pointer calls. Therefore,
inlined local functions do not use such indirect function pointer call
@@ -1191,17 +1236,17 @@
can be inlined on C++11
compilers (even when the local function is not declared inline).
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.recursion.f0" href="#boost_localfunction.Advanced_Topics.recursion.f0" class="para">21</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.recursion.f0" href="#boost_localfunction.Advanced_Topics.recursion.f0" class="para">24</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> This limitation comes from
- the fact that a global functor used to pass the local function as a template
- parameter (and eventually use it outside its declarations scope) does
- not know the local function name so the local function name used for
- recursive call cannot be set in the global functor. This limitation and
- preventing the possibility for inlining is also the reason why local
- function are not recursive unless programmers explicitly declare them
- <code class="computeroutput"><span class="identifier">recursive</span></code>.
+ the fact that the global functor used to pass the local function as a
+ template parameter (and eventually returned outside the declarations
+ scope) does not know the local function name so the local function name
+ used for recursive call cannot be set in the global functor. This limitation
+ together with preventing the possibility for inlining are the reasons
+ why local functions do not allow for recursion unless programmers explicitly
+ declare them <code class="computeroutput"><span class="identifier">recursive</span></code>.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" href="#boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" class="para">22</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" href="#boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" class="para">25</a>] </sup>
The <code class="computeroutput"><span class="keyword">auto</span></code> storage classifier
is part of the C++03
standard and therefore supported by this library. However, the meaning
@@ -1211,7 +1256,7 @@
classifier with the usual care in order to avoid writing C++03
code that might not work on C++11.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" href="#boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" class="para">23</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" href="#boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" class="para">26</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> This is the because a local
function name must be a valid local variable name (the local variable to
hold the local functor) and operators cannot be used as local variable
@@ -1224,7 +1269,7 @@
<td align="right"><div class="copyright-footer">Copyright © 2009-2012 Lorenzo
Caminiti<p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
Modified: sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Alternatives.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Alternatives.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Alternatives.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -1,12 +1,12 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
-<title>Appendix: Alternatives</title>
+<title>Annex: Alternatives</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
<link rel="up" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
-<link rel="prev" href="Examples.html" title="Appendix: Examples">
+<link rel="prev" href="../BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.html" title="Macro BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX">
<link rel="next" href="No_Variadic_Macros.html" title="Annex: No Variadic Macros">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -20,28 +20,24 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="Examples.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="No_Variadic_Macros.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+<a accesskey="p" href="../BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="No_Variadic_Macros.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
-<a name="boost_localfunction.Alternatives"></a><a class="link" href="Alternatives.html" title="Appendix: Alternatives">Appendix: Alternatives</a>
+<a name="boost_localfunction.Alternatives"></a><a class="link" href="Alternatives.html" title="Annex: Alternatives">Annex: Alternatives</a>
</h2></div></div></div>
-<div class="toc"><dl>
-<dt><span class="section">Features</span></dt>
-<dt><span class="section">Performances</span></dt>
-</dl></div>
<p>
This section compares the features offered by this library with similar features
offered by other libraries and by the new C++11
standard.
</p>
-<div class="section">
-<div class="titlepage"><div><div><h3 class="title">
-<a name="boost_localfunction.Alternatives.features"></a><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.features" title="Features">Features</a>
-</h3></div></div></div>
+<h6>
+<a name="boost_localfunction.Alternatives.h0"></a>
+ <span><a name="boost_localfunction.Alternatives.features"></a></span><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.features">Features</a>
+ </h6>
<p>
- The following table compares local function features.
- </p>
+ The following table compares local function features.
+ </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
@@ -54,695 +50,691 @@
</colgroup>
<thead><tr>
<th>
- <p>
- Local Function Feature
- </p>
- </th>
-<th>
- <p>
- Boost.Local (this library)
- </p>
- </th>
-<th>
- <p>
- Local Functor
- </p>
- </th>
-<th>
- <p>
- Global Functor (not local)
- </p>
- </th>
-<th>
- <p>
- __CPP0x_Lambda__ (not C++03)
- </p>
- </th>
-<th>
- <p>
- Boost.Lambda
- </p>
- </th>
-<th>
- <p>
- Boost.Phoenix
- </p>
- </th>
+ <p>
+ Local Function Feature
+ </p>
+ </th>
+<th>
+ <p>
+ Boost.Local (this library)
+ </p>
+ </th>
+<th>
+ <p>
+ Local Functor
+ </p>
+ </th>
+<th>
+ <p>
+ Global Functor (not local)
+ </p>
+ </th>
+<th>
+ <p>
+ __CPP0x_Lambda__ (not C++03)
+ </p>
+ </th>
+<th>
+ <p>
+ Boost.Lambda
+ </p>
+ </th>
+<th>
+ <p>
+ Boost.Phoenix
+ </p>
+ </th>
</tr></thead>
<tbody>
<tr>
<td>
- <p>
- <span class="emphasis"><em>Can be defined locally</em></span>
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
-<td>
- <p>
- No. Therefore this not really an alternative implementation of
- local functions but it is listed here just for comparison.
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
+ <p>
+ <span class="emphasis"><em>Can be defined locally</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ No. Therefore this not really an alternative implementation of local
+ functions but it is listed here just for comparison.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
</tr>
<tr>
<td>
- <p>
- <span class="emphasis"><em>Can be defined using C++ statement syntax</em></span>
- </p>
- </td>
-<td>
- <p>
- Yes. Plus eventual compiler errors follow the usual format of C++
- statement errors.
- </p>
- </td>
-<td>
- <p>
- Yes. Plus eventual compiler errors follow the usual format of C++
- statement errors.
- </p>
- </td>
-<td>
- <p>
- Yes. Plus eventual compiler errors follow the usual format of C++
- statement errors.
- </p>
- </td>
-<td>
- <p>
- Yes. Plus eventual compiler errors follow the usual format of C++
- statement errors.
- </p>
- </td>
-<td>
- <p>
- No (it uses C++ <a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Expression-template" target="_top">expression
- template</a> syntax).
- </p>
- </td>
-<td>
- <p>
- No (it uses C++ <a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Expression-template" target="_top">expression
- template</a> syntax).
- </p>
- </td>
+ <p>
+ <span class="emphasis"><em>Can be defined using C++ statement syntax</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. Plus eventual compiler errors follow the usual format of C++
+ statement errors.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. Plus eventual compiler errors follow the usual format of C++
+ statement errors.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. Plus eventual compiler errors follow the usual format of C++
+ statement errors.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. Plus eventual compiler errors follow the usual format of C++
+ statement errors.
+ </p>
+ </td>
+<td>
+ <p>
+ No (it uses C++ <a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Expression-template" target="_top">expression
+ template</a> syntax).
+ </p>
+ </td>
+<td>
+ <p>
+ No (it uses C++ <a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Expression-template" target="_top">expression
+ template</a> syntax).
+ </p>
+ </td>
</tr>
<tr>
<td>
- <p>
- <span class="emphasis"><em>Can be defined within expressions</em></span>
- </p>
- </td>
-<td>
- <p>
- No. It can be defined only within declarations.
- </p>
- </td>
-<td>
- <p>
- No. It can be defined only within declarations.
- </p>
- </td>
-<td>
- <p>
- No. It can be defined only within declarations.
- </p>
- </td>
-<td>
- <p>
- Yes (plus the local function can be unnamed).
- </p>
- </td>
-<td>
- <p>
- Yes (plus the local function can be unnamed).
- </p>
- </td>
-<td>
- <p>
- Yes (plus the local function can be unnamed).
- </p>
- </td>
+ <p>
+ <span class="emphasis"><em>Can be defined within expressions</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ No. It can be defined only within declarations.
+ </p>
+ </td>
+<td>
+ <p>
+ No. It can be defined only within declarations.
+ </p>
+ </td>
+<td>
+ <p>
+ No. It can be defined only within declarations.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes (plus the local function can be unnamed).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes (plus the local function can be unnamed).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes (plus the local function can be unnamed).
+ </p>
+ </td>
</tr>
<tr>
<td>
- <p>
- <span class="emphasis"><em>Can be passed as template parameter (e.g., to STL algorithms)</em></span>
- </p>
- </td>
-<td>
- <p>
- Yes. The C++03
- standard does not allow to pass local types as template parameters
- (see [N2657])
- but this library implements a "trick" to get around this
- limitation (see the <a class="link" href="../">Implementation</a>
- section).
- </p>
- </td>
-<td>
- <p>
- No on C++03
- compilers (but yes on C++11
- compilers and some compilers like MSVC 8.0, see [N2657]).
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
+ <p>
+ <span class="emphasis"><em>Can be passed as template parameter (e.g., to STL algorithms)</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. The C++03
+ standard does not allow to pass local types as template parameters
+ (see [N2657])
+ but this library implements a "trick" to get around this
+ limitation (see the <a class="link" href="Implementation.html" title="Annex: Implementation">Implementation</a>
+ section).
+ </p>
+ </td>
+<td>
+ <p>
+ No on C++03
+ compilers (but yes on C++11
+ compilers and some compilers like MSVC 8.0, see [N2657]).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
</tr>
<tr>
<td>
- <p>
- <span class="emphasis"><em>Access variables in scope</em></span>
- </p>
- </td>
-<td>
- <p>
- Yes. The variable names are repeated in the function declaration
- so they can be bound by value, by constant value, by reference,
- and by constant reference (the object <code class="computeroutput"><span class="keyword">this</span></code>
- can also be bound).
- </p>
- </td>
-<td>
- <p>
- No. Programmers must manually manage functor member variables and
- explicitly specify their types to access variables in scope.
- </p>
- </td>
-<td>
- <p>
- No. Programmers must manually manage functor member variables and
- explicitly specify their types to access variables in scope.
- </p>
- </td>
-<td>
- <p>
- Yes. The variable names are repeated in the function declaration
- (plus there is a short-hand syntax to bind all variables in scope
- at once) so they can be bound by constant value and by reference
- (the object <code class="computeroutput"><span class="keyword">this</span></code> can
- also be bound). However, variables cannot be bound by constant
- references and non-constant value (see below).
- </p>
- </td>
-<td>
- <p>
- Yes (variables in scope are accessible as usual within expressions).
- </p>
- </td>
-<td>
- <p>
- Yes (variables in scope are accessible as usual within expressions)
- plus <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">let</span></code> can be used to bind variables
- by constant reference.
- </p>
- </td>
+ <p>
+ <span class="emphasis"><em>Access variables in scope</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. The variable names are repeated in the function declaration
+ so they can be bound by value, by constant value, by reference, and
+ by constant reference (the object <code class="computeroutput"><span class="keyword">this</span></code>
+ can also be bound).
+ </p>
+ </td>
+<td>
+ <p>
+ No. Programmers must manually manage functor member variables and
+ explicitly specify their types to access variables in scope.
+ </p>
+ </td>
+<td>
+ <p>
+ No. Programmers must manually manage functor member variables and
+ explicitly specify their types to access variables in scope.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. The variable names are repeated in the function declaration
+ (plus there is a short-hand syntax to bind all variables in scope
+ at once) so they can be bound by constant value and by reference
+ (the object <code class="computeroutput"><span class="keyword">this</span></code> can
+ also be bound). However, variables cannot be bound by constant references
+ and non-constant value (see below).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes (variables in scope are accessible as usual within expressions).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes (variables in scope are accessible as usual within expressions)
+ plus <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">let</span></code> can be used to bind variables
+ by constant reference.
+ </p>
+ </td>
</tr>
<tr>
<td>
- <p>
- <span class="emphasis"><em>Polymorphic
- in the unbound parameter types</em></span>
- </p>
- </td>
-<td>
- <p>
- No (local functions cannot be function templates).
- </p>
- </td>
-<td>
- <p>
- No (local classes cannot have member function templates).
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
-<td>
- <p>
- No (C++11
- lambdas cannot be function templates).
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
-<td>
- <p>
- Yes.
- </p>
- </td>
+ <p>
+ <span class="emphasis"><em>Polymorphic
+ in the unbound parameter types</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ No (local functions cannot be function templates).
+ </p>
+ </td>
+<td>
+ <p>
+ No (local classes cannot have member function templates).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ No (C++11
+ lambdas cannot be function templates).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
</tr>
</tbody>
</table></div>
<h6>
-<a name="boost_localfunction.Alternatives.features.h0"></a>
- <span><a name="boost_localfunction.Alternatives.features.comparison_with___cpp0x_lambda___functions"></a></span><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.features.comparison_with___cpp0x_lambda___functions">Comparison
- with __CPP0x_Lambda__ Functions</a>
- </h6>
+<a name="boost_localfunction.Alternatives.h1"></a>
+ <span><a name="boost_localfunction.Alternatives.comparison_with___cpp0x_lambda___functions"></a></span><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.comparison_with___cpp0x_lambda___functions">Comparison
+ with __CPP0x_Lambda__ Functions</a>
+ </h6>
<p>
- __CPP0x_lambda__ functions have most of the features that __Boost_Local__
- local functions have, key pro and cons of the two approaches are:
- </p>
+ __CPP0x_lambda__ functions have most of the features that __Boost_Local__ local
+ functions have, key pro and cons of the two approaches are:
+ </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
- __CPP0x_lambda__ functions can be defined within expressions while __Boost_Local__
- local functions can only be defined within declarations.
- </li>
+ __CPP0x_lambda__ functions can be defined within expressions while __Boost_Local__
+ local functions can only be defined within declarations.
+ </li>
<li class="listitem">
- __CPP0x_lambda__ functions are only supported by the C++11
- standard so they are not supported by all C++ compilers. __Boost_Local__
- local functions use only C++03
- compliant features so they are supported on all C++ compliant compilers.
- </li>
+ __CPP0x_lambda__ functions are only supported by the C++11
+ standard so they are not supported by all C++ compilers. __Boost_Local__
+ local functions use only C++03
+ compliant features so they are supported on all C++ compliant compilers.
+ </li>
<li class="listitem">
- __CPP0x_lambda__ functions do not allow to bind variables in scope by
- constant reference or by non-constant value. Because a variable cannot
- be bound by constant reference, __CPP0x_lambda__ functions can bind a
- variable by constant only if the variable is copyable and the binding
- requires a (potentially expensive) extra copy operation. Both constant
- reference and non-constant value binding are instead supported by __Boost_Local__.
- </li>
+ __CPP0x_lambda__ functions do not allow to bind variables in scope by constant
+ reference or by non-constant value. Because a variable cannot be bound
+ by constant reference, __CPP0x_lambda__ functions can bind a variable by
+ constant only if the variable is copyable and the binding requires a (potentially
+ expensive) extra copy operation. Both constant reference and non-constant
+ value binding are instead supported by __Boost_Local__.
+ </li>
</ul></div>
<p>
- For example, for non-copyable objects:
- </p>
+ For example, for non-copyable objects:
+ </p>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr>
<th>
- <p>
- __CPP0x_Lambda__
- </p>
- </th>
-<th>
- <p>
- __Boost_Local__ __Variadic_Macro_Syntax__
- </p>
- </th>
-<th>
- <p>
- __Boost_Local__ __Sequencing_Macro_Syntax__
- </p>
- </th>
+ <p>
+ __CPP0x_Lambda__
+ </p>
+ </th>
+<th>
+ <p>
+ __Boost_Local__ __Variadic_Macro_Syntax__
+ </p>
+ </th>
+<th>
+ <p>
+ __Boost_Local__ __Sequencing_Macro_Syntax__
+ </p>
+ </th>
</tr></thead>
<tbody>
<tr><td>
- <p>
- [noncopyable_0x_lambda_cpp
- </p>
- </td></tr>
-<tr><td>
- <p>
- noncopyable_boost_local_va_cpp
- </p>
- </td></tr>
-<tr><td>
- <p>
- noncopyable_boost_local_cpp
- </p>
- </td></tr>
+ <p>
+ [noncopyable_0x_lambda_cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ noncopyable_boost_local_va_cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ noncopyable_boost_local_cpp
+ </p>
+ </td></tr>
</tbody>
</table></div>
<p>
- ]
- </p>
+ ]
+ </p>
<p>
- Or, for objects with expensive copy operations:
- </p>
+ Or, for objects with expensive copy operations:
+ </p>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr>
<th>
- <p>
- __CPP0x_Lambda__
- </p>
- </th>
-<th>
- <p>
- __Boost_Local__ __Variadic_Macro_Syntax__
- </p>
- </th>
-<th>
- <p>
- __Boost_Local__ __Sequencing_Macro_Syntax__
- </p>
- </th>
+ <p>
+ __CPP0x_Lambda__
+ </p>
+ </th>
+<th>
+ <p>
+ __Boost_Local__ __Variadic_Macro_Syntax__
+ </p>
+ </th>
+<th>
+ <p>
+ __Boost_Local__ __Sequencing_Macro_Syntax__
+ </p>
+ </th>
</tr></thead>
<tbody>
<tr><td>
- <p>
- [expensive_copy_0x_lambda_cpp
- </p>
- </td></tr>
-<tr><td>
- <p>
- expensive_copy_boost_local_va_cpp
- </p>
- </td></tr>
-<tr><td>
- <p>
- expensive_copy_boost_local_cpp
- </p>
- </td></tr>
+ <p>
+ [expensive_copy_0x_lambda_cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ expensive_copy_boost_local_va_cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ expensive_copy_boost_local_cpp
+ </p>
+ </td></tr>
</tbody>
</table></div>
<p>
- ]
- </p>
+ ]
+ </p>
<h6>
-<a name="boost_localfunction.Alternatives.features.h1"></a>
- <span><a name="boost_localfunction.Alternatives.features.examples"></a></span><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.features.examples">Examples</a>
- </h6>
-<p>
- The same example is rewritten here for all the different alternatives to
- local functions so programmers can get a sense of the different syntaxes
- and programming styles that the alternatives require. The following example
- adds together all the elements of a vector using this library local functions:
- </p>
+<a name="boost_localfunction.Alternatives.h2"></a>
+ <span><a name="boost_localfunction.Alternatives.examples"></a></span><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.examples">Examples</a>
+ </h6>
+<p>
+ The same example is rewritten here for all the different alternatives to local
+ functions so programmers can get a sense of the different syntaxes and programming
+ styles that the alternatives require. The following example adds together all
+ the elements of a vector using this library local functions:
+ </p>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr>
<th>
- <p>
- __Variadic_Macro_Syntax__
- </p>
- </th>
-<th>
- <p>
- __Sequencing_Macro_Syntax__
- </p>
- </th>
+ <p>
+ __Variadic_Macro_Syntax__
+ </p>
+ </th>
+<th>
+ <p>
+ __Sequencing_Macro_Syntax__
+ </p>
+ </th>
</tr></thead>
<tbody>
<tr><td>
- <p>
- [add_using_boost_local_va_cpp
- </p>
- </td></tr>
-<tr><td>
- <p>
- add_using_boost_local_cpp
- </p>
- </td></tr>
+ <p>
+ [add_using_boost_local_va_cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ add_using_boost_local_cpp
+ </p>
+ </td></tr>
</tbody>
</table></div>
<p>
- ]
- </p>
+ ]
+ </p>
<p>
- Or using C++ local functors:
- </p>
+ Or using C++ local functors:
+ </p>
<p>
- [add_using_local_functor_cpp]
- </p>
+ [add_using_local_functor_cpp]
+ </p>
<p>
- Or using C++ global functors (but these do not allow to define the function
- locally so they are not a real alternative implementation of local functions):
- </p>
+ Or using C++ global functors (but these do not allow to define the function
+ locally so they are not a real alternative implementation of local functions):
+ </p>
<p>
- [add_using_global_functor_cpp]
- </p>
+ [add_using_global_functor_cpp]
+ </p>
<p>
- Or using __CPP0x_lambda__ functions (but not part of the C++03
- standard):
- </p>
+ Or using __CPP0x_lambda__ functions (but not part of the C++03
+ standard):
+ </p>
<p>
- [add_using_cpp0x_lambda_cpp]
- </p>
+ [add_using_cpp0x_lambda_cpp]
+ </p>
<p>
- Or using Boost.Lambda
- functions:
- </p>
+ Or using Boost.Lambda
+ functions:
+ </p>
<p>
- [add_using_boost_lambda_cpp]
- </p>
+ [add_using_boost_lambda_cpp]
+ </p>
<p>
- Or using Boost.Phoenix:
- </p>
+ Or using Boost.Phoenix:
+ </p>
<p>
- [add_using_boost_phoenix_cpp]
- </p>
-</div>
-<div class="section">
-<div class="titlepage"><div><div><h3 class="title">
-<a name="boost_localfunction.Alternatives.performances"></a><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.performances" title="Performances">Performances</a>
-</h3></div></div></div>
+ [add_using_boost_phoenix_cpp]
+ </p>
+<h6>
+<a name="boost_localfunction.Alternatives.h3"></a>
+ <span><a name="boost_localfunction.Alternatives.performances"></a></span><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.performances">Performances</a>
+ </h6>
<p>
- The following tables compare run-times, compile-times, and binary sizes for
- the different alternatives presented so far for local functions.
- </p>
+ The following tables compare run-times, compile-times, and binary sizes for
+ the different alternatives presented so far for local functions.
+ </p>
<p>
- Overall, this library has compile-times and generates binary sizes similar
- to the ones of the other approaches. This library run-times on C++03
- compliant compilers (see "__Boost_Local__ Compliant" below) were
- measured to be larger than other approaches when compiler optimization is
- enabled (using <code class="computeroutput"><span class="identifier">bjam</span> <span class="identifier">release</span>
- <span class="special">...</span></code>). However, on compilers that allow
- to pass local types as template parameters (e.g., MSVC 8.0 or GCC 4.5.1 with
- C++11 features
- enabled, see also [N2657])
- this library automatically generates optimized code that runs as fast as
- the fastest of the other approaches (see "__Boost_Local__" below).
- When this library local function is specified <code class="computeroutput"><span class="keyword">inline</span></code>
- (see "__Boost_Local__ Inline For-Loop" below and the <a class="link" href="../">Advanced
- Topics</a> section) its run-times are always comparable to both the "Local
- Functor" and "Global Functor" approaches (but in this case
- the local function cannot be portably passed as template parameter, see
- [N2657],
- so <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code> is replaced by a for-loop). Finally,
- this library run-times are always among the fastest when no compiler optimization
- is enabled (using <code class="computeroutput"><span class="identifier">bjam</span> <span class="identifier">debug</span>
- <span class="special">...</span></code>).
- </p>
+ Overall, this library has compile-times and generates binary sizes similar
+ to the ones of the other approaches. This library run-times on C++03
+ compliant compilers (see "__Boost_Local__ Compliant" below) were
+ measured to be larger than other approaches when compiler optimization is enabled
+ (using <code class="computeroutput"><span class="identifier">bjam</span> <span class="identifier">release</span>
+ <span class="special">...</span></code>). However, on compilers that allow
+ to pass local types as template parameters (e.g., MSVC 8.0 or GCC 4.5.1 with
+ C++11 features
+ enabled, see also [N2657])
+ this library automatically generates optimized code that runs as fast as the
+ fastest of the other approaches (see "__Boost_Local__" below). When
+ this library local function is specified <code class="computeroutput"><span class="keyword">inline</span></code>
+ (see "__Boost_Local__ Inline For-Loop" below and the <a class="link" href="Advanced_Topics.html" title="Advanced Topics">Advanced
+ Topics</a> section) its run-times are always comparable to both the "Local
+ Functor" and "Global Functor" approaches (but in this case the
+ local function cannot be portably passed as template parameter, see [N2657],
+ so <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code> is replaced by a for-loop). Finally,
+ this library run-times are always among the fastest when no compiler optimization
+ is enabled (using <code class="computeroutput"><span class="identifier">bjam</span> <span class="identifier">debug</span>
+ <span class="special">...</span></code>).
+ </p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
- The run-time performances of this library local functions are explained
- because on C++03
- compliant compilers (e.g., GCC 4.3.4) this library needs to use a function
- pointer in order to pass the local function class as a template parameter
- (see [N2657]
- and the <a class="link" href="../">Implementation</a>
- section). For all tested compilers, this function pointer prevents the
- compiler optimization algorithms from inlining the local function calls.
- Instead, the functors used by other approaches like "Boost.Lambda"
- and "Boost.Phoenix"
- have been observed to allow all tested compilers to inline all the function
- calls for optimization. This run-time performance cost is not present on
- compilers that allow to pass local types as template parameters (e.g.,
- MSVC 8.0 or GCC 4.5.1 with C++11
- features enabled) because this library does not have to use the extra function
- pointer to implement the local function call (it directly passes the local
- class type as template parameter).
- </p></td></tr>
+ The run-time performances of this library local functions are explained because
+ on C++03
+ compliant compilers (e.g., GCC 4.3.4) this library needs to use a function
+ pointer in order to pass the local function class as a template parameter
+ (see [N2657]
+ and the <a class="link" href="Implementation.html" title="Annex: Implementation">Implementation</a>
+ section). For all tested compilers, this function pointer prevents the compiler
+ optimization algorithms from inlining the local function calls. Instead,
+ the functors used by other approaches like "Boost.Lambda"
+ and "Boost.Phoenix"
+ have been observed to allow all tested compilers to inline all the function
+ calls for optimization. This run-time performance cost is not present on
+ compilers that allow to pass local types as template parameters (e.g., MSVC
+ 8.0 or GCC 4.5.1 with C++11
+ features enabled) because this library does not have to use the extra function
+ pointer to implement the local function call (it directly passes the local
+ class type as template parameter).
+ </p></td></tr>
</table></div>
<p>
- This run-time performance cost on C++03
- compliant compilers might or might not be an issue depending on the performance
- requirements of specific applications. For example, an application might
- already be using a number of indirect function calls (function pointers,
- virtual functions, etc) for which the overhead added by using the one extra
- function pointer required by the local function call might not be noticeable
- within the overall program run-time.
- </p>
+ This run-time performance cost on C++03
+ compliant compilers might or might not be an issue depending on the performance
+ requirements of specific applications. For example, an application might already
+ be using a number of indirect function calls (function pointers, virtual functions,
+ etc) for which the overhead added by using the one extra function pointer required
+ by the local function call might not be noticeable within the overall program
+ run-time.
+ </p>
<p>
- Finally, note that only a very simple local function body with just a single
- instruction was used for the anaylsis presented here (see the <code class="computeroutput"><span class="identifier">profile_</span><span class="special">...</span></code>
- source files linked below). The authors have not studied how this library
- and the other approaches will perform with respect to each other when a more
- complex set of instructions is programmed for the local function body (e.g.,
- <span class="emphasis"><em>if</em></span> a more complex set of instructions in the local function
- body were to inhibit some compilers from inlining functor objects also other
- approaches like Boost.Lambda
- and Boost.Phoenix
- <span class="emphasis"><em>could</em></span> start to show higher run-times even when optimization
- is enabled).
- </p>
+ Finally, note that only a very simple local function body with just a single
+ instruction was used for the anaylsis presented here (see the <code class="computeroutput"><span class="identifier">profile_</span><span class="special">...</span></code>
+ source files linked below). The authors have not studied how this library and
+ the other approaches will perform with respect to each other when a more complex
+ set of instructions is programmed for the local function body (e.g., <span class="emphasis"><em>if</em></span>
+ a more complex set of instructions in the local function body were to inhibit
+ some compilers from inlining functor objects also other approaches like Boost.Lambda
+ and Boost.Phoenix
+ <span class="emphasis"><em>could</em></span> start to show higher run-times even when optimization
+ is enabled).
+ </p>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
- <p>
- Legend, Source Files, and Commands
- </p>
- </th></tr></thead>
+ <p>
+ Legend, Source Files, and Commands
+ </p>
+ </th></tr></thead>
<tbody>
<tr><td>
- <p>
- <span class="inlinemediaobject"><img src="../../../example/profile_legend.png" width="1170" alt="profile_legend"></span>
- </p>
- </td></tr>
-<tr><td>
- <p>
- The local function was called <code class="literal">1e8</code> times to add
- together all the elements of a vector and the run-time was measured
- using Boost.Chrono
- averaging over <code class="literal">10</code> executions of the vector summation
- (see source files profile_boost_local.cpp
,
- profile_boost_local_inline.cpp
,
- profile_local_functor.cpp
,
- profile_global_functor.cpp
,
- profile_0x_lambda.cpp
,
- profile_boost_lambda.cpp
,
- and profile_boost_phoenix.cpp
).
- </p>
- </td></tr>
-<tr><td>
- <p>
- The following commands were executed from the library example directory
- to measure compile-time, binary size, and run-time respectively:
+ <p>
+ <span class="inlinemediaobject"><img src="../../../example/profile_legend.png" width="1170" alt="profile_legend"></span>
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ The local function was called <code class="literal">1e8</code> times to add
+ together all the elements of a vector and the run-time was measured
+ using Boost.Chrono
+ averaging over <code class="literal">10</code> executions of the vector summation
+ (see source files profile_boost_local.cpp
,
+ profile_boost_local_inline.cpp
,
+ profile_local_functor.cpp
,
+ profile_global_functor.cpp
,
+ profile_0x_lambda.cpp
,
+ profile_boost_lambda.cpp
,
+ and profile_boost_phoenix.cpp
).
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ The following commands were executed from the library example directory
+ to measure compile-time, binary size, and run-time respectively:
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></span> <span class="identifier">python</span> <span class="identifier">chrono</span><span class="special">.</span><span class="identifier">py</span> <span class="identifier">bjam</span> <span class="special">{</span><span class="identifier">release</span><span class="special">|</span><span class="identifier">debug</span><span class="special">}</span> <span class="special"><</span><span class="identifier">PROGRAM</span><span class="special">></span> <span class="preprocessor"># compile</span><span class="special">-</span><span class="identifier">time</span>
<span class="special">></span> <span class="identifier">size</span> <span class="special"><</span><span class="identifier">PROGRAM</span><span class="special">></span> <span class="preprocessor"># binary</span> <span class="identifier">size</span> <span class="special">(</span><span class="identifier">Linux</span> <span class="keyword">and</span> <span class="identifier">Gygwin</span><span class="special">)</span>
<span class="special">></span> <span class="special"><</span><span class="identifier">PROGRAM</span><span class="special">></span> <span class="preprocessor"># run</span><span class="special">-</span><span class="identifier">time</span>
</pre>
<p>
- </p>
- </td></tr>
+ </p>
+ </td></tr>
</tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
- <p>
- GCC 4.5.1 With C++11
- Lambdas and "Local Types as Template Parameters" (<code class="literal">bjam
- cxxflags=-std=c++0x ...</code>) on Ubuntu Linux 10
- </p>
- </th></tr></thead>
+ <p>
+ GCC 4.5.1 With C++11
+ Lambdas and "Local Types as Template Parameters" (<code class="literal">bjam
+ cxxflags=-std=c++0x ...</code>) on Ubuntu Linux 10
+ </p>
+ </th></tr></thead>
<tbody>
<tr><td>
- <p>
- <span class="bold"><strong>Compiled with <code class="literal">bjam release ...</code>
- for maximum optimization (<code class="literal">-O3 -finline-functions</code>)</strong></span>
- <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.5.1-0x_release.png" width="1170" alt="profile_gcc-4.5.1-0x_release"></span>
- </p>
- </td></tr>
-<tr><td>
- <p>
- <span class="bold"><strong>Compiled with <code class="literal">bjam debug ...</code>
- for no optimization (<code class="literal">-O0 -fno-inline</code>)</strong></span>
- <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.5.1-0x_debug.png" width="1170" alt="profile_gcc-4.5.1-0x_debug"></span>
- </p>
- </td></tr>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam release ...</code>
+ for maximum optimization (<code class="literal">-O3 -finline-functions</code>)</strong></span>
+ <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.5.1-0x_release.png" width="1170" alt="profile_gcc-4.5.1-0x_release"></span>
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam debug ...</code>
+ for no optimization (<code class="literal">-O0 -fno-inline</code>)</strong></span>
+ <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.5.1-0x_debug.png" width="1170" alt="profile_gcc-4.5.1-0x_debug"></span>
+ </p>
+ </td></tr>
</tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
- <p>
- MSVC 8.0 With "Local Types as Template Parameters" (Without
- C++11
- Lambdas) on Windows XP
- </p>
- </th></tr></thead>
+ <p>
+ MSVC 8.0 With "Local Types as Template Parameters" (Without
+ C++11
+ Lambdas) on Windows XP
+ </p>
+ </th></tr></thead>
<tbody>
<tr><td>
- <p>
- <span class="bold"><strong>Compiled with <code class="literal">bjam release ...</code>
- for maximum optimization (<code class="literal">/O2 /Ob2</code>)</strong></span>
- <span class="inlinemediaobject"><img src="../../../example/profile_msvc-8.0_release.png" width="1170" alt="profile_msvc-8.0_release"></span>
- </p>
- </td></tr>
-<tr><td>
- <p>
- <span class="bold"><strong>Compiled with <code class="literal">bjam debug ...</code>
- for no optimization (<code class="literal">/Od /Ob0</code>)</strong></span> <span class="inlinemediaobject"><img src="../../../example/profile_msvc-8.0_debug.png" width="1170" alt="profile_msvc-8.0_debug"></span>
- </p>
- </td></tr>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam release ...</code>
+ for maximum optimization (<code class="literal">/O2 /Ob2</code>)</strong></span>
+ <span class="inlinemediaobject"><img src="../../../example/profile_msvc-8.0_release.png" width="1170" alt="profile_msvc-8.0_release"></span>
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam debug ...</code>
+ for no optimization (<code class="literal">/Od /Ob0</code>)</strong></span> <span class="inlinemediaobject"><img src="../../../example/profile_msvc-8.0_debug.png" width="1170" alt="profile_msvc-8.0_debug"></span>
+ </p>
+ </td></tr>
</tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
- <p>
- GCC 4.3.4 With C++03
- Only (Without C++11
- Lambdas and Without "Local Types as Template Parameters) on
- Cygwin
- </p>
- </th></tr></thead>
+ <p>
+ GCC 4.3.4 With C++03
+ Only (Without C++11
+ Lambdas and Without "Local Types as Template Parameters) on
+ Cygwin
+ </p>
+ </th></tr></thead>
<tbody>
<tr><td>
- <p>
- <span class="bold"><strong>Compiled with <code class="literal">bjam release ...</code>
- for maximum optimization (<code class="literal">-O3 -finline-functions</code>)</strong></span>
- <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.3.4_release.png" width="1170" alt="profile_gcc-4.3.4_release"></span>
- </p>
- </td></tr>
-<tr><td>
- <p>
- <span class="bold"><strong>Compiled with <code class="literal">bjam debug ...</code>
- for no optimization (<code class="literal">-O0 -fno-inline</code>)</strong></span>
- <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.3.4_debug.png" width="1170" alt="profile_gcc-4.3.4_debug"></span>
- </p>
- </td></tr>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam release ...</code>
+ for maximum optimization (<code class="literal">-O3 -finline-functions</code>)</strong></span>
+ <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.3.4_release.png" width="1170" alt="profile_gcc-4.3.4_release"></span>
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam debug ...</code>
+ for no optimization (<code class="literal">-O0 -fno-inline</code>)</strong></span>
+ <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.3.4_debug.png" width="1170" alt="profile_gcc-4.3.4_debug"></span>
+ </p>
+ </td></tr>
</tbody>
</table></div>
</div>
-</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2009-2012 Lorenzo
Caminiti<p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="Examples.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="No_Variadic_Macros.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+<a accesskey="p" href="../BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="No_Variadic_Macros.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
Modified: sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Bibliography.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Bibliography.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Bibliography.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -30,6 +30,9 @@
This section lists all the bibliographic references cited by this documentation.
</p>
<p>
+ @todo complete this
+ </p>
+<p>
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2511.html" target="_top">[N2511]</a>
Alisdair Meredith. <span class="emphasis"><em>Named Lambdas and Local Functions.</em></span>
The C++ Standards Committee, document no. N2511=08-0021, 2008.
@@ -57,7 +60,7 @@
<td align="right"><div class="copyright-footer">Copyright © 2009-2012 Lorenzo
Caminiti<p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
Modified: sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Examples.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Examples.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Examples.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -1,13 +1,13 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
-<title>Appendix: Examples</title>
+<title>Examples</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
<link rel="up" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
<link rel="prev" href="Advanced_Topics.html" title="Advanced Topics">
-<link rel="next" href="Alternatives.html" title="Appendix: Alternatives">
+<link rel="next" href="../reference.html" title="Reference">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
@@ -20,11 +20,11 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="Advanced_Topics.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="Alternatives.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+<a accesskey="p" href="Advanced_Topics.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../reference.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
-<a name="boost_localfunction.Examples"></a><a class="link" href="Examples.html" title="Appendix: Examples">Appendix: Examples</a>
+<a name="boost_localfunction.Examples"></a><a class="link" href="Examples.html" title="Examples">Examples</a>
</h2></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="Examples.html#boost_localfunction.Examples.gcc_lambdas__without_c__11_">GCC
@@ -32,12 +32,15 @@
<dt><span class="section"><a href="Examples.html#boost_localfunction.Examples.constant_blocks">Constant
Blocks</a></span></dt>
<dt><span class="section">Scope Exits</span></dt>
+<dt><span class="section"><a href="Examples.html#boost_localfunction.Examples.boost_phoenix_functions">Boost.Phoenix
+ Functions</a></span></dt>
+<dt><span class="section">Closures</span></dt>
<dt><span class="section"><a href="Examples.html#boost_localfunction.Examples.gcc_nested_functions">GCC
Nested Functions</a></span></dt>
<dt><span class="section">N-Papers</span></dt>
</dl></div>
<p>
- This sections lists some (interesting) examples that use this library features.
+ This sections lists some examples that use this library features.
</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
@@ -46,8 +49,8 @@
</h3></div></div></div>
<p>
Combing local functions with the <a href="http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html" target="_top">statement
- expression</a> GCC extension, it is possible to implement lambda functions
- for GCC compilers even without C++11
+ expression</a> extension of GCC compilers, it is possible to implement
+ lambda functions for GCC compilers even without C++11
support.
</p>
<div class="warning"><table border="0" summary="Warning">
@@ -62,7 +65,8 @@
</p></td></tr>
</table></div>
<p>
- For example (see also "gcc_lambda.cpp"
and "gcc_lambda_cpp11.cpp"
):
+ For example (see also gcc_lambda.cpp
+ and gcc_lambda_cpp11.cpp
):
</p>
<div class="informaltable"><table class="table">
<colgroup>
@@ -117,15 +121,15 @@
</tr></tbody>
</table></div>
<p>
- The macros are defined in "gcc_lambda.hpp"
.
+ Where the macros are defined in gcc_lambda.hpp
.
</p>
<p>
- This is possible because GCC statement expressions allow to put declaration
+ This is possible because GCC statement expressions allow to use declaration
statements within expressions and therefore to declare a local function within
an expression. The macros automatically detect if the compiler supports
<a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
lambda</a> functions in which case the implementation uses native lambdas
- instead of local functions. However, <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ instead of local functions in statement expressions. However, <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
lambda</a> functions do not support constant binding so it is best to
only use <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span>
<span class="identifier">variable</span></code> (same as <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
@@ -141,7 +145,7 @@
the macros because they are not supported by the local function implementation.
Finally, the result type <code class="computeroutput"><span class="keyword">return</span> </code><code class="literal"><span class="emphasis"><em>result-type</em></span></code>
is optional and it is assumed <code class="computeroutput"><span class="keyword">void</span></code>
- when it is not specified (as with <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ when it is not specified (same as with <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
lambda</a> functions).
</p>
</div>
@@ -152,9 +156,9 @@
</h3></div></div></div>
<p>
It is possible to use local functions to check assertions between variables
- that are constant within the assertion expression. This is advantageous because
- assertions are not supposed to change the state of the program and ideally
- the compiler will not compile assertions that modify variables.
+ that are made constant within the asserted expression. This is advantageous
+ because assertions are not supposed to change the state of the program and
+ ideally the compiler will not compile assertions that modify variables.
</p>
<p>
For example, consider the following assertion where by mistake we programmed
@@ -169,13 +173,12 @@
but the assertion even passes the run-time check and no error is generated
at all. The [N1613]
paper introduced the idea of a <span class="emphasis"><em>const-block</em></span> which could
- be used to wrap the assertion above and catch the mistake at compile-time.
- Similarly to [N1613]
- const-blocks, the following code will generate a compile-time error when
- <code class="computeroutput"><span class="keyword">operator</span><span class="special">=</span></code>
+ be used to wrap the assertion above and catch the programming error at compile-time.
+ Similarly, the following code will generate a compile-time error when <code class="computeroutput"><span class="keyword">operator</span><span class="special">=</span></code>
is mistakenly used instead of <code class="computeroutput"><span class="keyword">operator</span><span class="special">==</span></code> because both <code class="computeroutput"><span class="identifier">x</span></code>
- and <code class="computeroutput"><span class="identifier">y</span></code> are constants within
- the block of code performing the assertion (see also "const_block.cpp"
):
+ and <code class="computeroutput"><span class="identifier">y</span></code> are made constants
+ (using local functions) within the block of code performing the assertion
+ (see also const_block.cpp
):
</p>
<div class="informaltable"><table class="table">
<colgroup>
@@ -200,7 +203,7 @@
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
<span class="identifier">CONST_BLOCK</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Constant block.</span>
- <span class="identifier">assert</span><span class="special">(</span><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">y</span><span class="special">);</span> <span class="comment">// Compiler error.</span>
+ <span class="identifier">assert</span><span class="special">(</span><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">y</span><span class="special">);</span> <span class="comment">// Compiler error.</span>
<span class="special">}</span> <span class="identifier">CONST_BLOCK_END</span>
</pre>
<p>
@@ -210,8 +213,8 @@
<p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
-<span class="keyword">const</span> <span class="special">{</span> <span class="comment">// Constant block.</span>
- <span class="identifier">assert</span><span class="special">(</span><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">y</span><span class="special">);</span> <span class="comment">// Compiler error.</span>
+<span class="keyword">const</span> <span class="special">{</span> <span class="comment">// Constant block.</span>
+ <span class="identifier">assert</span><span class="special">(</span><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">y</span><span class="special">);</span> <span class="comment">// Compiler error.</span>
<span class="special">}</span>
</pre>
<p>
@@ -220,28 +223,29 @@
</tr></tbody>
</table></div>
<p>
- The macros are defined in "const_block.hpp"
.
+ Where the macros are defined in const_block.hpp
.
</p>
<p>
The constant block macros are implemented using a local function which binds
by constant reference <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&</span></code>
- all the specified variables, it executes the <code class="computeroutput"><span class="identifier">assert</span></code>
- instruction in local function body, and the local function is then called
+ all the specified variables (so the variables are constant within the code
+ block but they do not need to be <code class="computeroutput"><span class="identifier">CopyConstructible</span></code>
+ and no extra copy is performed). The local function executes the <code class="computeroutput"><span class="identifier">assert</span></code> instruction its body which is called
immediately after it is defined. More in general, constant blocks can be
used to evaluate any instruction (not just assertions) within a block were
all specified variables are constant.
</p>
<p>
Unfortunately, constant blocks cannot be implemented with <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
- lambda</a> functions because these do not support constant binding. Ideally,
- <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
- lambda</a> functions would allow to bind variables also using <code class="computeroutput"><span class="keyword">const</span><span class="special">&</span> <span class="identifier">variable</span></code> (constant reference) and <code class="computeroutput"><span class="keyword">const</span><span class="special">&</span></code>
- (all variables by constant reference). Variables bound by value using <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions because these do not support constant binding (of
+ course it is always possible to introduce extra constant variables <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&</span> <span class="identifier">const_x</span>
+ <span class="special">=</span> <span class="identifier">x</span><span class="special">;</span></code> and use these variables in the assertion).
+ Variables bound by value using <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
lambda</a> functions (<code class="computeroutput"><span class="identifier">variable</span></code>,
<code class="computeroutput"><span class="special">=</span><span class="identifier">variable</span></code>,
and <code class="computeroutput"><span class="special">=</span></code>) are constant but they
are required to be <code class="computeroutput"><span class="identifier">CopyConstructible</span></code>
- and they introduce potentially expensive copy operations.
+ and they introduce potentially expensive copy operations. <sup>[<a name="boost_localfunction.Examples.constant_blocks.f0" href="#ftn.boost_localfunction.Examples.constant_blocks.f0" class="footnote">27</a>]</sup>
</p>
</div>
<div class="section">
@@ -269,7 +273,7 @@
by constant reference so this variable cannot be modified within the scope
exit body but it is not copied and it will present the value it has at the
exit of the enclosing scope and not at the scope exit declaration (see also
- "scope_exit.cpp"
):
+ scope_exit.cpp
):
</p>
<div class="informaltable"><table class="table">
<colgroup>
@@ -318,11 +322,11 @@
</tr></tbody>
</table></div>
<p>
- The macros are defined in "scope_exit.hpp"
.
+ Where the macros are defined in scope_exit.hpp
.
</p>
<p>
- The scope exit macros are implemented by passing a local function to the
- constructor of the following object:
+ The scope exit macros are implemented by passing a local function when constructing
+ an object of the following class:
</p>
<p>
</p>
@@ -336,12 +340,142 @@
<p>
</p>
<p>
- The object variable is declared locally within the enclosing scope so the
- object destructor will be invoked at the exit of the enclosing scope and
- it will in turn call the local function. The scope exit local function has
- no parameter and <code class="computeroutput"><span class="keyword">void</span></code> result
- type but it supports binding and constant binding.
+ A local variable within the enclosing scope is used to hold the object so
+ the destructor will be invoked at the exit of the enclosing scope and it
+ will in turn call the local function executing the scope exit instructions.
+ The scope exit local function has no parameter and <code class="computeroutput"><span class="keyword">void</span></code>
+ result type but it supports binding and constant binding.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Examples.boost_phoenix_functions"></a><a class="link" href="Examples.html#boost_localfunction.Examples.boost_phoenix_functions" title="Boost.Phoenix Functions">Boost.Phoenix
+ Functions</a>
+</h3></div></div></div>
+<p>
+ Local functions can be used to create Boost.Phoenix
+ functions. For example (see also boost_phoenix_local_factorial.cpp
+ and boost_phoenix_factorial.cpp
):
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ Local Functions
+ </p>
+ </th>
+<th>
+ <p>
+ Global Functor
+ </p>
+ </th>
+</tr></thead>
+<tbody><tr>
+<td>
+ <p>
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">example_boost_phoenix_factorial_local</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">arg_names</span><span class="special">::</span><span class="identifier">arg1</span><span class="special">;</span>
+
+ <span class="keyword">int</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Monomorphic.</span>
+ <span class="keyword">return</span> <span class="special">(</span><span class="identifier">n</span> <span class="special"><=</span> <span class="number">0</span><span class="special">)</span> <span class="special">?</span> <span class="number">1</span> <span class="special">:</span> <span class="identifier">n</span> <span class="special">*</span> <span class="identifier">factorial_impl</span><span class="special">(</span><span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">recursive</span> <span class="identifier">factorial_impl</span><span class="special">)</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span><span class="keyword">int</span> <span class="special">(</span><span class="keyword">int</span><span class="special">)></span> <span class="special">></span>
+ <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">factorial_impl</span><span class="special">);</span> <span class="comment">// Phoenix function from local function.</span>
+
+ <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">4</span><span class="special">;</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">i</span><span class="special">)()</span> <span class="special">==</span> <span class="number">24</span> <span class="special">);</span> <span class="comment">// Call.</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">)(</span><span class="identifier">i</span><span class="special">)</span> <span class="special">==</span> <span class="number">24</span> <span class="special">);</span> <span class="comment">// Lazy call.</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+ </td>
+<td>
+ <p>
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">struct</span> <span class="identifier">factorial_impl</span> <span class="special">{</span> <span class="comment">// Phoenix function from global functor.</span>
+ <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Sig</span><span class="special">></span>
+ <span class="keyword">struct</span> <span class="identifier">result</span><span class="special">;</span>
+
+ <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">This</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Arg</span><span class="special">></span>
+ <span class="keyword">struct</span> <span class="identifier">result</span><span class="special"><</span><span class="identifier">This</span> <span class="special">(</span><span class="identifier">Arg</span><span class="special">)></span> <span class="special">:</span> <span class="identifier">result</span><span class="special"><</span><span class="identifier">This</span> <span class="special">(</span><span class="identifier">Arg</span> <span class="keyword">const</span><span class="special">&)></span> <span class="special">{};</span>
+
+ <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">This</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Arg</span><span class="special">></span>
+ <span class="keyword">struct</span> <span class="identifier">result</span><span class="special"><</span><span class="identifier">This</span> <span class="special">(</span><span class="identifier">Arg</span><span class="special">&)></span> <span class="special">{</span> <span class="keyword">typedef</span> <span class="identifier">Arg</span> <span class="identifier">type</span><span class="special">;</span> <span class="special">};</span>
+
+ <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Arg</span><span class="special">></span> <span class="comment">// Polymorphic.</span>
+ <span class="identifier">Arg</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">Arg</span> <span class="identifier">n</span><span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="special">(</span><span class="identifier">n</span> <span class="special"><=</span> <span class="number">0</span><span class="special">)</span> <span class="special">?</span> <span class="number">1</span> <span class="special">:</span> <span class="identifier">n</span> <span class="special">*</span> <span class="special">(*</span><span class="keyword">this</span><span class="special">)(</span><span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">example_boost_phoenix_factorial</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">arg_names</span><span class="special">::</span><span class="identifier">arg1</span><span class="special">;</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">function</span><span class="special"><</span><span class="identifier">factorial_impl</span><span class="special">></span> <span class="identifier">factorial</span><span class="special">;</span>
+
+ <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">4</span><span class="special">;</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">i</span><span class="special">)()</span> <span class="special">==</span> <span class="number">24</span> <span class="special">);</span> <span class="comment">// Call.</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">arg1</span><span class="special">)(</span><span class="identifier">i</span><span class="special">)</span> <span class="special">==</span> <span class="number">24</span> <span class="special">);</span> <span class="comment">// Lazy call.</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+ </td>
+</tr></tbody>
+</table></div>
+<p>
+ This is presented here mainly as a curiosity because Boost.Phoenix
+ functions created from local functions have the important limitation that
+ they cannot be polymorphic. <sup>[<a name="boost_localfunction.Examples.boost_phoenix_functions.f0" href="#ftn.boost_localfunction.Examples.boost_phoenix_functions.f0" class="footnote">28</a>]</sup> Therefore, in many cases creating the Boost.Phoenix
+ function from global functors (possibly with the help of Boost.Phoenix
+ adaptor macros) might be a more valuable option.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Examples.closures"></a><a class="link" href="Examples.html#boost_localfunction.Examples.closures" title="Closures">Closures</a>
+</h3></div></div></div>
+<p>
+ A few more examples on how to return local functions to the calling scope
+ (and the relative precautions to take) mainly adapted from examples of closures.
</p>
+<div class="informaltable"><table class="table">
+<colgroup><col></colgroup>
+<thead><tr><th>
+ <p>
+ Files
+ </p>
+ </th></tr></thead>
+<tbody>
+<tr><td>
+ <p>
+ return_inc.cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ return_this.cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ return_setget.cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ return_derivative.cpp
+ </p>
+ </td></tr>
+</tbody>
+</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
@@ -357,7 +491,7 @@
</p>
<p>
The following examples are taken form the GCC nested function documentation
- but are programmed using this library:
+ and programmed using this library:
</p>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
@@ -369,17 +503,17 @@
<tbody>
<tr><td>
<p>
- "gcc_square.cpp"
+ gcc_square.cpp
</p>
</td></tr>
<tr><td>
<p>
- "gcc_access.cpp"
+ gcc_access.cpp
</p>
</td></tr>
<tr><td>
<p>
- "gcc_store.cpp"
+ gcc_store.cpp
</p>
</td></tr>
</tbody>
@@ -414,7 +548,7 @@
<tr>
<td>
<p>
- "n2550_find_if.cpp"
+ n2550_find_if.cpp
</p>
</td>
<td>
@@ -429,7 +563,7 @@
<tr>
<td>
<p>
- "n2529_this.cpp"
+ n2529_this.cpp
</p>
</td>
<td>
@@ -443,19 +577,32 @@
</tbody>
</table></div>
</div>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Examples.constant_blocks.f0" href="#boost_localfunction.Examples.constant_blocks.f0" class="para">27</a>] </sup>
+ Ideally, <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions would allow to bind variables also using <code class="computeroutput"><span class="keyword">const</span><span class="special">&</span> <span class="identifier">variable</span></code> (constant reference) and <code class="computeroutput"><span class="keyword">const</span><span class="special">&</span></code>
+ (all variables by constant reference).
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Examples.boost_phoenix_functions.f0" href="#boost_localfunction.Examples.boost_phoenix_functions.f0" class="para">28</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> Local functions can only be
+ monomorphic because they are implemented using local classes and local
+ classes cannot be templates in C++ (not even in C++11).
+ </p></div>
+</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2009-2012 Lorenzo
Caminiti<p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="Advanced_Topics.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="Alternatives.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+<a accesskey="p" href="Advanced_Topics.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../reference.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
Modified: sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Getting_Started.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Getting_Started.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Getting_Started.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -32,11 +32,10 @@
<dt><span class="section"><a href="Getting_Started.html#boost_localfunction.Getting_Started.compilers_and_platforms">Compilers
and Platforms</a></span></dt>
<dt><span class="section">Installation</span></dt>
-<dt><span class="section"><a href="Getting_Started.html#boost_localfunction.Getting_Started.compile_time_configuration">Compile-Time
- Configuration</a></span></dt>
+<dt><span class="section">Configuration</span></dt>
</dl></div>
<p>
- This section explains how to setup a system to use this library.
+ This section explains how programmers can setup their system to use this library.
</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
@@ -45,12 +44,13 @@
</h3></div></div></div>
<p>
Programmers should have enough knowledge to use this library after reading
- the <a class="link" href="../">Introduction</a>, <a class="link" href="../">Getting
- Started</a>, and <a class="link" href="../">Tutorial</a>
- sections. The <a class="link" href="../">Advanced Topics</a>
+ the <a class="link" href="../index.html#boost_localfunction.Introduction" title="Introduction">Introduction</a>,
+ <a class="link" href="Getting_Started.html" title="Getting Started">Getting Started</a>,
+ and <a class="link" href="Tutorial.html" title="Tutorial">Tutorial</a> sections.
+ The <a class="link" href="Advanced_Topics.html" title="Advanced Topics">Advanced Topics</a>
and Reference sections can be consulted
at a later point to gain a more advanced knowledge of the library. All the
- other sections of this documentation are optional.
+ other sections of this documentation can be considered optional.
</p>
<p>
Some footnotes are marked by the word "<span class="bold"><strong>Rationale</strong></span>".
@@ -61,9 +61,10 @@
In some of the examples presented in this documentation, the Boost.Test
macro <code class="computeroutput"><span class="identifier">BOOST_CHECK</span></code> is used
equivalently to <code class="computeroutput"><span class="identifier">assert</span></code> and
- Boost.Test
- <code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_CASE</span></code> equivalently
- to <code class="computeroutput"><span class="identifier">main</span></code>. <sup>[<a name="boost_localfunction.Getting_Started.this_documentation.f0" href="#ftn.boost_localfunction.Getting_Started.this_documentation.f0" class="footnote">1</a>]</sup>
+ the Boost.Test
+ macro <code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_CASE</span></code>
+ is used equivalently to <code class="computeroutput"><span class="identifier">main</span></code>.
+ <sup>[<a name="boost_localfunction.Getting_Started.this_documentation.f0" href="#ftn.boost_localfunction.Getting_Started.this_documentation.f0" class="footnote">3</a>]</sup>
</p>
</div>
<div class="section">
@@ -84,11 +85,12 @@
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
- GNU Compiler Collection (GCC) 4.5.1 (with and without C++11
- features enabled) on Ubuntu Linux 10.
+ GNU Compiler Collection (GCC) 4.5.1 on Ubuntu Linux 10.
</li>
<li class="listitem">
- GCC 4.3.4 on Cygwin.
+ GCC 4.3.4 and 4.5.3 (with and without C++11
+ features enabled <code class="computeroutput"><span class="special">-</span><span class="identifier">std</span><span class="special">=</span><span class="identifier">c</span><span class="special">++</span><span class="number">0</span><span class="identifier">x</span></code>)
+ on Cygwin.
</li>
<li class="listitem">
Miscrosoft Visual Studio Compiler (MSVC) 8.0 on Windows XP and Windows
@@ -96,7 +98,7 @@
</li>
</ol></div>
<p>
- This library has not yet been tested on any other compiler or platform.
+ This library has not yet been tested on any other compiler and platform.
</p>
</div>
<div class="section">
@@ -105,9 +107,10 @@
</h3></div></div></div>
<p>
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 C++ compiler where to find the library header files (<code class="computeroutput"><span class="special">-</span><span class="identifier">I</span></code> option for GCC, <code class="computeroutput"><span class="special">/</span><span class="identifier">I</span></code> option for MSVC, etc) and they can start
- compiling the code that uses this library.
+ object file which needs to be installed or linked. Programmers can simply
+ instruct the C++ compiler where to find the library header files (<code class="computeroutput"><span class="special">-</span><span class="identifier">I</span></code> option
+ for GCC, <code class="computeroutput"><span class="special">/</span><span class="identifier">I</span></code>
+ option for MSVC, etc) and they can start compiling code using this library.
</p>
<p>
This library implementation uses a number of Boost
@@ -121,16 +124,13 @@
</p>
<p>
The followings are part of the library private API, they are not documented,
- and they should not be directly used by programmers: <sup>[<a name="boost_localfunction.Getting_Started.installation.f0" href="#ftn.boost_localfunction.Getting_Started.installation.f0" class="footnote">2</a>]</sup>
+ and they should not be directly used by programmers: <sup>[<a name="boost_localfunction.Getting_Started.installation.f0" href="#ftn.boost_localfunction.Getting_Started.installation.f0" class="footnote">4</a>]</sup>
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
- Any symbol defined by files within the <code class="computeroutput"><span class="string">"boost/local_function/aux_/"</span></code>
- or <code class="computeroutput"><span class="string">"boost/local_function/detail"</span></code>
- directories (these header files should not be directly included by programmers).
- </li>
-<li class="listitem">
- Any symbol prefixed by <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION_AUX_</span><span class="special">...</span></code> or <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION_DETAIL_</span><span class="special">...</span></code> (regardless of its namespace).
+ Any symbol defined by files within the <code class="literal">boost/local_function/aux_/</code>
+ or <code class="literal">boost/local_function/detail/</code> directory (these header
+ files should not be directly included by programmers).
</li>
<li class="listitem">
Any symbol within the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">local_function</span><span class="special">::</span><span class="identifier">aux</span></code>
@@ -139,12 +139,14 @@
<li class="listitem">
Any symbol prefixed by <code class="computeroutput"><span class="identifier">boost_local_function_aux_</span><span class="special">...</span></code> or <code class="computeroutput"><span class="identifier">boost_local_function_detail_</span><span class="special">...</span></code> (regardless of its namespace).
</li>
+<li class="listitem">
+ Any symbol prefixed by <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION_AUX_</span><span class="special">...</span></code> or <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION_DETAIL_</span><span class="special">...</span></code> (regardless of its namespace).
+ </li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
-<a name="boost_localfunction.Getting_Started.compile_time_configuration"></a><a class="link" href="Getting_Started.html#boost_localfunction.Getting_Started.compile_time_configuration" title="Compile-Time Configuration">Compile-Time
- Configuration</a>
+<a name="boost_localfunction.Getting_Started.configuration"></a><a class="link" href="Getting_Started.html#boost_localfunction.Getting_Started.configuration" title="Configuration">Configuration</a>
</h3></div></div></div>
<p>
Some of the library behaviour can be changed at compile-time by defining
@@ -153,33 +155,34 @@
it.
</p>
<p>
- All configuration macros have names prefixed by <code class="computeroutput"><span class="identifier">BOOST_LOCAL_CONFIG_</span><span class="special">...</span></code> (see the Reference
- section). It is strongly recommended not to change the library configuration
- macro definitions unless strictly necessary.
+ All configuration macros are defined in the header file <code class="computeroutput"><a class="link" href="../reference.html#header.boost.local_function.config_hpp" title="Header <boost/local_function/config.hpp>">boost/local_function/config.hpp</a></code>.
+ It is strongly recommended not to change the library configuration macro
+ definitions unless strictly necessary.
</p>
</div>
<div class="footnotes">
<br><hr width="100" align="left">
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Getting_Started.this_documentation.f0" href="#boost_localfunction.Getting_Started.this_documentation.f0" class="para">1</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Getting_Started.this_documentation.f0" href="#boost_localfunction.Getting_Started.this_documentation.f0" class="para">3</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> Using Boost.Test
- allows to add the documentation examples to the library regression test
- suite so to make sure that the listed examples always compile and run correctly.
+ allows to add the documentation examples to the library regression tests
+ so to make sure that the listed examples always compile and run correctly.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Getting_Started.installation.f0" href="#boost_localfunction.Getting_Started.installation.f0" class="para">2</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Getting_Started.installation.f0" href="#boost_localfunction.Getting_Started.installation.f0" class="para">4</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> This library concatenates symbols
specified by the programmers (e.g., the local function name) with other
symbols (e.g., special prefixes or preprocessor line numbers) to make internal
symbols with unique names to avoid name clashes. These symbols are separated
by the letter "<code class="computeroutput"><span class="identifier">X</span></code>"
- when they are concatenated so they read more easily during debugging. The
+ when they are concatenated so they read more easily during debugging (the
underscore character "<code class="computeroutput"><span class="identifier">_</span></code>"
could not be used instead of the letter "<code class="computeroutput"><span class="identifier">X</span></code>"
because if the original symbols already contained a leading or trailing
underscore, the concatenation could result in a symbol with double underscores
"<code class="computeroutput"><span class="identifier">__</span></code>" which is
- reserved by the C++ standard. The "aux" symbols are private to
- this library while the "detail" symbols can be used within Boost
- by other libraries but they are still not part of this library public API.
+ reserved by the C++ standard). The "aux" symbols are private
+ to this library while the "detail" symbols can be used within
+ Boost by other libraries but they are still not part of this library public
+ API.
</p></div>
</div>
</div>
@@ -188,7 +191,7 @@
<td align="right"><div class="copyright-footer">Copyright © 2009-2012 Lorenzo
Caminiti<p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
Modified: sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Implementation.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Implementation.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Implementation.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -1,7 +1,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
-<title>Appendix: Implementation</title>
+<title>Annex: Implementation</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
@@ -24,16 +24,8 @@
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
-<a name="boost_localfunction.Implementation"></a><a class="link" href="Implementation.html" title="Appendix: Implementation">Appendix: Implementation</a>
+<a name="boost_localfunction.Implementation"></a><a class="link" href="Implementation.html" title="Annex: Implementation">Annex: Implementation</a>
</h2></div></div></div>
-<div class="toc"><dl>
-<dt><span class="section"><a href="Implementation.html#boost_localfunction.Implementation.local_classes_as_template_parameters">Local
- Classes as Template Parameters</a></span></dt>
-<dt><span class="section"><a href="Implementation.html#boost_localfunction.Implementation.parsing_macros">Parsing
- Macros</a></span></dt>
-<dt><span class="section"><a href="Implementation.html#boost_localfunction.Implementation.local_functions">Local
- Functions</a></span></dt>
-</dl></div>
<p>
This section gives an overview of the key programming techniques used to implement
this library.
@@ -45,42 +37,46 @@
</tr>
<tr><td align="left" valign="top"><p>
The code listed here can be used by curious readers and library maintainers
- as a reference in trying to understand this library source files. There is
+ as a reference in trying to understand the library source code. There is
absolutely no guarantee that the library implementation uses the exact code
listed here.
</p></td></tr>
</table></div>
-<div class="section">
-<div class="titlepage"><div><div><h3 class="title">
-<a name="boost_localfunction.Implementation.local_classes_as_template_parameters"></a><a class="link" href="Implementation.html#boost_localfunction.Implementation.local_classes_as_template_parameters" title="Local Classes as Template Parameters">Local
+<h6>
+<a name="boost_localfunction.Implementation.h0"></a>
+ <span><a name="boost_localfunction.Implementation.local_classes_as_template_parameters"></a></span><a class="link" href="Implementation.html#boost_localfunction.Implementation.local_classes_as_template_parameters">Local
Classes as Template Parameters</a>
-</h3></div></div></div>
+ </h6>
<p>
- This library uses a local class to implement the local function object. However,
- in C++03
- local classes (and therefore the local function objects they implement) cannot
- be passed as template parameters (e.g., to the <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code>
- algorithm), this is instead possible on C++11,
- MSVC, and some other compilers (see [N2657]).
- To work around this limitation, this library investigated the following two
- "tricks" (both tricks can be extended to support eventual function
- default parameters):
- </p>
+ This library uses a local class to implement the local function object. However,
+ in C++03
+ local classes (and therefore the local function objects they implement) cannot
+ be passed as template parameters (e.g., to the <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code>
+ algorithm), this is instead possible on C++11,
+ MSVC, and some other compilers (see [N2657]).
+ To work around this limitation, this library investigated the following two
+ "tricks" (both tricks can be extended to support eventual function
+ default parameters):
+ </p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
- The <span class="emphasis"><em>casting functor trick</em></span> uses a non-local functor
- that calls a static member function of the local class via a function
- pointer. The static member function then calls the correct local function
- body after type casting the object from a <code class="computeroutput"><span class="keyword">void</span><span class="special">*</span></code> pointer (local classes can always be
- used for type casting).
- </li>
+ The <span class="emphasis"><em>casting functor trick</em></span> uses a non-local functor
+ that calls a static member function of the local class via a function pointer.
+ The static member function then calls the correct local function body after
+ type casting the object from a <code class="computeroutput"><span class="keyword">void</span><span class="special">*</span></code> pointer (local classes can always be used
+ for type casting).
+ </li>
<li class="listitem">
- The <span class="emphasis"><em>virtual functor trick</em></span> derives the local functor
- class from a non-local base class. The correct overridden implementation
- of the virtual <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code> is then called via polymorphism.
- </li>
+ The <span class="emphasis"><em>virtual functor trick</em></span> derives the local functor
+ class from a non-local base class. The correct overridden implementation
+ of the virtual <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code>
+ is then called via polymorphism.
+ </li>
</ol></div>
<p>
+ For example (see also impl_tparam_tricks.cpp
):
+ </p>
+<p>
</p>
<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">ExampleTparamTricks</span>
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
@@ -146,43 +142,42 @@
<span class="special">}</span>
</pre>
<p>
- </p>
+ </p>
<p>
- The casting functor trick measured slightly better run-time performances
- than the virtual functor trick so the current implementation of this library
- uses the casting functor trick (probably because in addition to the indirect
- function call, the virtual functor trick also requires accessing the <a href="http://en.wikipedia.org/wiki/Virtual_method_table" target="_top">virtual function
- table</a>). However, neither one of tricks has been observed to allow
- for compiler optimizations that inline the local function calls because they
- rely on one indirect function call (via either a function pointer or a virtual
- function respectively). Therefore, on compilers that accept local types as
- template parameters (MSVC, C++11,
- etc, see [N2657]),
- this library automatically generates code that passes the local class type
- directly as template parameter without using neither one of these two tricks
- in order to take full advantage of compiler optimizations that inline the
- local function calls.
- </p>
-</div>
-<div class="section">
-<div class="titlepage"><div><div><h3 class="title">
-<a name="boost_localfunction.Implementation.parsing_macros"></a><a class="link" href="Implementation.html#boost_localfunction.Implementation.parsing_macros" title="Parsing Macros">Parsing
+ The casting functor trick measured slightly better run-time performances than
+ the virtual functor trick so the current implementation of this library uses
+ the casting functor trick (probably because in addition to the indirect function
+ call, the virtual functor trick also requires accessing the <a href="http://en.wikipedia.org/wiki/Virtual_method_table" target="_top">virtual
+ function table</a>). However, neither one of tricks has been observed to
+ allow for compiler optimizations that inline the local function calls (because
+ they rely on one indirect function call via either a function pointer or a
+ virtual function respectively). Therefore, on compilers that accept local types
+ as template parameters (MSVC, C++11,
+ etc, see [N2657]),
+ this library automatically generates code that passes the local class type
+ directly as template parameter without using neither one of these two tricks
+ in order to take full advantage of compiler optimizations that inline the local
+ function calls.
+ </p>
+<h6>
+<a name="boost_localfunction.Implementation.h1"></a>
+ <span><a name="boost_localfunction.Implementation.parsing_macros"></a></span><a class="link" href="Implementation.html#boost_localfunction.Implementation.parsing_macros">Parsing
Macros</a>
-</h3></div></div></div>
+ </h6>
<p>
- This library macros can parse the list of specified parameters and detect
- if any of the bound parameter name matches the token <code class="computeroutput"><span class="identifier">this_</span></code>
- (to generate special code to bind the object in scope), or if the parameter
- is bound by <code class="computeroutput"><span class="keyword">const</span></code> (to generate
- special code to bind by constant), etc. The parameter tokens are inspected
- using preprocessor metaprogramming, specifically using the macros from <code class="computeroutput"><span class="string">"boost/local_function/detail/preprocessor/keyword/"</span></code>.
- <sup>[<a name="boost_localfunction.Implementation.parsing_macros.f0" href="#ftn.boost_localfunction.Implementation.parsing_macros.f0" class="footnote">24</a>]</sup>
- </p>
+ This library macros can parse the list of specified parameters and detect if
+ any of the bound variable names matches the token <code class="computeroutput"><span class="identifier">this_</span></code>
+ (to generate special code to bind the object in scope), or if the variable
+ is bound by <code class="computeroutput"><span class="keyword">const</span></code> (to generate
+ special code to bind by constant), etc. The parameter tokens are inspected
+ using preprocessor metaprogramming, specifically using the macros from <code class="computeroutput"><span class="string">"boost/local_function/detail/preprocessor/keyword/"</span></code>.
+ <sup>[<a name="boost_localfunction.Implementation.f0" href="#ftn.boost_localfunction.Implementation.f0" class="footnote">29</a>]</sup>
+ </p>
<p>
- For example, the following code defines a macro that allows the preprocessor
- to detect if a set of space-separated tokens end with <code class="computeroutput"><span class="identifier">this_</span></code>
- or not:
- </p>
+ For example, the following code defines a macro that allows the preprocessor
+ to detect if a set of space-separated tokens ends with <code class="computeroutput"><span class="identifier">this_</span></code>
+ or not:
+ </p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local_function</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">preprocessor</span><span class="special">/</span><span class="identifier">keyword</span><span class="special">/</span><span class="identifier">thisunderscore</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
@@ -205,16 +200,15 @@
<span class="special">}</span>
</pre>
<p>
- </p>
-</div>
-<div class="section">
-<div class="titlepage"><div><div><h3 class="title">
-<a name="boost_localfunction.Implementation.local_functions"></a><a class="link" href="Implementation.html#boost_localfunction.Implementation.local_functions" title="Local Functions">Local
+ </p>
+<h6>
+<a name="boost_localfunction.Implementation.h2"></a>
+ <span><a name="boost_localfunction.Implementation.local_functions"></a></span><a class="link" href="Implementation.html#boost_localfunction.Implementation.local_functions">Local
Functions</a>
-</h3></div></div></div>
+ </h6>
<p>
- The local function macros expand to code equivalent to the following:
- </p>
+ The local function macros expand to code equivalent to the following:
+ </p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local</span><span class="special">/</span><span class="identifier">function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
@@ -394,15 +388,14 @@
<span class="special">}</span>
</pre>
<p>
- </p>
-</div>
+ </p>
<div class="footnotes">
<br><hr width="100" align="left">
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Implementation.parsing_macros.f0" href="#boost_localfunction.Implementation.parsing_macros.f0" class="para">24</a>] </sup>
- This technique is at the core of even more complex preprocessor parsing
- macros like the ones that parse the Contract++
- syntax.
- </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Implementation.f0" href="#boost_localfunction.Implementation.f0" class="para">29</a>] </sup>
+ This technique is at the core of even more complex preprocessor parsing macros
+ like the ones that parse the Contract++
+ syntax.
+ </p></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
@@ -410,7 +403,7 @@
<td align="right"><div class="copyright-footer">Copyright © 2009-2012 Lorenzo
Caminiti<p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
Modified: sandbox/local_function/libs/local_function/doc/html/boost_localfunction/No_Variadic_Macros.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/boost_localfunction/No_Variadic_Macros.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/boost_localfunction/No_Variadic_Macros.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -6,8 +6,8 @@
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
<link rel="up" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
-<link rel="prev" href="Alternatives.html" title="Appendix: Alternatives">
-<link rel="next" href="Implementation.html" title="Appendix: Implementation">
+<link rel="prev" href="Alternatives.html" title="Annex: Alternatives">
+<link rel="next" href="Implementation.html" title="Annex: Implementation">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
@@ -27,41 +27,34 @@
<a name="boost_localfunction.No_Variadic_Macros"></a><a class="link" href="No_Variadic_Macros.html" title="Annex: No Variadic Macros">Annex: No Variadic
Macros</a>
</h2></div></div></div>
-<div class="toc"><dl>
-<dt><span class="section"><a href="No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.sequence_syntax">Sequence
- Syntax</a></span></dt>
-<dt><span class="section"><a href="No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.an_example">An
- Example</a></span></dt>
-</dl></div>
<p>
This section illustrates an alternative syntax for compilers without variadic
macro support.
</p>
-<div class="section">
-<div class="titlepage"><div><div><h3 class="title">
-<a name="boost_localfunction.No_Variadic_Macros.sequence_syntax"></a><a class="link" href="No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.sequence_syntax" title="Sequence Syntax">Sequence
- Syntax</a>
-</h3></div></div></div>
-<p>
- Most modern compilers support <a href="http://en.wikipedia.org/wiki/Variadic_macro" target="_top">variaid
- macros</a> (notably, these include GCC, MSVC, and all C++11
- compilers). However, in the rare case that programmers need to use this library
- on a compiler without variadic macros, this library also allows to specify
- its macro parameters using a Boost.Preprocessor
- sequence where tokens are separated by round parenthesis <code class="computeroutput"><span class="special">()</span></code>:
- </p>
+<h6>
+<a name="boost_localfunction.No_Variadic_Macros.h0"></a>
+ <span><a name="boost_localfunction.No_Variadic_Macros.sequence_syntax"></a></span><a class="link" href="No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.sequence_syntax">Sequence Syntax</a>
+ </h6>
+<p>
+ Most modern compilers support <a href="http://en.wikipedia.org/wiki/Variadic_macro" target="_top">variaid
+ macros</a> (notably, these include GCC, MSVC, and all C++11
+ compilers). However, in the rare case that programmers need to use this library
+ on a compiler without variadic macros, this library also allows to specify
+ its macro parameters using a Boost.Preprocessor
+ sequence where tokens are separated by round parenthesis <code class="computeroutput"><span class="special">()</span></code>:
+ </p>
<pre class="programlisting"><span class="special">(</span><span class="identifier">token1</span><span class="special">)</span> <span class="special">(</span><span class="identifier">token2</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// All compilers.</span>
</pre>
<p>
- Instead of the comma-separated list that we have seen so far which requires
- variadic macros:
- </p>
+ Instead of the comma-separated list that we have seen so far which requires
+ variadic macros:
+ </p>
<pre class="programlisting"><span class="identifier">token1</span><span class="special">,</span> <span class="identifier">token2</span><span class="special">,</span> <span class="special">...</span> <span class="comment">// Only compilers with varidic macros.</span>
</pre>
<p>
- For example, the following syntax is accepted on all compilers with and without
- variadic macros (see also "add_seq.cpp"
):
- </p>
+ For example, the following syntax is accepted on all compilers with and without
+ variadic macros (see also "add_seq.cpp"
):
+ </p>
<p>
</p>
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
@@ -76,45 +69,44 @@
<span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
</pre>
<p>
- </p>
+ </p>
<p>
- However, on compilers with variadic macros the comma-separated syntax we
- have seen so far is preferred because more readable (see also "add.cpp"
):
- </p>
+ However, on compilers with variadic macros the comma-separated syntax we have
+ seen so far is preferred because more readable (see also "add.cpp"
):
+ </p>
<p>
</p>
-<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
- <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
+<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
+ <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&</span> <span class="identifier">sum</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
- <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the local function (with one parameter `num`).</span>
+ <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the local function.</span>
<span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
- <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
<span class="special">}</span>
</pre>
<p>
- </p>
+ </p>
<p>
- Note how the same macros accept both syntaxes on compilers with variadic
- macros and only the sequence syntax on compilers without variadic macros.
- Finally, an empty list is always specified using <code class="computeroutput"><span class="keyword">void</span></code>
- on compilers with and without variadic macros.
- </p>
-</div>
-<div class="section">
-<div class="titlepage"><div><div><h3 class="title">
-<a name="boost_localfunction.No_Variadic_Macros.an_example"></a><a class="link" href="No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.an_example" title="An Example">An
+ Note how the same macros accept both syntaxes on compilers with variadic macros
+ and only the sequence syntax on compilers without variadic macros. Finally,
+ an empty list is always specified using <code class="computeroutput"><span class="keyword">void</span></code>
+ on compilers with and without variadic macros.
+ </p>
+<h6>
+<a name="boost_localfunction.No_Variadic_Macros.h1"></a>
+ <span><a name="boost_localfunction.No_Variadic_Macros.an_example"></a></span><a class="link" href="No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.an_example">An
Example</a>
-</h3></div></div></div>
+ </h6>
<p>
- The following is an example that shows a bit of all the different macro parameter
- combinations using the sequence syntax (see also "seq.cpp"
):
- </p>
+ The following is an example that shows a bit of all the different macro parameter
+ combinations using the sequence syntax (see also "seq.cpp"
):
+ </p>
<p>
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">s</span> <span class="special">{</span>
@@ -268,15 +260,14 @@
<span class="special">};</span>
</pre>
<p>
- </p>
-</div>
+ </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2009-2012 Lorenzo
Caminiti<p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
Modified: sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Release_Notes.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Release_Notes.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Release_Notes.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -6,7 +6,7 @@
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
<link rel="up" href="../index.html" title="Chapter 1. Boost.LocalFunction 1.0.0">
-<link rel="prev" href="Implementation.html" title="Appendix: Implementation">
+<link rel="prev" href="Implementation.html" title="Annex: Implementation">
<link rel="next" href="Bibliography.html" title="Bibliography">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -32,6 +32,14 @@
</p>
<h6>
<a name="boost_localfunction.Release_Notes.h0"></a>
+ <span><a name="boost_localfunction.Release_Notes.version_1_0_0__2012_01_31_"></a></span><a class="link" href="Release_Notes.html#boost_localfunction.Release_Notes.version_1_0_0__2012_01_31_">Version
+ 1.0.0 (2012-01-31)</a>
+ </h6>
+<p>
+ @todo do this
+ </p>
+<h6>
+<a name="boost_localfunction.Release_Notes.h1"></a>
<span><a name="boost_localfunction.Release_Notes.version_0_2_0__2011_05_14_"></a></span><a class="link" href="Release_Notes.html#boost_localfunction.Release_Notes.version_0_2_0__2011_05_14_">Version
0.2.0 (2011-05-14)</a>
</h6>
@@ -72,7 +80,7 @@
</li>
</ol></div>
<h6>
-<a name="boost_localfunction.Release_Notes.h1"></a>
+<a name="boost_localfunction.Release_Notes.h2"></a>
<span><a name="boost_localfunction.Release_Notes.version_0_1_1__2011_01_10_"></a></span><a class="link" href="Release_Notes.html#boost_localfunction.Release_Notes.version_0_1_1__2011_01_10_">Version
0.1.1 (2011-01-10)</a>
</h6>
@@ -88,7 +96,7 @@
</li>
</ol></div>
<h6>
-<a name="boost_localfunction.Release_Notes.h2"></a>
+<a name="boost_localfunction.Release_Notes.h3"></a>
<span><a name="boost_localfunction.Release_Notes.version_0_1_0__2011_01_03_"></a></span><a class="link" href="Release_Notes.html#boost_localfunction.Release_Notes.version_0_1_0__2011_01_03_">Version
0.1.0 (2011-01-03)</a>
</h6>
@@ -96,7 +104,7 @@
Shared with Boost for first round of comments.
</li></ol></div>
<h6>
-<a name="boost_localfunction.Release_Notes.h3"></a>
+<a name="boost_localfunction.Release_Notes.h4"></a>
<span><a name="boost_localfunction.Release_Notes.version_0_0_1__2010_12_15_"></a></span><a class="link" href="Release_Notes.html#boost_localfunction.Release_Notes.version_0_0_1__2010_12_15_">Version
0.0.1 (2010-12-15)</a>
</h6>
@@ -109,7 +117,7 @@
<td align="right"><div class="copyright-footer">Copyright © 2009-2012 Lorenzo
Caminiti<p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
Modified: sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Tutorial.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Tutorial.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/boost_localfunction/Tutorial.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -41,12 +41,12 @@
<a name="boost_localfunction.Tutorial.local_functions"></a><a class="link" href="Tutorial.html#boost_localfunction.Tutorial.local_functions" title="Local Functions">Local Functions</a>
</h3></div></div></div>
<p>
- Local functions are defined using macros from the header file <code class="computeroutput">boost/local_function.hpp</code>. The
+ Local functions are defined using macros from the header file <code class="computeroutput"><a class="link" href="../reference.html#header.boost.local_function_hpp" title="Header <boost/local_function.hpp>">boost/local_function.hpp</a></code>. The
macros must be used from within a declarative context (this is a limitation
with respect to <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
lambda</a> functions which can instead be declared within expressions):
</p>
-<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> <span class="comment">// Include library header.</span>
<span class="special">...</span>
<span class="special">{</span> <span class="comment">// Some declarative context.</span>
@@ -59,8 +59,8 @@
</pre>
<p>
The code expanded by the macros declares a function object (or functor)
- with the local function name specified by <code class="computeroutput">BOOST_LOCAL_FUNCTION_NAME</code>.
- <sup>[<a name="boost_localfunction.Tutorial.local_functions.f0" href="#ftn.boost_localfunction.Tutorial.local_functions.f0" class="footnote">3</a>]</sup> The usual C++ scope visibility rules apply to local functions
+ with the local function name specified by <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_NAME.html" title="Macro BOOST_LOCAL_FUNCTION_NAME">BOOST_LOCAL_FUNCTION_NAME</a></code>.
+ <sup>[<a name="boost_localfunction.Tutorial.local_functions.f0" href="#ftn.boost_localfunction.Tutorial.local_functions.f0" class="footnote">5</a>]</sup> The usual C++ scope visibility rules apply to local functions
for which a local function is visible only within the enclosing scope in
which it is declared.
</p>
@@ -69,23 +69,22 @@
<span class="special">...</span> <span class="special">}</span></code>
using the usual C++ syntax. The body is specified outside any of the macros
so eventual compiler error messages and related line numbers retain their
- usual meaning and format. <sup>[<a name="boost_localfunction.Tutorial.local_functions.f1" href="#ftn.boost_localfunction.Tutorial.local_functions.f1" class="footnote">4</a>]</sup>
+ usual meaning and format. <sup>[<a name="boost_localfunction.Tutorial.local_functions.f1" href="#ftn.boost_localfunction.Tutorial.local_functions.f1" class="footnote">6</a>]</sup>
</p>
<p>
- The local function parameters are passed to the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
- macro as a comma-separated list of tokens (see the <a class="link" href="../">No
+ The local function parameters are passed to the <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION.html" title="Macro BOOST_LOCAL_FUNCTION">BOOST_LOCAL_FUNCTION</a></code>
+ macro as a comma-separated list of tokens (see the <a class="link" href="No_Variadic_Macros.html" title="Annex: No Variadic Macros">No
Variadic Macros</a> section for compilers that do not support variadic
macros):
</p>
<pre class="programlisting"><span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><code class="literal"><span class="emphasis"><em>parameter-type1 parameter-name1</em></span></code><span class="special">,</span> <code class="literal"><span class="emphasis"><em>parameter-type2 parameter-name2, ...</em></span></code><span class="special">)</span>
</pre>
<p>
- The maximum number of parameters that can be passed to a local function (excluding
- eventual bound variables) is controlled at compile-time by the configuration
- macro <code class="computeroutput">BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX</code>.
+ The maximum number of parameters that can be passed to a local function is
+ controlled at compile-time by the configuration macro <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX.html" title="Macro BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX">BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX</a></code>.
For example, let's program a local function named <code class="computeroutput"><span class="identifier">add</span></code>
that adds together two integers <code class="computeroutput"><span class="identifier">x</span></code>
- and <code class="computeroutput"><span class="identifier">y</span></code> (see also "add_nobind.cpp"
):
+ and <code class="computeroutput"><span class="identifier">y</span></code> (see also add_params.cpp
):
</p>
<p>
</p>
@@ -98,15 +97,15 @@
<p>
</p>
<p>
- If the local function has no parameter, it is possible to pass <code class="computeroutput"><span class="keyword">void</span></code> to the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
+ If the local function has no parameter, it is possible to pass <code class="computeroutput"><span class="keyword">void</span></code> to the <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION.html" title="Macro BOOST_LOCAL_FUNCTION">BOOST_LOCAL_FUNCTION</a></code>
macro (similarly to the C syntax that allows to use <code class="computeroutput"><span class="keyword">int</span>
- <span class="identifier">f</span><span class="special">(</span><span class="keyword">void</span><span class="special">)</span></code> for
- a function with no parameter): <sup>[<a name="boost_localfunction.Tutorial.local_functions.f2" href="#ftn.boost_localfunction.Tutorial.local_functions.f2" class="footnote">5</a>]</sup>
+ <span class="identifier">f</span><span class="special">(</span><span class="keyword">void</span><span class="special">)</span></code> to declare
+ a function with no parameter): <sup>[<a name="boost_localfunction.Tutorial.local_functions.f2" href="#ftn.boost_localfunction.Tutorial.local_functions.f2" class="footnote">7</a>]</sup>
</p>
<pre class="programlisting"><span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">void</span><span class="special">)</span> <span class="comment">// No parameter.</span>
</pre>
<p>
- For example, let's program a local function that always returns <code class="computeroutput"><span class="number">10</span></code> (see also "ten.cpp"
):
+ For example, let's program a local function that always returns <code class="computeroutput"><span class="number">10</span></code> (see also ten_void.cpp
):
</p>
<p>
</p>
@@ -130,7 +129,7 @@
from the enclosing scope are accessible from within the local function body.
The types of bound variables are automatically deduced by this library using
<a href="http://www.boost.org/doc/libs/release/doc/html/typeof.html" target="_top">Boost.Typeof</a>.
- <sup>[<a name="boost_localfunction.Tutorial.Binding.f0" href="#ftn.boost_localfunction.Tutorial.Binding.f0" class="footnote">6</a>]</sup>
+ <sup>[<a name="boost_localfunction.Tutorial.Binding.f0" href="#ftn.boost_localfunction.Tutorial.Binding.f0" class="footnote">8</a>]</sup>
</p>
<div class="important"><table border="0" summary="Important">
<tr>
@@ -139,9 +138,9 @@
</tr>
<tr><td align="left" valign="top"><p>
The library implementation uses Boost.Typeof
- to automatically deduce the types of the bound variables. In order to compile
- code in type-of emulation mode, all types should be properly registered
- with <code class="computeroutput"><span class="identifier">BOOST_TYPEOF_REGISTER_TYPE</span></code>
+ to automatically deduce the types of the bound variables. Therefore, in
+ order to compile code in type-of emulation mode, all types should be properly
+ registered with <code class="computeroutput"><span class="identifier">BOOST_TYPEOF_REGISTER_TYPE</span></code>
or <code class="computeroutput"><span class="identifier">BOOST_TYPEOF_REGISTER_TEMPLATE</span></code>
macros, or appropriate Boost.Typeof
headers should be included (see the Boost.Typeof
@@ -150,7 +149,7 @@
</table></div>
<p>
This library introduces the new "keyword" <code class="computeroutput"><span class="identifier">bind</span></code>
- <sup>[<a name="boost_localfunction.Tutorial.Binding.f1" href="#ftn.boost_localfunction.Tutorial.Binding.f1" class="footnote">7</a>]</sup> which is used in place of the parameter type to specify the name
+ <sup>[<a name="boost_localfunction.Tutorial.Binding.f1" href="#ftn.boost_localfunction.Tutorial.Binding.f1" class="footnote">9</a>]</sup> which is used in place of the parameter type to specify the name
of a variable in scope to bind (therefore, <code class="computeroutput"><span class="identifier">bind</span></code>
cannot be used as a local function parameter type). A variable can be bound
by value:
@@ -177,7 +176,7 @@
<p>
Note that when <code class="computeroutput"><span class="keyword">const</span></code> is used,
it must always precede <code class="computeroutput"><span class="identifier">bind</span></code>.
- <sup>[<a name="boost_localfunction.Tutorial.Binding.f2" href="#ftn.boost_localfunction.Tutorial.Binding.f2" class="footnote">8</a>]</sup>
+ <sup>[<a name="boost_localfunction.Tutorial.Binding.f2" href="#ftn.boost_localfunction.Tutorial.Binding.f2" class="footnote">10</a>]</sup>
</p>
<p>
If a variable is bound by value, then a copy of the variable value is taken
@@ -197,50 +196,52 @@
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
If a bound variable was declared constant in the enclosing scope, it
- will be always bound by constant value or constant reference even if
- <code class="computeroutput"><span class="identifier">bind</span></code> is used instead
- of <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span></code>
+ will always be bound by constant value or constant reference even if
+ <code class="computeroutput"><span class="identifier">bind</span><span class="special">...</span></code>
+ is used instead of <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">...</span></code>
. However, if a bound variable was not declared constant in the enclosing
scope then it will not be bound as constant unless constant binding is
- forced using <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span></code>.
- (Note that binding by constant reference is not supported by <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
- lambda</a> functions but it is supported by this library.) <sup>[<a name="boost_localfunction.Tutorial.Binding.f3" href="#ftn.boost_localfunction.Tutorial.Binding.f3" class="footnote">9</a>]</sup>
+ forced using <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">...</span></code>. (Note that binding by constant reference
+ is not supported by <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions but it is supported by this library.) <sup>[<a name="boost_localfunction.Tutorial.Binding.f3" href="#ftn.boost_localfunction.Tutorial.Binding.f3" class="footnote">11</a>]</sup>
</li>
<li class="listitem">
If a bound variable was declared as a reference in the enclosing scope,
it will still be bound by value unless it is explicitly bound by reference
using <code class="computeroutput"><span class="identifier">bind</span><span class="special">&</span></code>
- or <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&</span></code>. <sup>[<a name="boost_localfunction.Tutorial.Binding.f4" href="#ftn.boost_localfunction.Tutorial.Binding.f4" class="footnote">10</a>]</sup>
+ or <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&</span></code>. <sup>[<a name="boost_localfunction.Tutorial.Binding.f4" href="#ftn.boost_localfunction.Tutorial.Binding.f4" class="footnote">12</a>]</sup>
</li>
</ul></div>
<p>
- As with passing parameters to usual C++ functions, programmers might want
- to bind variables of complex types by (possibly constant) reference instead
- than by value to avoid expensive copy operations when these variables are
- bound to a local function.
+ When a variable is bound by value (constant or not), its type must be <code class="computeroutput"><span class="identifier">CopyConstructible</span></code> (i.e., its must provide
+ a copy constructor). As with passing parameters to usual C++ functions, programmers
+ might want to bind variables of complex types by (possibly constant) reference
+ instead than by value to avoid expensive copy operations when these variables
+ are bound to a local function.
</p>
<p>
For example, let's program the local function <code class="computeroutput"><span class="identifier">add</span></code>
- from the example in the <a class="link" href="../">Introduction</a>
+ from the example in the <a class="link" href="../index.html#boost_localfunction.Introduction" title="Introduction">Introduction</a>
section. We bind the local variable <code class="computeroutput"><span class="identifier">factor</span></code>
- by constant value, the local variable <code class="computeroutput"><span class="identifier">sum</span></code>
- by (non-constant) reference, and program the body to perform the summation
- (see also "add.cpp"
):
+ by constant value (because its value does not need to be changed), the local
+ variable <code class="computeroutput"><span class="identifier">sum</span></code> by non-constant
+ reference (because its value needs to be updated with the summation result),
+ and program the body to perform the summation (see also add.cpp
):
</p>
<p>
</p>
-<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
- <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
+<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
+ <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&</span> <span class="identifier">sum</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
- <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the local function (with one parameter `num`).</span>
+ <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the local function.</span>
<span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
- <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
<span class="special">}</span>
</pre>
<p>
@@ -255,10 +256,23 @@
It is also possible to bind the object <code class="computeroutput"><span class="keyword">this</span></code>
when it is in scope (e.g., from an enclosing non-static member function).
This is done by using the special symbol <code class="computeroutput"><span class="identifier">this_</span></code>
- <sup>[<a name="boost_localfunction.Tutorial.binding_the_object__this_.f0" href="#ftn.boost_localfunction.Tutorial.binding_the_object__this_.f0" class="footnote">11</a>]</sup> (instead of <code class="computeroutput"><span class="keyword">this</span></code>)
- <sup>[<a name="boost_localfunction.Tutorial.binding_the_object__this_.f1" href="#ftn.boost_localfunction.Tutorial.binding_the_object__this_.f1" class="footnote">12</a>]</sup> as the name of the variable to bind in the local function declaration
+ (instead of <code class="computeroutput"><span class="keyword">this</span></code>) <sup>[<a name="boost_localfunction.Tutorial.binding_the_object__this_.f0" href="#ftn.boost_localfunction.Tutorial.binding_the_object__this_.f0" class="footnote">13</a>]</sup> as the name of the variable to bind in the local function declaration
and also to access the object within the local function body.
</p>
+<div class="warning"><table border="0" summary="Warning">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../doc/src/images/warning.png"></td>
+<th align="left">Warning</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ The library will generate a compile-time error if <code class="computeroutput"><span class="keyword">this</span></code>
+ is mistakenly used instead of <code class="computeroutput"><span class="identifier">this_</span></code>
+ to bind the object in the local function declaration. However, mistakenly
+ using <code class="computeroutput"><span class="keyword">this</span></code> instead of <code class="computeroutput"><span class="identifier">this_</span></code> to access the object within the
+ local function body will leads to undefined behaviour and it will not necessarily
+ generate a compile-time error. <sup>[<a name="boost_localfunction.Tutorial.binding_the_object__this_.f1" href="#ftn.boost_localfunction.Tutorial.binding_the_object__this_.f1" class="footnote">14</a>]</sup> Programmers are ultimately responsible to make sure that <code class="computeroutput"><span class="keyword">this</span></code> is never used within a local function.
+ </p></td></tr>
+</table></div>
<p>
The object <code class="computeroutput"><span class="keyword">this</span></code> can be bound
by value:
@@ -282,32 +296,19 @@
Note that the object <code class="computeroutput"><span class="keyword">this</span></code> can
never be bound by reference because C++ does not allow to obtain a reference
to <code class="computeroutput"><span class="keyword">this</span></code> (the library will generate
- a compile-time error if programmers try to use <code class="computeroutput"><span class="identifier">bind</span><span class="special">&</span> <span class="keyword">this</span></code>
- or <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&</span> <span class="keyword">this</span></code>).
+ a compile-time error if programmers try to use <code class="computeroutput"><span class="identifier">bind</span><span class="special">&</span> <span class="identifier">this_</span></code>
+ or <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&</span> <span class="identifier">this_</span></code>).
Note that <code class="computeroutput"><span class="keyword">this</span></code> is a pointer
so the pointed object is never copied even if <code class="computeroutput"><span class="keyword">this</span></code>
is bound by value (also it is not allowed to directly bind <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> because
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
is an expression and not a valid name of a variable in scope).
</p>
-<div class="warning"><table border="0" summary="Warning">
-<tr>
-<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../doc/src/images/warning.png"></td>
-<th align="left">Warning</th>
-</tr>
-<tr><td align="left" valign="top"><p>
- Unfortunately, mistakenly using <code class="computeroutput"><span class="keyword">this</span></code>
- within the local function body instead of <code class="computeroutput"><span class="identifier">this_</span></code>
- leads to undefined behaviour and it will not necessarily generate a compile-time
- error. <sup>[<a name="boost_localfunction.Tutorial.binding_the_object__this_.f2" href="#ftn.boost_localfunction.Tutorial.binding_the_object__this_.f2" class="footnote">13</a>]</sup> Programmers are responsible to make sure that <code class="computeroutput"><span class="keyword">this</span></code> is never used within a local function
- body which should only use the special symbol <code class="computeroutput"><span class="identifier">this_</span></code>.
- </p></td></tr>
-</table></div>
<p>
For example, let's program a local function <code class="computeroutput"><span class="identifier">add</span></code>
- similar to the one in the example from the <a class="link" href="../">Introduction</a>
+ similar to the one in the example from the <a class="link" href="../index.html#boost_localfunction.Introduction" title="Introduction">Introduction</a>
section but using a member function to illustrate how to bind the object
- <code class="computeroutput"><span class="keyword">this</span></code> (see also "add_this.cpp"
):
+ <code class="computeroutput"><span class="keyword">this</span></code> (see also add_this.cpp
):
</p>
<p>
</p>
@@ -329,6 +330,13 @@
</pre>
<p>
</p>
+<p>
+ As expected, the local function has access to all class members via the bound
+ object <code class="computeroutput"><span class="identifier">this_</span></code> regardless of
+ their access level (<code class="computeroutput"><span class="keyword">public</span></code>,
+ <code class="computeroutput"><span class="keyword">protected</span></code>, or <code class="computeroutput"><span class="keyword">private</span></code>). <sup>[<a name="boost_localfunction.Tutorial.binding_the_object__this_.f2" href="#ftn.boost_localfunction.Tutorial.binding_the_object__this_.f2" class="footnote">15</a>]</sup> Specifically, in the example above the local function updates
+ the <code class="computeroutput"><span class="keyword">private</span></code> data member <code class="computeroutput"><span class="identifier">sum_</span></code>.
+ </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
@@ -336,8 +344,8 @@
</h3></div></div></div>
<p>
When local functions are programmed within templates, they need to be declared
- using the special macro <code class="computeroutput">BOOST_LOCAL_FUNCTION_TPL</code>
- (see the Reference section): <sup>[<a name="boost_localfunction.Tutorial.templates.f0" href="#ftn.boost_localfunction.Tutorial.templates.f0" class="footnote">14</a>]</sup>
+ using the special macro <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_TPL.html" title="Macro BOOST_LOCAL_FUNCTION_TPL">BOOST_LOCAL_FUNCTION_TPL</a></code>
+ (see the Reference section): <sup>[<a name="boost_localfunction.Tutorial.templates.f0" href="#ftn.boost_localfunction.Tutorial.templates.f0" class="footnote">16</a>]</sup>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
@@ -351,14 +359,14 @@
<span class="special">}</span>
</pre>
<p>
- The <code class="computeroutput">BOOST_LOCAL_FUNCTION_TPL</code>
- macro has the exact same syntax of the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
+ The <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_TPL.html" title="Macro BOOST_LOCAL_FUNCTION_TPL">BOOST_LOCAL_FUNCTION_TPL</a></code>
+ macro has the exact same syntax of the <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION.html" title="Macro BOOST_LOCAL_FUNCTION">BOOST_LOCAL_FUNCTION</a></code>
macro that we have seen so far.
</p>
<p>
- For example, let's rewrite a local function similar to the one from the
- <a class="link" href="../">Introduction</a> section but
- wrapped within a template:
+ For example, let's program a local function similar to the one from the
+ <a class="link" href="../index.html#boost_localfunction.Introduction" title="Introduction">Introduction</a> section
+ but wrapped within a template (see also add_template.cpp
):
</p>
<p>
</p>
@@ -384,20 +392,23 @@
</div>
<div class="footnotes">
<br><hr width="100" align="left">
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.local_functions.f0" href="#boost_localfunction.Tutorial.local_functions.f0" class="para">3</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.local_functions.f0" href="#boost_localfunction.Tutorial.local_functions.f0" class="para">5</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> The local function name must
- be passed to the macro <code class="computeroutput">BOOST_LOCAL_FUNCTION_NAME</code>
+ be passed to the macro <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_NAME.html" title="Macro BOOST_LOCAL_FUNCTION_NAME">BOOST_LOCAL_FUNCTION_NAME</a></code>
ending the function definition so this macro can declare a local variable
- with the local function name to hold the local function object.
+ with the local function name to hold the local function object. Therefore
+ the local function name cannot be specified within the <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION.html" title="Macro BOOST_LOCAL_FUNCTION">BOOST_LOCAL_FUNCTION</a></code>
+ and it must appear instead after the local function body (even if that
+ differs from the usual C++ function declaration syntax).
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.local_functions.f1" href="#boost_localfunction.Tutorial.local_functions.f1" class="para">4</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.local_functions.f1" href="#boost_localfunction.Tutorial.local_functions.f1" class="para">6</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> If the local function body
were instead passed as a macro parameter, it would be expanded on a single
line of code (because macros always expand as a single line of code). Therefore,
eventual compiler error line numbers would all report the same value and
- would no longer be useful to pinpoint the error.
+ would no longer be useful to pinpoint errors.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.local_functions.f2" href="#boost_localfunction.Tutorial.local_functions.f2" class="para">5</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.local_functions.f2" href="#boost_localfunction.Tutorial.local_functions.f2" class="para">7</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> The C++03
standard does not allow pass empty parameters to a macro so the macro cannot
be invoked as <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">()</span></code>. On C99
@@ -405,7 +416,7 @@
be possible to allow <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">()</span></code> but this is already not the case for
MSVC so this syntax is never allowed to ensure better portability.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f0" href="#boost_localfunction.Tutorial.Binding.f0" class="para">6</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f0" href="#boost_localfunction.Tutorial.Binding.f0" class="para">8</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> By binding a variable in scope,
the local function declaration is specifying that such a variable should
be accessible within the local function body regardless of its type. Semantically,
@@ -415,19 +426,19 @@
the semantic of binding a variable does not depend on the variable type
but just on the variable name: "The variable in scope named <span class="emphasis"><em>x</em></span>
should be accessible within the local function named <span class="emphasis"><em>f</em></span>".
- For example, this is useful for maintenance because if a bound variable
- type is changed, the local function declaration does not have to change.
+ For example, this reduces maintenance because if a bound variable type
+ is changed, the local function declaration does not have to change.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f1" href="#boost_localfunction.Tutorial.Binding.f1" class="para">7</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f1" href="#boost_localfunction.Tutorial.Binding.f1" class="para">9</a>] </sup>
Obviously, the token <code class="computeroutput"><span class="identifier">bind</span></code>
is not a keyword of the C++ language. This library parses the token <code class="computeroutput"><span class="identifier">bind</span></code> during macro expansion using preprocessor
- metaprogramming (see the <a class="link" href="../">Implementation</a>
+ metaprogramming (see the <a class="link" href="Implementation.html" title="Annex: Implementation">Implementation</a>
section). Therefore, <code class="computeroutput"><span class="identifier">bind</span></code>
can be considered a new "keyword" only at the preprocessor metaprogramming
- level within the syntax defined by the macros of this library- thus it
- is referred to as a "keyword" only within quotes.
+ level within the syntax defined by the macros of this library (thus it
+ is referred to as a "keyword" only within quotes).
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f2" href="#boost_localfunction.Tutorial.Binding.f2" class="para">8</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f2" href="#boost_localfunction.Tutorial.Binding.f2" class="para">10</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> The library macros could have
been implemented to accept both syntaxes <code class="computeroutput"><span class="keyword">const</span>
<span class="identifier">bind</span> <span class="special">...</span></code>
@@ -438,7 +449,7 @@
<span class="identifier">bind</span> <span class="special">...</span></code>)
is supported.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f3" href="#boost_localfunction.Tutorial.Binding.f3" class="para">9</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f3" href="#boost_localfunction.Tutorial.Binding.f3" class="para">11</a>] </sup>
An historical note: Constant binding of variables in scope was the
main use case that originally motivated the authors in developing this
library. The authors needed to locally create a chuck of code to assert
@@ -450,9 +461,10 @@
(for example confusing the operator <code class="computeroutput"><span class="special">==</span></code>
with <code class="computeroutput"><span class="special">=</span></code>), the compiler
correctly generates an error because the bound variable is of <code class="computeroutput"><span class="keyword">const</span></code> type within the local function
- body.
+ body (see also <span class="emphasis"><em>constant blocks</em></span> in the <a class="link" href="Examples.html" title="Examples">Examples</a>
+ section).
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f4" href="#boost_localfunction.Tutorial.Binding.f4" class="para">10</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f4" href="#boost_localfunction.Tutorial.Binding.f4" class="para">12</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> Variables originally declared
as references are bound by value unless <code class="computeroutput"><span class="special">[</span><span class="keyword">const</span><span class="special">]</span> <span class="identifier">bind</span><span class="special">&</span></code>
is used so that references can be bound by both value <code class="computeroutput"><span class="special">[</span><span class="keyword">const</span><span class="special">]</span> <span class="identifier">bind</span></code>
@@ -465,18 +477,15 @@
even if <code class="computeroutput"><span class="identifier">bind</span><span class="special">[&]</span></code>
is used instead of <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">[&]</span></code>.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.binding_the_object__this_.f0" href="#boost_localfunction.Tutorial.binding_the_object__this_.f0" class="para">11</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.binding_the_object__this_.f0" href="#boost_localfunction.Tutorial.binding_the_object__this_.f0" class="para">13</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> The special name <code class="computeroutput"><span class="identifier">this_</span></code> was chosen following <a href="http://boost.2283326.n4.nabble.com/local-this-or-this-td3423912.html" target="_top">Boost
practises</a> which postfix with an underscore identifiers that are
named after keywords (the C++ keyword <code class="computeroutput"><span class="keyword">this</span></code>
- in this case).
- </p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.binding_the_object__this_.f1" href="#boost_localfunction.Tutorial.binding_the_object__this_.f1" class="para">12</a>] </sup>
- <span class="bold"><strong>Rationale.</strong></span> This limitation comes from
- the fact that <code class="computeroutput"><span class="keyword">this</span></code> is a reserved
- C++ keyword so it cannot be used as the name of the internal parameter
- that passes the bound object to the local function body. It would have
- been possible to use <code class="computeroutput"><span class="keyword">this</span></code>
+ in this case). The special symbol <code class="computeroutput"><span class="identifier">this_</span></code>
+ is needed because <code class="computeroutput"><span class="keyword">this</span></code> is
+ a reserved C++ keyword so it cannot be used as the name of the internal
+ parameter that passes the bound object to the local function body. It would
+ have been possible to use <code class="computeroutput"><span class="keyword">this</span></code>
(instead of <code class="computeroutput"><span class="identifier">this_</span></code>) within
the local function body either at the expenses of copying the bound object
(which would introduce run-time overhead and also the stringent requirement
@@ -485,20 +494,26 @@
behaviour of <code class="computeroutput"><span class="keyword">static_cast</span></code></a>
(which might not work on all platforms at the cost of portability).
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.binding_the_object__this_.f2" href="#boost_localfunction.Tutorial.binding_the_object__this_.f2" class="para">13</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.binding_the_object__this_.f1" href="#boost_localfunction.Tutorial.binding_the_object__this_.f1" class="para">14</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> The local function body cannot
be a static member function of the local functor object in order to support
- recursion (because the local function name is specified by the <code class="computeroutput">BOOST_LOCAL_FUNCTION_NAME</code>
+ recursion (because the local function name is specified by the <code class="computeroutput"><a class="link" href="../BOOST_LOCAL_FUNCTION_NAME.html" title="Macro BOOST_LOCAL_FUNCTION_NAME">BOOST_LOCAL_FUNCTION_NAME</a></code>
macro only after the body so it must be made available via a functor
member variable named after the local function and local classes cannot
have static member variables in C++) and nesting (because the argument
binding variable must be declared as a member variable so it is visible
in a local function nested within the body member function) -- see the
- <a class="link" href="../">Implementation</a> section.
- Therefore, from within the local function body the variable <code class="computeroutput"><span class="keyword">this</span></code> is visible but it refers to the local
- functor and not to the bound object.
+ <a class="link" href="Implementation.html" title="Annex: Implementation">Implementation</a>
+ section. Therefore, from within the local function body the variable
+ <code class="computeroutput"><span class="keyword">this</span></code> is visible but it refers
+ to the local functor and not to the bound object.
</p></div>
-<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.templates.f0" href="#boost_localfunction.Tutorial.templates.f0" class="para">14</a>] </sup>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.binding_the_object__this_.f2" href="#boost_localfunction.Tutorial.binding_the_object__this_.f2" class="para">15</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> This is possible because of
+ C++ defect fix #46 that made inner and local types able to access all outer
+ class members regardless of their access level.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.templates.f0" href="#boost_localfunction.Tutorial.templates.f0" class="para">16</a>] </sup>
<span class="bold"><strong>Rationale.</strong></span> Within templates, this library
needs to use <code class="computeroutput"><span class="keyword">typename</span></code> to explicitly
indicate that some expressions evaluate to a type. Because C++03
@@ -515,7 +530,7 @@
<td align="right"><div class="copyright-footer">Copyright © 2009-2012 Lorenzo
Caminiti<p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
Modified: sandbox/local_function/libs/local_function/doc/html/index.html
==============================================================================
--- sandbox/local_function/libs/local_function/doc/html/index.html (original)
+++ sandbox/local_function/libs/local_function/doc/html/index.html 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -21,16 +21,16 @@
<div class="chapter">
<div class="titlepage"><div>
<div><h2 class="title">
-<a name="local_function"></a>Chapter 1. Boost.LocalFunction 1.0.0 </h2></div>
+<a name="boost_localfunction"></a>Chapter 1. Boost.LocalFunction 1.0.0</h2></div>
<div><div class="author"><h3 class="author">
<span class="firstname">Lorenzo</span> <span class="surname">Caminiti <code class="email"><<a class="email" href="mailto:lorcaminiti_at_[hidden]">lorcaminiti_at_[hidden]</a>></code></span>
</h3></div></div>
<div><p class="copyright">Copyright © 2009-2012 Lorenzo
Caminiti</p></div>
<div><div class="legalnotice">
-<a name="local_function.legal"></a><p>
+<a name="boost_localfunction.legal"></a><p>
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)
+ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></div>
</div></div>
@@ -45,8 +45,7 @@
<dt><span class="section"><a href="boost_localfunction/Getting_Started.html#boost_localfunction.Getting_Started.compilers_and_platforms">Compilers
and Platforms</a></span></dt>
<dt><span class="section">Installation</span></dt>
-<dt><span class="section"><a href="boost_localfunction/Getting_Started.html#boost_localfunction.Getting_Started.compile_time_configuration">Compile-Time
- Configuration</a></span></dt>
+<dt><span class="section">Configuration</span></dt>
</dl></dd>
<dt><span class="section">Tutorial</span></dt>
<dd><dl>
@@ -79,46 +78,37 @@
<dt><span class="section"><a href="boost_localfunction/Advanced_Topics.html#boost_localfunction.Advanced_Topics.limitations__operators__etc_">Limitations
(operators, etc)</a></span></dt>
</dl></dd>
-<dt><span class="section">Appendix: Examples</span></dt>
+<dt><span class="section">Examples</span></dt>
<dd><dl>
<dt><span class="section"><a href="boost_localfunction/Examples.html#boost_localfunction.Examples.gcc_lambdas__without_c__11_">GCC
Lambdas (Without C++11)</a></span></dt>
<dt><span class="section"><a href="boost_localfunction/Examples.html#boost_localfunction.Examples.constant_blocks">Constant
Blocks</a></span></dt>
<dt><span class="section">Scope Exits</span></dt>
+<dt><span class="section"><a href="boost_localfunction/Examples.html#boost_localfunction.Examples.boost_phoenix_functions">Boost.Phoenix
+ Functions</a></span></dt>
+<dt><span class="section">Closures</span></dt>
<dt><span class="section"><a href="boost_localfunction/Examples.html#boost_localfunction.Examples.gcc_nested_functions">GCC
Nested Functions</a></span></dt>
<dt><span class="section">N-Papers</span></dt>
</dl></dd>
-<dt><span class="section">Appendix: Alternatives</span></dt>
+<dt><span class="section">Reference</span></dt>
<dd><dl>
-<dt><span class="section">Features</span></dt>
-<dt><span class="section">Performances</span></dt>
+<dt><span class="section">Header <boost/local_function.hpp></span></dt>
+<dt><span class="section">Header <boost/local_function/config.hpp></span></dt>
</dl></dd>
+<dt><span class="section">Annex: Alternatives</span></dt>
<dt><span class="section"><a href="boost_localfunction/No_Variadic_Macros.html">Annex: No Variadic
Macros</a></span></dt>
-<dd><dl>
-<dt><span class="section"><a href="boost_localfunction/No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.sequence_syntax">Sequence
- Syntax</a></span></dt>
-<dt><span class="section"><a href="boost_localfunction/No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.an_example">An
- Example</a></span></dt>
-</dl></dd>
-<dt><span class="section">Appendix: Implementation</span></dt>
-<dd><dl>
-<dt><span class="section"><a href="boost_localfunction/Implementation.html#boost_localfunction.Implementation.local_classes_as_template_parameters">Local
- Classes as Template Parameters</a></span></dt>
-<dt><span class="section"><a href="boost_localfunction/Implementation.html#boost_localfunction.Implementation.parsing_macros">Parsing
- Macros</a></span></dt>
-<dt><span class="section"><a href="boost_localfunction/Implementation.html#boost_localfunction.Implementation.local_functions">Local
- Functions</a></span></dt>
-</dl></dd>
+<dt><span class="section">Annex: Implementation</span></dt>
<dt><span class="section">Release Notes</span></dt>
<dt><span class="section">Bibliography</span></dt>
<dt><span class="section">Acknowledgments</span></dt>
</dl>
</div>
<p>
- This library allows to declare functions at local scope within an enclosing function.
+ This library allows to program functions locally, directly within the scope where
+ they are needed.
</p>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
@@ -138,22 +128,22 @@
<p>
Using <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
lambda</a> functions, it is possible to implement local functions by naming
- the lambdas assigning them to local variables. For example (see also "add_lambda.cpp"
):
+ the lambdas assigning them to local variables. For example (see also add_lambda.cpp
):
</p>
<p>
</p>
-<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
- <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
+<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
+ <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
- <span class="keyword">auto</span> <span class="identifier">add</span> <span class="special">=</span> <span class="special">[</span><span class="identifier">factor</span><span class="special">,</span> <span class="special">&</span><span class="identifier">sum</span><span class="special">](</span><span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// C++11 only.</span>
+ <span class="keyword">auto</span> <span class="identifier">add</span> <span class="special">=</span> <span class="special">[</span><span class="identifier">factor</span><span class="special">,</span> <span class="special">&</span><span class="identifier">sum</span><span class="special">](</span><span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// C++11 only.</span>
<span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
<span class="special">};</span>
- <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the lambda (with one parameter `num`).</span>
+ <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the lambda.</span>
<span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
- <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
<span class="special">}</span>
</pre>
<p>
@@ -162,23 +152,23 @@
This library allows to program local functions portably between C++03
and C++11 (and
with performances comparable to lambdas on C++11
- compilers, see the <a class="link" href="">Alternatives</a>
- section). For example (see also "add.cpp"
):
+ compilers, see the <a class="link" href="boost_localfunction/Alternatives.html" title="Annex: Alternatives">Alternatives</a>
+ section). For example (see also add.cpp
):
</p>
<p>
</p>
-<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
- <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
+<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
+ <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&</span> <span class="identifier">sum</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
- <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the local function (with one parameter `num`).</span>
+ <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the local function.</span>
<span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
- <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
<span class="special">}</span>
</pre>
<p>
@@ -194,35 +184,45 @@
</li>
<li class="listitem">
The local function body is programmed using the usual C++ statement syntax
- (as a consequence, compiler error messages retain their usual meaning and
- format).
+ (as a consequence, compiler errors and debugging retain their usual meaning
+ and format).
</li>
<li class="listitem">
Local functions can be passed as template parameters so they can be conveniently
- passed to STL algorithms, etc (this is a strength with respect to C++03
- functors implemented using local classes, see [N2657]
- and the <a class="link" href="">Alternatives</a> section).
+ passed to STL algorithms, etc. <sup>[<a name="boost_localfunction.Introduction.f0" href="#ftn.boost_localfunction.Introduction.f0" class="footnote">1</a>]</sup>
</li>
<li class="listitem">
- However, local functions must be defined within a declarative context (e.g.,
- at a point in the code where local variables can be declared) thus they
- cannot be defined within expressions (this is a weakness with respect to
- <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
- lambda</a> functions, see the <a class="link" href="">Alternatives</a>
- section).
+ However, local functions must be specified within a declarative context
+ (e.g., at a point in the code where local variables can be declared) thus
+ they cannot be specified within expressions. <sup>[<a name="boost_localfunction.Introduction.f1" href="#ftn.boost_localfunction.Introduction.f1" class="footnote">2</a>]</sup>
</li>
</ul></div>
<p>
- See the <a class="link" href="">Alternatives</a> section
- for a comparison between this library, <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ See the <a class="link" href="boost_localfunction/Alternatives.html" title="Annex: Alternatives">Alternatives</a>
+ section for a comparison between this library, <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
lambda</a> functions, Boost.Phoenix,
- and other C++ techniques implementing related features.
+ and other C++ techniques that implement features related to local functions.
</p>
</div>
-<span style="color: red"><xi:include></xi:include></span>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Introduction.f0" href="#boost_localfunction.Introduction.f0" class="para">1</a>] </sup>
+ This is a strength with respect to C++03
+ functors implemented using local classes which cannot be passed as template
+ parameters, see [N2657]
+ and the <a class="link" href="boost_localfunction/Alternatives.html" title="Annex: Alternatives">Alternatives</a>
+ section.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Introduction.f1" href="#boost_localfunction.Introduction.f1" class="para">2</a>] </sup>
+ This is a weakness with respect to <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions which can instead be specified also within expressions,
+ see the <a class="link" href="boost_localfunction/Alternatives.html" title="Annex: Alternatives">Alternatives</a>
+ section.
+ </p></div>
+</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
-<td align="left"><p><small>Last revised: January 21, 2012 at 22:31:55 GMT</small></p></td>
+<td align="left"><p><small>Last revised: January 23, 2012 at 10:04:24 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
Modified: sandbox/local_function/libs/local_function/doc/implementation.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/implementation.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/implementation.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -4,16 +4,16 @@
[/ License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a ]
[/ copy at http://www.boost.org/LICENSE_1_0.txt). ]
-[section:Implementation Appendix: Implementation]
+[section:Implementation Annex: Implementation]
This section gives an overview of the key programming techniques used to implement this library.
[note
-The code listed here can be used by curious readers and library maintainers as a reference in trying to understand this library source files.
+The code listed here can be used by curious readers and library maintainers as a reference in trying to understand the library source code.
There is absolutely no guarantee that the library implementation uses the exact code listed here.
]
-[section Local Classes as Template Parameters]
+[h5 Local Classes as Template Parameters]
This library uses a local class to implement the local function object.
However, in __CPP03__ local classes (and therefore the local function objects they implement) cannot be passed as template parameters (e.g., to the `std::for_each` algorithm), this is instead possible on __CPP11__, MSVC, and some other compilers (see __N2657__).
@@ -25,29 +25,27 @@
# The /virtual functor trick/ derives the local functor class from a non-local base class.
The correct overridden implementation of the virtual `operator()` is then called via polymorphism.
+For example (see also [@../../example/impl_tparam_tricks.cpp =impl_tparam_tricks.cpp=]):
+
[example_impl_tparam_tricks]
The casting functor trick measured slightly better run-time performances than the virtual functor trick so the current implementation of this library uses the casting functor trick (probably because in addition to the indirect function call, the virtual functor trick also requires accessing the [@http://en.wikipedia.org/wiki/Virtual_method_table virtual function table]).
-However, neither one of tricks has been observed to allow for compiler optimizations that inline the local function calls because they rely on one indirect function call (via either a function pointer or a virtual function respectively).
+However, neither one of tricks has been observed to allow for compiler optimizations that inline the local function calls (because they rely on one indirect function call via either a function pointer or a virtual function respectively).
Therefore, on compilers that accept local types as template parameters (MSVC, __CPP11__, etc, see __N2657__), this library automatically generates code that passes the local class type directly as template parameter without using neither one of these two tricks in order to take full advantage of compiler optimizations that inline the local function calls.
-[endsect]
-
-[section Parsing Macros]
+[h5 Parsing Macros]
-This library macros can parse the list of specified parameters and detect if any of the bound parameter name matches the token `this_` (to generate special code to bind the object in scope), or if the parameter is bound by `const` (to generate special code to bind by constant), etc.
+This library macros can parse the list of specified parameters and detect if any of the bound variable names matches the token `this_` (to generate special code to bind the object in scope), or if the variable is bound by `const` (to generate special code to bind by constant), etc.
The parameter tokens are inspected using preprocessor metaprogramming, specifically using the macros from `"boost/local_function/detail/preprocessor/keyword/"`.
[footnote
This technique is at the core of even more complex preprocessor parsing macros like the ones that parse the __Contractpp__ syntax.
]
-For example, the following code defines a macro that allows the preprocessor to detect if a set of space-separated tokens end with `this_` or not:
+For example, the following code defines a macro that allows the preprocessor to detect if a set of space-separated tokens ends with `this_` or not:
[example_impl_pp_keyword]
-[endsect]
-
-[section Local Functions]
+[h5 Local Functions]
The local function macros expand to code equivalent to the following:
@@ -55,5 +53,3 @@
[endsect]
-[endsect]
-
Modified: sandbox/local_function/libs/local_function/doc/introduction.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/introduction.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/introduction.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -11,23 +11,29 @@
Local functions are a feature of many programming languages, notably [@http://en.wikipedia.org/wiki/Nested_function#An_example Pascal] and [@http://en.wikipedia.org/wiki/Nesting_(computing)#In_programming Ada], yet lacking from __CPP03__ (see also __N2511__).
Using __CPP11_lambda__ functions, it is possible to implement local functions by naming the lambdas assigning them to local variables.
-For example (see also [@../../test/add_lambda.cpp `"add_lambda.cpp"`]):
+For example (see also [@../../test/add_lambda.cpp =add_lambda.cpp=]):
[test_add_lambda]
This library allows to program local functions portably between __CPP03__ and __CPP11__ (and with performances comparable to lambdas on __CPP11__ compilers, see the __Alternatives__ section).
-For example (see also [@../../test/add.cpp `"add.cpp"`]):
+For example (see also [@../../test/add.cpp =add.cpp=]):
[test_add]
This library supports the following features for local functions:
* Local functions can capture, or better [@http://en.wikipedia.org/wiki/Name_binding /bind/], any of the variables from the enclosing scope (a function together with its captured variables is also called a [@http://en.wikipedia.org/wiki/Closure_(computer_science) /closure/]).
-* The local function body is programmed using the usual C++ statement syntax (as a consequence, compiler error messages retain their usual meaning and format).
-* Local functions can be passed as template parameters so they can be conveniently passed to STL algorithms, etc (this is a strength with respect to __CPP03__ functors implemented using local classes, see __N2657__ and the __Alternatives__ section).
-* However, local functions must be defined within a declarative context (e.g., at a point in the code where local variables can be declared) thus they cannot be defined within expressions (this is a weakness with respect to __CPP11_lambda__ functions, see the __Alternatives__ section).
+* The local function body is programmed using the usual C++ statement syntax (as a consequence, compiler errors and debugging retain their usual meaning and format).
+* Local functions can be passed as template parameters so they can be conveniently passed to STL algorithms, etc.
+[footnote
+This is a strength with respect to __CPP03__ functors implemented using local classes which cannot be passed as template parameters, see __N2657__ and the __Alternatives__ section.
+]
+* However, local functions must be specified within a declarative context (e.g., at a point in the code where local variables can be declared) thus they cannot be specified within expressions.
+[footnote
+This is a weakness with respect to __CPP11_lambda__ functions which can instead be specified also within expressions, see the __Alternatives__ section.
+]
-See the __Alternatives__ section for a comparison between this library, __CPP11_lambda__ functions, __Boost_Phoenix__, and other C++ techniques implementing related features.
+See the __Alternatives__ section for a comparison between this library, __CPP11_lambda__ functions, __Boost_Phoenix__, and other C++ techniques that implement features related to local functions.
[endsect]
Modified: sandbox/local_function/libs/local_function/doc/local_function.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/local_function.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/local_function.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -6,18 +6,16 @@
[library Boost.LocalFunction
[quickbook 1.5]
- [version 1.0.0 ]
+ [version 1.0.0]
[copyright 2009-2012 Lorenzo Caminiti]
[purpose declare functions at local scope]
[license
Distributed under the Boost Software License, Version 1.0.
- (See accompanying file LICENSE_1_0.txt or copy at
+ (See accompanying file LICENSE_1_0.txt or a copy at
[@http://www.boost.org/LICENSE_1_0.txt])
]
[authors [Caminiti <email>lorcaminiti_at_[hidden]</email>, Lorenzo]]
[category Function Objects and Higher-Order Programming]
- [id local_function]
- [dirname local_function]
]
[def __CPP03__ [@http://www.open-std.org/JTC1/SC22/WG21/docs/standards C++03]]
@@ -35,6 +33,7 @@
[def __Boost_Parameter__ [@http://www.boost.org/doc/libs/release/libs/parameter/doc/index.html Boost.Paramater]]
[def __Boost_Typeof__ [@http://www.boost.org/doc/libs/release/doc/html/typeof.html Boost.Typeof]]
[def __Boost_Function__ [@http://www.boost.org/doc/libs/release/doc/html/function.html Boost.Function]]
+[def __Boost_FunctionalOverloadedFunction__ [@http://www.boost.org/doc/libs/release/doc/html/functional/overloaded_function.html Boost.Functional/OverloadedFunction]]
[def __Boost_TypeTraits__ [@http://www.boost.org/doc/libs/release/libs/type_traits/doc/html/index.html Boost.TypeTraits]]
[def __Boost_Utility__ [@http://www.boost.org/doc/libs/release/libs/utility/doc/html/index.html Boost.Utility]]
[def __Boost_Chrono__ [@http://www.boost.org/doc/libs/release/libs/chrono/doc/html/index.html Boost.Chrono]]
@@ -49,28 +48,29 @@
[def __N2550__ [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2550.pdf \[N2550\]]]
[def __N2657__ [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm \[N2657\]]]
-[def __Introduction__ [link boost_local.Introduction Introduction]]
-[def __Getting_Started__ [link boost_local.Getting_Started Getting Started]]
-[def __Tutorial__ [link boost_local.Tutorial Tutorial]]
-[def __Advanced_Topics__ [link boost_local.Advanced_Topics Advanced Topics]]
+[def __Introduction__ [link boost_localfunction.Introduction Introduction]]
+[def __Getting_Started__ [link boost_localfunction.Getting_Started Getting Started]]
+[def __Tutorial__ [link boost_localfunction.Tutorial Tutorial]]
+[def __Advanced_Topics__ [link boost_localfunction.Advanced_Topics Advanced Topics]]
+[def __Examples__ [link boost_localfunction.Examples Examples]]
[def __Reference__ [@reference.html Reference]]
-[def __Examples__ [link boost_local.Examples Examples]]
-[def __Alternatives__ [link boost_local.Alternatives Alternatives]]
-[def __No_Variadic_Macros__ [link boost_local.No_Variadic_Macros No Variadic Macros]]
-[def __Implementation__ [link boost_local.Implementation Implementation]]
-[def __Release_Notes__ [link boost_local.Release_Notes Release Notes]]
-[def __Bibliography__ [link boost_local.Bibliography Bibliography]]
-[def __Acknowledgments__ [link boost_local.Acknowledgments Acknowledgments]]
+[def __Alternatives__ [link boost_localfunction.Alternatives Alternatives]]
+[def __No_Variadic_Macros__ [link boost_localfunction.No_Variadic_Macros No Variadic Macros]]
+[def __Implementation__ [link boost_localfunction.Implementation Implementation]]
+[def __Release_Notes__ [link boost_localfunction.Release_Notes Release Notes]]
+[def __Bibliography__ [link boost_localfunction.Bibliography Bibliography]]
+[def __Acknowledgments__ [link boost_localfunction.Acknowledgments Acknowledgments]]
[import ../test/add.cpp]
[import ../test/add_seq.cpp]
[import ../test/add_lambda.cpp]
-[import ../test/add_nobind.cpp]
-[import ../test/ten.cpp]
+[import ../test/add_params.cpp]
+[import ../test/ten_void.cpp]
[import ../test/add_this.cpp]
[import ../test/add_template.cpp]
[import ../test/add_default.cpp]
[import ../test/add_with_default.cpp]
+[import ../test/macro_commas.cpp]
[import ../test/return_assign.cpp]
[import ../test/transform.cpp]
[import ../test/typeof.cpp]
@@ -82,6 +82,8 @@
[import ../test/overload.cpp]
[import ../test/add_except.cpp]
[import ../test/add_classifiers.cpp]
+[import ../test/operator_err.cpp]
+[import ../test/goto_err.cpp]
[import ../test/seq.cpp]
[import ../example/const_block.cpp]
@@ -89,18 +91,20 @@
[import ../example/gcc_lambda_cpp11.cpp]
[import ../example/scope_exit.cpp]
[import ../example/scope_exit.hpp]
+[import ../example/boost_phoenix_local_factorial.cpp]
+[import ../example/boost_phoenix_factorial.cpp]
[import ../example/impl_tparam_tricks.cpp]
[import ../example/impl_pp_keyword.cpp]
[import ../example/impl_factorial.cpp]
-This library allows to declare functions at local scope within an enclosing function.
+This library allows to program functions locally, directly within the scope where they are needed.
[include introduction.qbk]
[include getting_started.qbk]
[include tutorial.qbk]
[include advanced_topics.qbk]
-[xinclude ../reference.xml]
[include examples.qbk]
+[xinclude reference.xml]
[include alternatives.qbk]
[include no_variadic_macros.qbk]
[include implementation.qbk]
Modified: sandbox/local_function/libs/local_function/doc/no_variadic_macros.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/no_variadic_macros.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/no_variadic_macros.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -3,7 +3,7 @@
This section illustrates an alternative syntax for compilers without variadic macro support.
-[section Sequence Syntax]
+[h5 Sequence Syntax]
Most modern compilers support [@http://en.wikipedia.org/wiki/Variadic_macro variaid macros] (notably, these include GCC, MSVC, and all __CPP11__ compilers).
However, in the rare case that programmers need to use this library on a compiler without variadic macros, this library also allows to specify its macro parameters using a __Boost_Preprocessor__ sequence where tokens are separated by round parenthesis `()`:
@@ -25,9 +25,7 @@
Note how the same macros accept both syntaxes on compilers with variadic macros and only the sequence syntax on compilers without variadic macros.
Finally, an empty list is always specified using `void` on compilers with and without variadic macros.
-[endsect]
-
-[section An Example]
+[h5 An Example]
The following is an example that shows a bit of all the different macro parameter combinations using the sequence syntax (see also [@../../test/seq.cpp `"seq.cpp"`]):
@@ -35,5 +33,3 @@
[endsect]
-[endsect]
-
Modified: sandbox/local_function/libs/local_function/doc/release_notes.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/release_notes.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/release_notes.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -8,6 +8,10 @@
This section lists the major changes between different library releases (in chronological order).
+[h5 Version 1.0.0 (2012-01-31)]
+
+@todo do this
+
[h5 Version 0.2.0 (2011-05-14)]
# Replaced parenthesized syntax with variadic and sequencing macro syntaxes.
Modified: sandbox/local_function/libs/local_function/doc/tutorial.qbk
==============================================================================
--- sandbox/local_function/libs/local_function/doc/tutorial.qbk (original)
+++ sandbox/local_function/libs/local_function/doc/tutorial.qbk 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -13,7 +13,7 @@
Local functions are defined using macros from the header file [headerref boost/local_function.hpp].
The macros must be used from within a declarative context (this is a limitation with respect to __CPP11_lambda__ functions which can instead be declared within expressions):
- #include <boost/local_function.hpp>
+ #include <boost/local_function.hpp> // Include library header.
...
{ // Some declarative context.
@@ -28,6 +28,7 @@
[footnote
*Rationale.*
The local function name must be passed to the macro [macroref BOOST_LOCAL_FUNCTION_NAME] ending the function definition so this macro can declare a local variable with the local function name to hold the local function object.
+Therefore the local function name cannot be specified within the [macroref BOOST_LOCAL_FUNCTION] and it must appear instead after the local function body (even if that differs from the usual C++ function declaration syntax).
]
The usual C++ scope visibility rules apply to local functions for which a local function is visible only within the enclosing scope in which it is declared.
@@ -36,19 +37,19 @@
[footnote
*Rationale.*
If the local function body were instead passed as a macro parameter, it would be expanded on a single line of code (because macros always expand as a single line of code).
-Therefore, eventual compiler error line numbers would all report the same value and would no longer be useful to pinpoint the error.
+Therefore, eventual compiler error line numbers would all report the same value and would no longer be useful to pinpoint errors.
]
The local function parameters are passed to the [macroref BOOST_LOCAL_FUNCTION] macro as a comma-separated list of tokens (see the __No_Variadic_Macros__ section for compilers that do not support variadic macros):
BOOST_LOCAL_FUNCTION(``[^/parameter-type1 parameter-name1/]``,`` [^/parameter-type2 parameter-name2, .../]``)
-The maximum number of parameters that can be passed to a local function (excluding eventual bound variables) is controlled at compile-time by the configuration macro [macroref BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX].
-For example, let's program a local function named `add` that adds together two integers `x` and `y` (see also [@../../test/add_nobind.cpp `"add_nobind.cpp"`]):
+The maximum number of parameters that can be passed to a local function is controlled at compile-time by the configuration macro [macroref BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX].
+For example, let's program a local function named `add` that adds together two integers `x` and `y` (see also [@../../test/add_params.cpp =add_params.cpp=]):
-[test_add_nobind]
+[test_add_params]
-If the local function has no parameter, it is possible to pass `void` to the [macroref BOOST_LOCAL_FUNCTION] macro (similarly to the C syntax that allows to use `int f(void)` for a function with no parameter):
+If the local function has no parameter, it is possible to pass `void` to the [macroref BOOST_LOCAL_FUNCTION] macro (similarly to the C syntax that allows to use `int f(void)` to declare a function with no parameter):
[footnote
*Rationale.*
The __CPP03__ standard does not allow pass empty parameters to a macro so the macro cannot be invoked as `BOOST_LOCAL_FUNCTION()`.
@@ -57,9 +58,9 @@
BOOST_LOCAL_FUNCTION(void) // No parameter.
-For example, let's program a local function that always returns `10` (see also [@../../test/ten.cpp `"ten.cpp"`]):
+For example, let's program a local function that always returns `10` (see also [@../../test/ten_void.cpp =ten_void.cpp=]):
-[test_ten]
+[test_ten_void]
[endsect]
@@ -73,19 +74,19 @@
By binding a variable in scope, the local function declaration is specifying that such a variable should be accessible within the local function body regardless of its type.
Semantically, this binding should be seen as an "extension" of the scope of the bound variable from the enclosing scope to the scope of the local function body.
Therefore, contrary to the semantic of passing a function parameter, the semantic of binding a variable does not depend on the variable type but just on the variable name: "The variable in scope named /x/ should be accessible within the local function named /f/".
-For example, this is useful for maintenance because if a bound variable type is changed, the local function declaration does not have to change.
+For example, this reduces maintenance because if a bound variable type is changed, the local function declaration does not have to change.
]
[important
The library implementation uses __Boost_Typeof__ to automatically deduce the types of the bound variables.
-In order to compile code in type-of emulation mode, all types should be properly registered with `BOOST_TYPEOF_REGISTER_TYPE` or `BOOST_TYPEOF_REGISTER_TEMPLATE` macros, or appropriate __Boost_Typeof__ headers should be included (see the __Boost_Typeof__ documentation for more detail).
+Therefore, in order to compile code in type-of emulation mode, all types should be properly registered with `BOOST_TYPEOF_REGISTER_TYPE` or `BOOST_TYPEOF_REGISTER_TEMPLATE` macros, or appropriate __Boost_Typeof__ headers should be included (see the __Boost_Typeof__ documentation for more detail).
]
This library introduces the new "keyword" `bind`
[footnote
Obviously, the token `bind` is not a keyword of the C++ language.
This library parses the token `bind` during macro expansion using preprocessor metaprogramming (see the __Implementation__ section).
-Therefore, `bind` can be considered a new "keyword" only at the preprocessor metaprogramming level within the syntax defined by the macros of this library- thus it is referred to as a "keyword" only within quotes.
+Therefore, `bind` can be considered a new "keyword" only at the preprocessor metaprogramming level within the syntax defined by the macros of this library (thus it is referred to as a "keyword" only within quotes).
]
which is used in place of the parameter type to specify the name of a variable in scope to bind (therefore, `bind` cannot be used as a local function parameter type).
A variable can be bound by value:
@@ -117,14 +118,14 @@
The type of a bound variable is automatically deduced and it is the exact same type used to declare such a variable in the enclosing scope with the following notes:
-* If a bound variable was declared constant in the enclosing scope, it will be always bound by constant value or constant reference even if `bind` is used instead of `const bind` .
-However, if a bound variable was not declared constant in the enclosing scope then it will not be bound as constant unless constant binding is forced using `const bind`.
+* If a bound variable was declared constant in the enclosing scope, it will always be bound by constant value or constant reference even if `bind...` is used instead of `const bind...` .
+However, if a bound variable was not declared constant in the enclosing scope then it will not be bound as constant unless constant binding is forced using `const bind...`.
(Note that binding by constant reference is not supported by __CPP11_lambda__ functions but it is supported by this library.)
[footnote
An historical note: Constant binding of variables in scope was the main use case that originally motivated the authors in developing this library.
The authors needed to locally create a chuck of code to assert some correctness conditions while these assertions were not supposed to modify any of the variables they were using (see the __Contractpp__ library).
This was achieved by binding by constant reference `const bind&` the variables needed by the assertions and then by programming the local function body to check the assertions.
-This way if any of the assertions mistakenly changes a bound variable (for example confusing the operator `==` with `=`), the compiler correctly generates an error because the bound variable is of `const` type within the local function body.
+This way if any of the assertions mistakenly changes a bound variable (for example confusing the operator `==` with `=`), the compiler correctly generates an error because the bound variable is of `const` type within the local function body (see also /constant blocks/ in the __Examples__ section).
]
* If a bound variable was declared as a reference in the enclosing scope, it will still be bound by value unless it is explicitly bound by reference using `bind&` or `const bind&`.
[footnote
@@ -133,10 +134,11 @@
On the other hand, variables originally declared as constants should never loose their `const` qualifier (to prevent their modification not just in the enclosing scope but also in the local scope) thus they are always bound by constant even if `bind[&]` is used instead of `const bind[&]`.
]
+When a variable is bound by value (constant or not), its type must be `CopyConstructible` (i.e., its must provide a copy constructor).
As with passing parameters to usual C++ functions, programmers might want to bind variables of complex types by (possibly constant) reference instead than by value to avoid expensive copy operations when these variables are bound to a local function.
For example, let's program the local function `add` from the example in the __Introduction__ section.
-We bind the local variable `factor` by constant value, the local variable `sum` by (non-constant) reference, and program the body to perform the summation (see also [@../../test/add.cpp `"add.cpp"`]):
+We bind the local variable `factor` by constant value (because its value does not need to be changed), the local variable `sum` by non-constant reference (because its value needs to be updated with the summation result), and program the body to perform the summation (see also [@../../test/add.cpp =add.cpp=]):
[test_add]
@@ -145,18 +147,25 @@
[section Binding the Object `this`]
It is also possible to bind the object `this` when it is in scope (e.g., from an enclosing non-static member function).
-This is done by using the special symbol `this_`
+This is done by using the special symbol `this_` (instead of `this`)
[footnote
*Rationale.*
The special name `this_` was chosen following [@http://boost.2283326.n4.nabble.com/local-this-or-this-td3423912.html Boost practises] which postfix with an underscore identifiers that are named after keywords (the C++ keyword `this` in this case).
+The special symbol `this_` is needed because `this` is a reserved C++ keyword so it cannot be used as the name of the internal parameter that passes the bound object to the local function body.
+It would have been possible to use `this` (instead of `this_`) within the local function body either at the expenses of copying the bound object (which would introduce run-time overhead and also the stringent requirement that the bound object must have a deep copy constructor) or by relying on an [@http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/d3a86f27277f713b undefined behaviour of `static_cast`] (which might not work on all platforms at the cost of portability).
]
-(instead of `this`)
+as the name of the variable to bind in the local function declaration and also to access the object within the local function body.
+
+[warning
+The library will generate a compile-time error if `this` is mistakenly used instead of `this_` to bind the object in the local function declaration.
+However, mistakenly using `this` instead of `this_` to access the object within the local function body will leads to undefined behaviour and it will not necessarily generate a compile-time error.
[footnote
*Rationale.*
-This limitation comes from the fact that `this` is a reserved C++ keyword so it cannot be used as the name of the internal parameter that passes the bound object to the local function body.
-It would have been possible to use `this` (instead of `this_`) within the local function body either at the expenses of copying the bound object (which would introduce run-time overhead and also the stringent requirement that the bound object must have a deep copy constructor) or by relying on an [@http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/d3a86f27277f713b undefined behaviour of `static_cast`] (which might not work on all platforms at the cost of portability).
+The local function body cannot be a static member function of the local functor object in order to support recursion (because the local function name is specified by the [macroref BOOST_LOCAL_FUNCTION_NAME] macro only after the body so it must be made available via a functor member variable named after the local function and local classes cannot have static member variables in C++) and nesting (because the argument binding variable must be declared as a member variable so it is visible in a local function nested within the body member function) -- see the __Implementation__ section.
+Therefore, from within the local function body the variable `this` is visible but it refers to the local functor and not to the bound object.
+]
+Programmers are ultimately responsible to make sure that `this` is never used within a local function.
]
-as the name of the variable to bind in the local function declaration and also to access the object within the local function body.
The object `this` can be bound by value:
@@ -169,22 +178,19 @@
In this case the local function will never be able to modify the object (regardless of whether the enclosing scope is a constant member or not).
-Note that the object `this` can never be bound by reference because C++ does not allow to obtain a reference to `this` (the library will generate a compile-time error if programmers try to use `bind& this` or `const bind& this`).
+Note that the object `this` can never be bound by reference because C++ does not allow to obtain a reference to `this` (the library will generate a compile-time error if programmers try to use `bind& this_` or `const bind& this_`).
Note that `this` is a pointer so the pointed object is never copied even if `this` is bound by value (also it is not allowed to directly bind `*this` because `*this` is an expression and not a valid name of a variable in scope).
-[warning
-Unfortunately, mistakenly using `this` within the local function body instead of `this_` leads to undefined behaviour and it will not necessarily generate a compile-time error.
+For example, let's program a local function `add` similar to the one in the example from the __Introduction__ section but using a member function to illustrate how to bind the object `this` (see also [@../../test/add_this.cpp =add_this.cpp=]):
+
+[test_add_this]
+
+As expected, the local function has access to all class members via the bound object `this_` regardless of their access level (`public`, `protected`, or `private`).
[footnote
*Rationale.*
-The local function body cannot be a static member function of the local functor object in order to support recursion (because the local function name is specified by the [macroref BOOST_LOCAL_FUNCTION_NAME] macro only after the body so it must be made available via a functor member variable named after the local function and local classes cannot have static member variables in C++) and nesting (because the argument binding variable must be declared as a member variable so it is visible in a local function nested within the body member function) -- see the __Implementation__ section.
-Therefore, from within the local function body the variable `this` is visible but it refers to the local functor and not to the bound object.
-]
-Programmers are responsible to make sure that `this` is never used within a local function body which should only use the special symbol `this_`.
+This is possible because of C++ defect fix #46 that made inner and local types able to access all outer class members regardless of their access level.
]
-
-For example, let's program a local function `add` similar to the one in the example from the __Introduction__ section but using a member function to illustrate how to bind the object `this` (see also [@../../test/add_this.cpp `"add_this.cpp"`]):
-
-[test_add_this]
+Specifically, in the example above the local function updates the `private` data member `sum_`.
[endsect]
@@ -210,7 +216,7 @@
The [macroref BOOST_LOCAL_FUNCTION_TPL] macro has the exact same syntax of the [macroref BOOST_LOCAL_FUNCTION] macro that we have seen so far.
-For example, let's rewrite a local function similar to the one from the __Introduction__ section but wrapped within a template:
+For example, let's program a local function similar to the one from the __Introduction__ section but wrapped within a template (see also [@../../test/add_template.cpp =add_template.cpp=]):
[test_add_template]
Modified: sandbox/local_function/libs/local_function/example/Jamfile.v2
==============================================================================
--- sandbox/local_function/libs/local_function/example/Jamfile.v2 (original)
+++ sandbox/local_function/libs/local_function/example/Jamfile.v2 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -15,6 +15,9 @@
run gcc_lambda.cpp ;
run gcc_lambda_cpp11.cpp ;
+run boost_phoenix_factorial.cpp ;
+run boost_phoenix_local_factorial.cpp ;
+
run gcc_access.cpp ;
run gcc_square.cpp ;
run gcc_store.cpp ;
Modified: sandbox/local_function/libs/local_function/example/const_block.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/example/const_block.cpp (original)
+++ sandbox/local_function/libs/local_function/example/const_block.cpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -6,7 +6,7 @@
//[example_const_block
int x = 1, y = 2;
CONST_BLOCK(x, y) { // Constant block.
- assert(x = y); // Compiler error.
+ assert(x = y); // Compiler error.
} CONST_BLOCK_END
//]
return 0;
Modified: sandbox/local_function/libs/local_function/example/impl_tparam_tricks.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/example/impl_tparam_tricks.cpp (original)
+++ sandbox/local_function/libs/local_function/example/impl_tparam_tricks.cpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -4,8 +4,6 @@
// License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
// copy at http://www.boost.org/LICENSE_1_0.txt).
-// Tricks to "pass" a local class as a template parameter.
-
//[example_impl_tparam_tricks
#define BOOST_TEST_MODULE ExampleTparamTricks
#include <boost/test/unit_test.hpp>
Modified: sandbox/local_function/libs/local_function/test/Jamfile.v2
==============================================================================
--- sandbox/local_function/libs/local_function/test/Jamfile.v2 (original)
+++ sandbox/local_function/libs/local_function/test/Jamfile.v2 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -11,19 +11,24 @@
run add_except.cpp ;
run add_inline.cpp ;
run add_lambda.cpp ;
-run add_nobind.cpp ;
+run add_params.cpp ;
run add_template.cpp ;
run add_this.cpp ;
run add_typed.cpp ;
run add_with_default.cpp ;
run factorial.cpp ;
+run macro_commas.cpp ;
run nesting.cpp ;
run overload.cpp ;
-run ten.cpp ;
+run ten_void.cpp ;
run transform.cpp ;
run typeof.cpp ;
run typeof_template.cpp ;
+run operator_ok.cpp ;
+compile-fail operator_err.cpp ;
+run goto_ok.cpp ;
+compile-fail goto_err.cpp ;
run return_assign.cpp ;
run return_derivative.cpp ;
Modified: sandbox/local_function/libs/local_function/test/add.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/test/add.cpp (original)
+++ sandbox/local_function/libs/local_function/test/add.cpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -6,18 +6,18 @@
BOOST_AUTO_TEST_CASE( test_add )
//[test_add
-{ // Some local scope.
- int sum = 0, factor = 10; // Variables in scope to bind.
+{ // Some local scope.
+ int sum = 0, factor = 10; // Variables in scope to bind.
void BOOST_LOCAL_FUNCTION(const bind factor, bind& sum, int num) {
sum += factor * num;
} BOOST_LOCAL_FUNCTION_NAME(add)
- add(1); // Call the local function (with one parameter `num`).
+ add(1); // Call the local function.
int nums[] = {2, 3};
- std::for_each(nums, nums + 2, add); // Pass it to an algorithm.
+ std::for_each(nums, nums + 2, add); // Pass it to an algorithm.
- BOOST_CHECK( sum == 60 ); // Assert final summation value.
+ BOOST_CHECK( sum == 60 ); // Assert final summation value.
}
//]
Modified: sandbox/local_function/libs/local_function/test/add_lambda.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/test/add_lambda.cpp (original)
+++ sandbox/local_function/libs/local_function/test/add_lambda.cpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -9,18 +9,18 @@
BOOST_AUTO_TEST_CASE( test_add_lambda )
//[test_add_lambda
-{ // Some local scope.
- int sum = 0, factor = 10; // Variables in scope to bind.
+{ // Some local scope.
+ int sum = 0, factor = 10; // Variables in scope to bind.
- auto add = [factor, &sum](int num) { // C++11 only.
+ auto add = [factor, &sum](int num) { // C++11 only.
sum += factor * num;
};
- add(1); // Call the lambda (with one parameter `num`).
+ add(1); // Call the lambda.
int nums[] = {2, 3};
- std::for_each(nums, nums + 2, add); // Pass it to an algorithm.
+ std::for_each(nums, nums + 2, add); // Pass it to an algorithm.
- BOOST_CHECK( sum == 60 ); // Assert final summation value.
+ BOOST_CHECK( sum == 60 ); // Assert final summation value.
}
//]
Deleted: sandbox/local_function/libs/local_function/test/add_nobind.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/test/add_nobind.cpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
+++ (empty file)
@@ -1,21 +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).
-
-#include <boost/local_function.hpp>
-#define BOOST_TEST_MODULE TestAddNobind
-#include <boost/test/unit_test.hpp>
-
-BOOST_AUTO_TEST_CASE( test_add_nobind ) {
- //[test_add_nobind
- int BOOST_LOCAL_FUNCTION(int x, int y) { // Local function.
- return x + y;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- BOOST_CHECK( add(1, 2) == 3 ); // Local function call.
- //]
-}
-//]
-
Copied: sandbox/local_function/libs/local_function/test/add_params.cpp (from r76631, /sandbox/local_function/libs/local_function/test/add_nobind.cpp)
==============================================================================
--- /sandbox/local_function/libs/local_function/test/add_nobind.cpp (original)
+++ sandbox/local_function/libs/local_function/test/add_params.cpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -5,11 +5,11 @@
// copy at http://www.boost.org/LICENSE_1_0.txt).
#include <boost/local_function.hpp>
-#define BOOST_TEST_MODULE TestAddNobind
+#define BOOST_TEST_MODULE TestAddParams
#include <boost/test/unit_test.hpp>
-BOOST_AUTO_TEST_CASE( test_add_nobind ) {
- //[test_add_nobind
+BOOST_AUTO_TEST_CASE( test_add_params ) {
+ //[test_add_params
int BOOST_LOCAL_FUNCTION(int x, int y) { // Local function.
return x + y;
} BOOST_LOCAL_FUNCTION_NAME(add)
Modified: sandbox/local_function/libs/local_function/test/factorial.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/test/factorial.cpp (original)
+++ sandbox/local_function/libs/local_function/test/factorial.cpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -19,7 +19,7 @@
bool recursion, default false) {
int result = 0;
- if (num < 2 ) result = 1;
+ if(num <= 0) result = 1;
else result = num * factorial(num - 1, true); // Recursive call.
if (!recursion) this_->results.push_back(result);
Deleted: sandbox/local_function/libs/local_function/test/ten.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/test/ten.cpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
+++ (empty file)
@@ -1,16 +0,0 @@
-
-#include <boost/local_function.hpp>
-#define BOOST_TEST_MODULE TestTen
-#include <boost/test/unit_test.hpp>
-#include <iostream>
-
-BOOST_AUTO_TEST_CASE( test_ten ) {
- //[test_ten
- int BOOST_LOCAL_FUNCTION(void) { // No parameter.
- return 10;
- } BOOST_LOCAL_FUNCTION_NAME(ten)
-
- BOOST_CHECK( ten() == 10 );
- //]
-}
-
Copied: sandbox/local_function/libs/local_function/test/ten_void.cpp (from r76631, /sandbox/local_function/libs/local_function/test/ten.cpp)
==============================================================================
--- /sandbox/local_function/libs/local_function/test/ten.cpp (original)
+++ sandbox/local_function/libs/local_function/test/ten_void.cpp 2012-01-25 09:20:56 EST (Wed, 25 Jan 2012)
@@ -1,11 +1,11 @@
#include <boost/local_function.hpp>
-#define BOOST_TEST_MODULE TestTen
+#define BOOST_TEST_MODULE TestTenVoid
#include <boost/test/unit_test.hpp>
#include <iostream>
-BOOST_AUTO_TEST_CASE( test_ten ) {
- //[test_ten
+BOOST_AUTO_TEST_CASE( test_ten_void ) {
+ //[test_ten_void
int BOOST_LOCAL_FUNCTION(void) { // No parameter.
return 10;
} BOOST_LOCAL_FUNCTION_NAME(ten)
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