Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76564 - in sandbox/closure: boost/functional boost/functional/overloaded_function boost/functional/overloaded_function/detail libs/functional/overloaded_function/doc
From: lorcaminiti_at_[hidden]
Date: 2012-01-17 17:21:06


Author: lcaminiti
Date: 2012-01-17 17:21:05 EST (Tue, 17 Jan 2012)
New Revision: 76564
URL: http://svn.boost.org/trac/boost/changeset/76564

Log:
Overload.
Added:
   sandbox/closure/boost/functional/overloaded_function.hpp (contents, props changed)
   sandbox/closure/boost/functional/overloaded_function/config.hpp (contents, props changed)
   sandbox/closure/boost/functional/overloaded_function/detail/base.hpp (contents, props changed)
   sandbox/closure/boost/functional/overloaded_function/detail/function_type.hpp (contents, props changed)
Properties modified:
   sandbox/closure/libs/functional/overloaded_function/doc/ (props changed)

Added: sandbox/closure/boost/functional/overloaded_function.hpp
==============================================================================
--- (empty file)
+++ sandbox/closure/boost/functional/overloaded_function.hpp 2012-01-17 17:21:05 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,282 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// Use, modification, and distribution is subject to the Boost Software
+// License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
+// copy at http://www.boost.org/LICENSE_1_0.txt).
+
+#ifndef DOXY // Doxygen documentation only.
+
+#if !BOOST_PP_IS_ITERATING
+# ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_HPP_
+# define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_HPP_
+
+# include <boost/functional/overloaded_function/detail/base.hpp>
+# include <boost/functional/overloaded_function/detail/function_type.hpp>
+# include <boost/functional/overloaded_function/config.hpp>
+# include <boost/preprocessor/iteration/iterate.hpp>
+# include <boost/preprocessor/repetition/enum.hpp>
+# include <boost/preprocessor/repetition/repeat.hpp>
+# include <boost/preprocessor/control/expr_iif.hpp>
+# include <boost/preprocessor/control/expr_if.hpp>
+# include <boost/preprocessor/comparison/greater.hpp>
+# include <boost/preprocessor/comparison/less.hpp>
+# include <boost/preprocessor/cat.hpp>
+# include <boost/preprocessor/arithmetic/add.hpp>
+# include <boost/preprocessor/tuple/eat.hpp>
+# include <boost/preprocessor/logical/and.hpp>
+# include <boost/preprocessor/logical/not.hpp>
+# include <boost/preprocessor/facilities/expand.hpp>
+
+#define BOOST_FUNCTIONAL_f_type(z, n, unused) \
+ BOOST_PP_CAT(F, n)
+
+#define BOOST_FUNCTIONAL_f_arg(z, n, unused) \
+ BOOST_PP_CAT(f, n)
+
+#define BOOST_FUNCTIONAL_f_tparam(z, n, unused) \
+ typename BOOST_FUNCTIONAL_f_type(z, n, ~) \
+
+#define BOOST_FUNCTIONAL_f_tparam_dflt(z, n, is_tspec) \
+ BOOST_FUNCTIONAL_f_tparam(z, n, ~) \
+ /* overload requires at least 2 functors so F0 and F1 not optional */ \
+ BOOST_PP_EXPR_IIF(BOOST_PP_AND(BOOST_PP_NOT(is_tspec), \
+ BOOST_PP_GREATER(n, 1)), \
+ = void \
+ )
+
+#define BOOST_FUNCTIONAL_f_arg_decl(z, n, unused) \
+ BOOST_FUNCTIONAL_f_type(z, n, ~) /* no qualifier to deduce tparam */ \
+ BOOST_FUNCTIONAL_f_arg(z, n, ~)
+
+#define BOOST_FUNCTIONAL_g_type(z, n, unused) \
+ BOOST_PP_CAT(G, n)
+
+#define BOOST_FUNCTIONAL_g_arg(z, n, unused) \
+ BOOST_PP_CAT(g, n)
+
+#define BOOST_FUNCTIONAL_g_tparam(z, n, unused) \
+ typename BOOST_FUNCTIONAL_g_type(z, n, ~)
+
+#define BOOST_FUNCTIONAL_g_arg_decl(z, n, unused) \
+ BOOST_FUNCTIONAL_g_type(z, n, ~) /* no qualifier to deduce tparam */ \
+ BOOST_FUNCTIONAL_g_arg(z, n, ~)
+
+#define BOOST_FUNCTIONAL_base(z, n, unused) \
+ ::boost::overloaded_function_detail::base< \
+ BOOST_FUNCTIONAL_f_type(z, n, ~) \
+ >
+
+#define BOOST_FUNCTIONAL_inherit(z, n, unused) \
+ public BOOST_FUNCTIONAL_base(z, n, ~)
+
+#define BOOST_FUNCTIONAL_base_init(z, n, unused) \
+ BOOST_FUNCTIONAL_base(z, n, ~)(BOOST_FUNCTIONAL_g_arg(z, n, ~))
+
+#define BOOST_FUNCTIONAL_using_operator_call(z, n, unused) \
+ using BOOST_FUNCTIONAL_base(z, n, ~)::operator();
+
+#define BOOST_FUNCTIONAL_function_type(z, n, unused) \
+ typename ::boost::overloaded_function_detail::function_type< \
+ BOOST_FUNCTIONAL_f_type(z, n, ~) \
+ >::type
+
+namespace boost {
+
+// Iterate within namespace.
+# define BOOST_PP_ITERATION_PARAMS_1 \
+ (3, (0, BOOST_PP_SUB( /*at least 2 func to overload 2, 3, ...*/\
+ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, 2), \
+ "boost/functional/overloaded_function.hpp"))
+# include BOOST_PP_ITERATE() // Iterate over function arity.
+
+} // namespace
+
+#undef BOOST_FUNCTIONAL_f_type
+#undef BOOST_FUNCTIONAL_f_arg
+#undef BOOST_FUNCTIONAL_f_tparam
+#undef BOOST_FUNCTIONAL_f_arg_decl
+#undef BOOST_FUNCTIONAL_f_tparam_dflt
+#undef BOOST_FUNCTIONAL_g_type
+#undef BOOST_FUNCTIONAL_g_arg
+#undef BOOST_FUNCTIONAL_g_tparam
+#undef BOOST_FUNCTIONAL_g_arg_decl
+#undef BOOST_FUNCTIONAL_base
+#undef BOOST_FUNCTIONAL_inherit
+#undef BOOST_FUNCTIONAL_base_init
+#undef BOOST_FUNCTIONAL_using_operator_call
+#undef BOOST_FUNCTIONAL_function_type
+
+# endif // #include guard
+
+#elif BOOST_PP_ITERATION_DEPTH() == 1
+# define BOOST_FUNCTIONAL_overloads \
+ /* iterate as OVERLOADS, OVERLOADS-1, OVERLOADS-2, ... */ \
+ BOOST_PP_SUB(BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, \
+ BOOST_PP_FRAME_ITERATION(1))
+# define BOOST_FUNCTIONAL_is_tspec \
+ /* if template specialization */ \
+ BOOST_PP_LESS(BOOST_FUNCTIONAL_overloads, \
+ BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX)
+
+template<
+ BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_tparam_dflt,
+ BOOST_FUNCTIONAL_is_tspec)
+>
+class overloaded_function
+ // Template specialization.
+ BOOST_PP_EXPR_IIF(BOOST_PP_EXPAND(BOOST_FUNCTIONAL_is_tspec), <)
+ BOOST_PP_IIF(BOOST_FUNCTIONAL_is_tspec,
+ BOOST_PP_ENUM
+ ,
+ BOOST_PP_TUPLE_EAT(3)
+ )(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_type, ~)
+ BOOST_PP_EXPR_IIF(BOOST_PP_EXPAND(BOOST_FUNCTIONAL_is_tspec), >)
+ // Bases (overloads >= 2 so always at least 2 bases).
+ : BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
+ BOOST_FUNCTIONAL_inherit, ~)
+{
+public:
+ template<
+ BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_g_tparam, ~)
+ > /* implicit */ inline overloaded_function(
+ BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
+ BOOST_FUNCTIONAL_g_arg_decl, ~))
+ // Overloads >= 2 so always at least 2 bases to initialize.
+ : BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
+ BOOST_FUNCTIONAL_base_init, ~)
+ {}
+
+ BOOST_PP_REPEAT(BOOST_FUNCTIONAL_overloads,
+ BOOST_FUNCTIONAL_using_operator_call, ~)
+};
+
+template<
+ BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_tparam, ~)
+>
+overloaded_function<
+ BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_function_type, ~)
+> make_overloaded_function(
+ BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_arg_decl, ~)
+) {
+ return overloaded_function<
+ BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
+ BOOST_FUNCTIONAL_function_type, ~)
+ >(BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_arg, ~));
+}
+
+# undef BOOST_FUNCTIONAL_overloads
+# undef BOOST_FUNCTIONAL_is_tspec
+#endif // iteration
+
+#else // DOXY: Doxygen documentation only.
+
+/** @file
+@brief Overload distinct function pointers, function references, and function
+objects into a single function object.
+*/
+
+namespace boost {
+
+/**
+@brief Function object that overloads functions with distinct signatures.
+
+This function object aggregates together calls to functions of all the
+specified function types <c>F1</c>, <c>F2</c>, etc.
+The function types must be distinct from one another and they must be specified
+following the Boost.Function preferred syntax:
+@code
+ result_type (argument1_type, argumgnet2_type, ...)
+@endcode
+
+In some cases, the @RefFunc{make_overloaded_function} function template can be
+used to construct the overloaded function object without explicitly specifying
+the function types.
+
+The maximum number of functions to overload is given by the
+@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}
+configuration macro.
+The maximum number of function parameters for each of the specified function
+types is given by the
+@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX}
+configuration macro.
+
+@See
+ @RefSect{Tutorial} section,
+ @RefFunc{make_overloaded_function},
+ @RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX},
+ @RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX},
+ Boost.Function.
+*/
+template<typename F1, typename F2, ...>
+class overloaded_function {
+public:
+ /**
+ @brief Construct the overloaded function object.
+
+ Any function pointer, function reference, function object that can be
+ converted to a <c>boost::function</c> function object can be specified as
+ parameter.
+ */
+ overload(const boost::function<F1>&, const boost::function<F2>&, ...);
+
+ /**
+ @brief Call operator matching the signature of the function type specified
+ as first template parameter.
+
+ This will in turn invoke the call operator of the first function passed to
+ the constructor.
+ */
+ typename boost::function_traits<F1>::result_type operator()(
+ typename boost::function_traits<F1>::arg1_type,
+ typename boost::function_traits<F1>::arg2_type,
+ ...) const;
+
+ /**
+ @brief Call operator matching the signature of the function type specified
+ as second template parameter.
+
+ This will in turn invoke the call operator of the second function passed to
+ the constructor.
+ */
+ typename boost::function_traits<F2>::result_type operator()(
+ typename boost::function_traits<F2>::arg1_type,
+ typename boost::function_traits<F2>::arg2_type,
+ ...) const;
+};
+
+/**
+@brief Make an overloaded function object without explicitly specifying the
+function types.
+
+This function template creates and returns an @RefClass{overloaded_function}
+function object that overloads all the functions specified by its parameters.
+
+The function types are internally determined from the template parameter types
+so they do not need to be explicitly specified.
+Therefore, this function template has a more concise syntax when compared to
+@RefClass{overloaded_function}.
+This is especially useful when the explicit type of the returned
+@RefClass{overloaded_function} does not need to be known (e.g., when used with Boost.Typeof's <c>BOOST_AUTO</c> (or C++11 <c>auto</c>) or when the overloaded
+function object is deduced using a function template parameter).
+
+The maximum number of functions to overload is given by the
+@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}
+configuration macro.
+
+@Note <c>__function_type__</c> is a placeholder in this documentation for a
+symbol that is specific to implementation of this library.
+
+@See
+ @RefSect{Tutorial} section,
+ @RefClass{overloaded_function},
+ @RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}.
+*/
+template<typename F1, typename F2, ...>
+overloaded_function<
+ __function_type__<F1>, __function_type__<F2>, ...
+> make_overloaded_function(F1 f1, F2 f2, ...);
+
+} // namespace
+
+#endif // DOXY
+

Added: sandbox/closure/boost/functional/overloaded_function/config.hpp
==============================================================================
--- (empty file)
+++ sandbox/closure/boost/functional/overloaded_function/config.hpp 2012-01-17 17:21:05 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,37 @@
+
+#ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_HPP_
+#define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_HPP_
+
+/** @file
+@brief Macros to change the compile-time configuration of this library.
+*/
+
+/**
+@brief Specify the maximum number of arguments of the functions being
+overloaded.
+
+If this macro is left undefined by the user, it has a default value of 5.
+
+@See
+ @RefSectId{Getting_Started, Getting Started},
+ @RefClass{overloaded_function}.
+*/
+#ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX
+#define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX 5
+#endif
+
+/**
+@brief Specify the maximum number of functions that can be overloaded.
+
+If this macro is left undefined by the user, it has a default value of 5.
+
+@See
+ @RefSectId{Getting_Started, Getting Started},
+ @RefClass{overloaded_function}.
+*/
+#ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX
+#define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX 5
+#endif
+
+#endif // #include guard
+

Added: sandbox/closure/boost/functional/overloaded_function/detail/base.hpp
==============================================================================
--- (empty file)
+++ sandbox/closure/boost/functional/overloaded_function/detail/base.hpp 2012-01-17 17:21:05 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,84 @@
+
+// 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).
+
+#if !BOOST_PP_IS_ITERATING
+# ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_BASE_HPP_
+# define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_BASE_HPP_
+
+# include <boost/functional/overloaded_function/config.hpp>
+# include <boost/function.hpp>
+# include <boost/preprocessor/iteration/iterate.hpp>
+# include <boost/preprocessor/repetition/enum.hpp>
+# include <boost/preprocessor/cat.hpp>
+# include <boost/preprocessor/comma_if.hpp>
+
+#define BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused) \
+ BOOST_PP_CAT(A, n)
+
+#define BOOST_FUNCTIONAL_DETAIL_arg_name(z, n, unused) \
+ BOOST_PP_CAT(a, n)
+
+#define BOOST_FUNCTIONAL_DETAIL_arg_tparam(z, n, unused) \
+ typename BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused)
+
+#define BOOST_FUNCTIONAL_DETAIL_arg(z, n, unused) \
+ BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused) \
+ BOOST_FUNCTIONAL_DETAIL_arg_name(z, n, unused)
+
+#define BOOST_FUNCTIONAL_DETAIL_f \
+ R (BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity, \
+ BOOST_FUNCTIONAL_DETAIL_arg_type, ~))
+
+namespace boost { namespace overloaded_function_detail {
+
+template<typename F>
+class base {}; // Empty template cannot be used directly (only its spec).
+
+# define BOOST_PP_ITERATION_PARAMS_1 \
+ (3, (0, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, \
+ "boost/functional/overloaded_function/detail/base.hpp"))
+# include BOOST_PP_ITERATE() // Iterate over funciton arity.
+
+} } // namespace
+
+#undef BOOST_FUNCTIONAL_DETAIL_arg_type
+#undef BOOST_FUNCTIONAL_DETAIL_arg_name
+#undef BOOST_FUNCTIONAL_DETAIL_arg_tparam
+#undef BOOST_FUNCTIONAL_DETAIL_arg
+#undef BOOST_FUNCTIONAL_DETAIL_f
+
+# endif // #include guard
+
+#elif BOOST_PP_ITERATION_DEPTH() == 1
+# define BOOST_FUNCTIONAL_DETAIL_arity BOOST_PP_FRAME_ITERATION(1)
+
+template<
+ typename R
+ BOOST_PP_COMMA_IF(BOOST_FUNCTIONAL_DETAIL_arity)
+ BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity,
+ BOOST_FUNCTIONAL_DETAIL_arg_tparam, ~)
+>
+class base< BOOST_FUNCTIONAL_DETAIL_f > {
+public:
+ /* implicit */ inline base(
+ // This requires specified type to be implicitly convertible to
+ // a boost::function<> functor.
+ boost::function< BOOST_FUNCTIONAL_DETAIL_f > const& f): f_(f)
+ {}
+
+ inline R operator()(BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity,
+ BOOST_FUNCTIONAL_DETAIL_arg, ~)) const {
+ return f_(BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity,
+ BOOST_FUNCTIONAL_DETAIL_arg_name, ~));
+ }
+
+private:
+ boost::function< BOOST_FUNCTIONAL_DETAIL_f > const f_;
+};
+
+# undef BOOST_FUNCTIONAL_DETAIL_arity
+#endif // iteration
+

Added: sandbox/closure/boost/functional/overloaded_function/detail/function_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/closure/boost/functional/overloaded_function/detail/function_type.hpp 2012-01-17 17:21:05 EST (Tue, 17 Jan 2012)
@@ -0,0 +1,67 @@
+
+#ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_FUNCTION_TYPE_HPP_
+#define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_FUNCTION_TYPE_HPP_
+
+#include <boost/function_types/is_function.hpp>
+#include <boost/function_types/is_function_pointer.hpp>
+#include <boost/function_types/is_function_reference.hpp>
+#include <boost/function_types/function_type.hpp>
+#include <boost/function_types/parameter_types.hpp>
+#include <boost/function_types/result_type.hpp>
+#include <boost/type_traits/remove_pointer.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/pop_front.hpp>
+#include <boost/mpl/push_front.hpp>
+#include <boost/typeof/typeof.hpp>
+
+namespace boost { namespace overloaded_function_detail {
+
+// Requires: F is a monomorphic functor (i.e., has non-template `operator()`).
+// Returns: F's function type `result_type (arg1_type, arg2_type, ...)`.
+// It does not assume F typedef result_type, arg1_type, ... but needs typeof.
+template<typename F>
+class functor_type {
+ typedef BOOST_TYPEOF_TPL(&(F::operator())) call_ptr;
+public:
+ typedef
+ typename boost::function_types::function_type<
+ typename boost::mpl::push_front<
+ typename boost::mpl::pop_front< // Remove functor type (1st).
+ typename boost::function_types::parameter_types<
+ call_ptr>::type
+ >::type
+ , typename boost::function_types::result_type<call_ptr>::type
+ >::type
+ >::type
+ type;
+};
+
+// Requires: F is a function type, pointer, reference, or monomorphic functor.
+// Returns: F's function type `result_type (arg1_type, arg2_type, ...)`.
+template<typename F>
+struct function_type {
+ typedef
+ typename boost::mpl::if_<boost::function_types::is_function<F>,
+ boost::mpl::identity<F>
+ ,
+ typename boost::mpl::if_<boost::function_types::
+ is_function_pointer<F>,
+ boost::remove_pointer<F>
+ ,
+ typename boost::mpl::if_<boost::function_types::
+ is_function_reference<F>,
+ boost::remove_reference<F>
+ , // Requires, it's a functor.
+ functor_type<F>
+ >::type
+ >::type
+ >::type
+ ::type type;
+};
+
+} } // namespace
+
+#endif // #include guard
+


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