|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71846 - in sandbox/local: boost/local/aux_ boost/local/function libs/local/example
From: lorcaminiti_at_[hidden]
Date: 2011-05-09 12:52:21
Author: lcaminiti
Date: 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
New Revision: 71846
URL: http://svn.boost.org/trac/boost/changeset/71846
Log:
Added overloading source and examples.
Added:
sandbox/local/boost/local/aux_/overload_base.hpp (contents, props changed)
sandbox/local/boost/local/function/
sandbox/local/boost/local/function/overload.hpp (contents, props changed)
sandbox/local/libs/local/example/b00.cpp (contents, props changed)
sandbox/local/libs/local/example/b01.cpp (contents, props changed)
sandbox/local/libs/local/example/overload.cpp (contents, props changed)
sandbox/local/libs/local/example/overload_va.cpp (contents, props changed)
sandbox/local/libs/local/example/p12.cpp (contents, props changed)
sandbox/local/libs/local/example/p13.cpp (contents, props changed)
sandbox/local/libs/local/example/p20.cpp (contents, props changed)
sandbox/local/libs/local/example/p21.cpp (contents, props changed)
sandbox/local/libs/local/example/p21.py (contents, props changed)
sandbox/local/libs/local/example/p22.cpp (contents, props changed)
sandbox/local/libs/local/example/p30.cpp (contents, props changed)
sandbox/local/libs/local/example/p31.cpp (contents, props changed)
sandbox/local/libs/local/example/p34.cpp (contents, props changed)
Added: sandbox/local/boost/local/aux_/overload_base.hpp
==============================================================================
--- (empty file)
+++ sandbox/local/boost/local/aux_/overload_base.hpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,80 @@
+
+#if !BOOST_PP_IS_ITERATING
+# ifndef BOOST_LOCAL_AUX_OVERLOAD_BASE_HPP_
+# define BOOST_LOCAL_AUX_OVERLOAD_BASE_HPP_
+
+# include "file.hpp"
+# include "../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_LOCAL_AUX_arg_type(z, n, unused) \
+ BOOST_PP_CAT(A, n)
+
+#define BOOST_LOCAL_AUX_arg_name(z, n, unused) \
+ BOOST_PP_CAT(a, n)
+
+#define BOOST_LOCAL_AUX_arg_tparam(z, n, unused) \
+ typename BOOST_LOCAL_AUX_arg_type(z, n, unused)
+
+#define BOOST_LOCAL_AUX_arg(z, n, unused) \
+ BOOST_LOCAL_AUX_arg_type(z, n, unused) \
+ BOOST_LOCAL_AUX_arg_name(z, n, unused)
+
+#define BOOST_LOCAL_AUX_f \
+ R (BOOST_PP_ENUM(BOOST_LOCAL_AUX_arity, BOOST_LOCAL_AUX_arg_type, ~))
+
+namespace boost { namespace local { namespace aux {
+
+template<typename F>
+class overload_base {
+ // Empty template cannot be used directly (only via its specializations).
+};
+
+# define BOOST_PP_ITERATION_PARAMS_1 \
+ (3, (0, BOOST_LOCAL_CONFIG_FUNCTION_ARITY_MAX, \
+ BOOST_LOCAL_AUX_FILE_OVERLOAD_BASE_HPP))
+# include BOOST_PP_ITERATE() // Iterate over funciton arity.
+
+}}} // namespace boost::local::aux
+
+#undef BOOST_LOCAL_AUX_arg_type
+#undef BOOST_LOCAL_AUX_arg_name
+#undef BOOST_LOCAL_AUX_arg_tparam
+#undef BOOST_LOCAL_AUX_arg
+#undef BOOST_LOCAL_AUX_f
+
+# endif // #include guard
+
+#elif BOOST_PP_ITERATION_DEPTH() == 1
+# define BOOST_LOCAL_AUX_arity BOOST_PP_FRAME_ITERATION(1)
+
+// Iterating within namespace boost::local::aux.
+template<typename R
+ BOOST_PP_COMMA_IF(BOOST_LOCAL_AUX_arity)
+ BOOST_PP_ENUM(BOOST_LOCAL_AUX_arity, BOOST_LOCAL_AUX_arg_tparam, ~)
+>
+class overload_base<BOOST_LOCAL_AUX_f> {
+public:
+ /* implicit */ inline overload_base(
+ // This requires specified type to be implicitly convertible to
+ // a boost::function<> functor.
+ ::boost::function<BOOST_LOCAL_AUX_f> const& f): f_(f)
+ {}
+
+ inline R operator()(BOOST_PP_ENUM(BOOST_LOCAL_AUX_arity,
+ BOOST_LOCAL_AUX_arg, ~)) const {
+ return f_(BOOST_PP_ENUM(BOOST_LOCAL_AUX_arity,
+ BOOST_LOCAL_AUX_arg_name, ~));
+ }
+
+private:
+ ::boost::function<BOOST_LOCAL_AUX_f> const f_;
+};
+
+# undef BOOST_LOCAL_AUx_arity
+#endif // iteration
+
Added: sandbox/local/boost/local/function/overload.hpp
==============================================================================
--- (empty file)
+++ sandbox/local/boost/local/function/overload.hpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,119 @@
+
+#if !BOOST_PP_IS_ITERATING
+# ifndef BOOST_LOCAL_FUNCTION_OVERLOAD_HPP_
+# define BOOST_LOCAL_FUNCTION_OVERLOAD_HPP_
+
+# include "../config.hpp"
+# include "../aux_/file.hpp"
+# include "../aux_/overload_base.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_LOCAL_f_type(z, f, unused) \
+ BOOST_PP_CAT(F, f)
+
+#define BOOST_LOCAL_f_tparam(z, f, unused) \
+ typename BOOST_LOCAL_f_type(z, f, unused) \
+
+#define BOOST_LOCAL_f_tparam_dflt(z, f, is_tspec) \
+ BOOST_LOCAL_f_tparam(z, f, unused) \
+ /* 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(f, 1)), \
+ = void \
+ )
+
+#define BOOST_LOCAL_g_arg_type(z, f, unused) \
+ BOOST_PP_CAT(G, f)
+
+#define BOOST_LOCAL_g_arg_name(z, f, unused) \
+ BOOST_PP_CAT(g, f)
+
+#define BOOST_LOCAL_g_arg_tparam(z, f, unused) \
+ typename BOOST_LOCAL_g_arg_type(z, f, unused)
+
+#define BOOST_LOCAL_g_arg(z, f, unused) \
+ /* unfortunately, cannot add const and/or & (not even using */ \
+ /* Boost.TypeTraits or Boost.CallTraits) to this function argument */ \
+ /* type which needs to remain generic as in its template declaration */ \
+ /* (otherwise MSVC cannot deduce the types */ \
+ BOOST_LOCAL_g_arg_type(z, f, unused) \
+ BOOST_LOCAL_g_arg_name(z, f, unsed)
+
+#define BOOST_LOCAL_overload_base(z, f, unused) \
+ ::boost::local::aux::overload_base<BOOST_LOCAL_f_type(z, f, unused)>
+
+#define BOOST_LOCAL_overload_inherit(z, f, unused) \
+ public BOOST_LOCAL_overload_base(z, f, unused)
+
+#define BOOST_LOCAL_overload_base_init(z, f, unused) \
+ BOOST_LOCAL_overload_base(z, f, unused)( /* base init paren `()` */ \
+ BOOST_LOCAL_g_arg_name(z, f, unused))
+
+#define BOOST_LOCAL_using_operator_call(z, f, unused) \
+ using BOOST_LOCAL_overload_base(z, f, unused)::operator();
+
+namespace boost { namespace local { namespace function {
+
+// Iterate within namespace.
+# define BOOST_PP_ITERATION_PARAMS_1 \
+ /* need at least 2 functors to overload so iter 2, 3, ... */ \
+ (3, (0, BOOST_PP_SUB(BOOST_LOCAL_CONFIG_OVERLOADS, 2), \
+ BOOST_LOCAL_AUX_FILE_FUNCTION_OVERLOAD_HPP))
+# include BOOST_PP_ITERATE() // Iterate over function arity.
+
+}}} // namespace boost::local::function
+
+# endif // #include guard
+
+#elif BOOST_PP_ITERATION_DEPTH() == 1
+# define BOOST_LOCAL_overloads \
+ /* iterate as OVERLOADS, OVERLOADS-1, OVERLOADS-2, ... */ \
+ BOOST_PP_SUB(BOOST_LOCAL_CONFIG_OVERLOADS, BOOST_PP_FRAME_ITERATION(1))
+# define BOOST_LOCAL_is_tspec \
+ /* if template specialization */ \
+ BOOST_PP_LESS(BOOST_LOCAL_overloads, BOOST_LOCAL_CONFIG_OVERLOADS)
+
+// Iterating within namespace boost::local::function.
+template<BOOST_PP_ENUM(BOOST_LOCAL_overloads, BOOST_LOCAL_f_tparam_dflt,
+ BOOST_LOCAL_is_tspec)>
+class overload
+ // Template specialization.
+ BOOST_PP_EXPR_IIF(BOOST_PP_EXPAND(BOOST_LOCAL_is_tspec), <)
+ BOOST_PP_IIF(BOOST_LOCAL_is_tspec,
+ BOOST_PP_ENUM
+ ,
+ BOOST_PP_TUPLE_EAT(3)
+ )(BOOST_LOCAL_overloads, BOOST_LOCAL_f_type, ~)
+ BOOST_PP_EXPR_IIF(BOOST_PP_EXPAND(BOOST_LOCAL_is_tspec), >)
+ // Bases.
+ : // Overloads >= 2 so always at least 2 bases.
+ BOOST_PP_ENUM(BOOST_LOCAL_overloads, BOOST_LOCAL_overload_inherit, ~)
+{
+public:
+ template<BOOST_PP_ENUM(BOOST_LOCAL_overloads, BOOST_LOCAL_g_arg_tparam, ~)>
+ /* implicit */ inline overload(
+ BOOST_PP_ENUM(BOOST_LOCAL_overloads, BOOST_LOCAL_g_arg, ~))
+ : // Overloads >= 2 so always at least 2 bases to initialize.
+ BOOST_PP_ENUM(BOOST_LOCAL_overloads,
+ BOOST_LOCAL_overload_base_init, ~)
+ {}
+
+ BOOST_PP_REPEAT(BOOST_LOCAL_overloads, BOOST_LOCAL_using_operator_call, ~)
+};
+
+# undef BOOST_LOCAL_is_tspec
+# undef BOOST_LOCAL_AUX_overloads
+#endif // iteration
+
Added: sandbox/local/libs/local/example/b00.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/b00.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,29 @@
+
+/*
+
+const bind& x
+--> bind& x
+--> & x
+
+const bind_type int& x
+--> bind_type int& x
+--> int& x --> int
+
+const bind<int>& x
+--> bind<int>& x
+--> <int>& x
+--> select<t11>::type<int>& x
+
+*/
+
+struct bind {
+ template<typename T = void>
+ struct type {};
+};
+
+
+int main() {
+ bind::type<int> b;
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/b01.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/b01.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,54 @@
+
+#include <boost/local/aux_/preprocessor/keyword/bind.hpp>
+#include <boost/preprocessor.hpp>
+#include <boost/preprocessor/detail/is_unary.hpp>
+
+#define IS_BIND_TYPED_(tokens) \
+ BOOST_PP_IS_UNARY(BOOST_LOCAL_AUX_PP_KEYWORD_BIND_REMOVE_FRONT(tokens))
+
+#define IS_BIND_TYPED(tokens) \
+ BOOST_PP_IIF(BOOST_LOCAL_AUX_PP_KEYWORD_IS_BIND_FRONT(tokens), \
+ IS_BIND_TYPED_ \
+ , \
+ 0 BOOST_PP_TUPLE_EAT(1) \
+ )(tokens)
+
+#define BIND_TYPED_EXPR_bind(type) \
+ type
+
+#define BIND_TYPED_EXPR_(tokens) \
+ BOOST_PP_CAT(BIND_TYPED_EXPR_, tokens)
+
+#define BIND_TYPED_EXPR(tokens) \
+ BOOST_PP_IIF(IS_BIND_TYPED(tokens), \
+ BIND_TYPED_EXPR_ \
+ , \
+ tokens BOOST_PP_TUPLE_EAT(1) \
+ )(tokens)
+
+#define BIND_TYPED_REMOVE_FRONT_bind(tokens) /* must expand to nothing */
+
+#define BIND_TYPED_REMOVE_FRONT_(tokens) \
+ BOOST_PP_CAT(BIND_TYPED_REMOVE_FRONT_, tokens)
+
+#define BIND_TYPED_REMOVE_FRONT(tokens) \
+ BOOST_PP_IIF(IS_BIND_TYPED(tokens), \
+ BIND_TYPED_REMOVE_FRONT_ \
+ , \
+ tokens BOOST_PP_TUPLE_EAT(1) \
+ )(tokens)
+
+-----
+IS_BIND_TYPED( int& x )
+IS_BIND_TYPED( bind& x )
+IS_BIND_TYPED( bind(double)& x )
+-----
+BIND_TYPED_EXPR( int& x )
+BIND_TYPED_EXPR( bind& x )
+BIND_TYPED_EXPR( bind(double)& x )
+-----
+BIND_TYPED_REMOVE_FRONT( int& x )
+BIND_TYPED_REMOVE_FRONT( bind& x )
+BIND_TYPED_REMOVE_FRONT( bind(double)& x )
+-----
+
Added: sandbox/local/libs/local/example/overload.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/overload.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,50 @@
+
+//[overload_cpp
+#include <boost/local/function/overload.hpp> // Include header for overloading.
+#include <boost/local/function.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include <string>
+
+int print_add(int x, int y) {
+ std::cout << x << " + " << y << " = ";
+ return x + y;
+}
+
+int main() {
+ char sep = '\n';
+
+ void BOOST_LOCAL_FUNCTION_PARAMS( (const std::string& item)
+ (const bind& sep) ) {
+ std::cout << item << " (string)" << sep;
+ } BOOST_LOCAL_FUNCTION_NAME(print_string)
+
+ void BOOST_LOCAL_FUNCTION_PARAMS( (const double& item)
+ (const char* name)(default " (double)") (const bind& sep) ) {
+ std::cout << item << name << sep;
+ } BOOST_LOCAL_FUNCTION_NAME(print_double)
+
+ boost::local::function::overload<
+ void (const std::string&)
+ , void (const double&) // Overload 1st param type.
+ , void (const double&, const char*) // Overload giving default param.
+ , int (int, int) // Overload giving 2 params (from function pointer).
+ > print(print_string, print_double, print_double, print_add);
+
+ std::vector<std::string> s(3);
+ s[0] = "ab"; s[1] = "cd"; s[2] = "ef";
+ std::for_each(s.begin(), s.end(), print); // Call `print_string` 1-param.
+
+ std::vector<double> d(2);
+ d[0] = 1.2; d[1] = 3.4;
+ std::for_each(d.begin(), d.end(), print); // Call `print_double` 1-param.
+
+ print(-1.234, " (real)"); // Call `print_double` 2-params.
+
+ std::cout << print(2, 3) << std::endl; // Call `print_add`.
+
+ return 0;
+}
+//]
+
Added: sandbox/local/libs/local/example/overload_va.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/overload_va.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,61 @@
+
+#include <boost/config.hpp>
+#if defined(BOOST_NO_VARIADIC_MACROS) || defined(BOOST_LOCAL_CONFIG_COMPLIANT)
+#include <iostream>
+int main() {
+ std::cerr << "Error: This program requires variadic macros" << std::endl;
+ return 0;
+}
+#else
+
+//[overload_va_cpp
+#include <boost/local/function/overload.hpp> // Include header for overloading.
+#include <boost/local/function.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include <string>
+
+int print_add(int x, int y) {
+ std::cout << x << " + " << y << " = ";
+ return x + y;
+}
+
+int main() {
+ char sep = '\n';
+
+ void BOOST_LOCAL_FUNCTION_PARAMS(const std::string& item,
+ const bind& sep) {
+ std::cout << item << " (string)" << sep;
+ } BOOST_LOCAL_FUNCTION_NAME(print_string)
+
+ void BOOST_LOCAL_FUNCTION_PARAMS(const double& item,
+ const char* name, default " (double)", const bind& sep) {
+ std::cout << item << name << sep;
+ } BOOST_LOCAL_FUNCTION_NAME(print_double)
+
+ boost::local::function::overload<
+ void (const std::string&)
+ , void (const double&) // Overload 1st param type.
+ , void (const double&, const char*) // Overload giving default param.
+ , int (int, int) // Overload giving 2 params (from function pointer).
+ > print(print_string, print_double, print_double, print_add);
+
+ std::vector<std::string> s(3);
+ s[0] = "ab"; s[1] = "cd"; s[2] = "ef";
+ std::for_each(s.begin(), s.end(), print); // Call `print_string` 1-param.
+
+ std::vector<double> d(2);
+ d[0] = 1.2; d[1] = 3.4;
+ std::for_each(d.begin(), d.end(), print); // Call `print_double` 1-param.
+
+ print(-1.234, " (real)"); // Call `print_double` 2-params.
+
+ std::cout << print(2, 3) << std::endl; // Call `print_add`.
+
+ return 0;
+}
+//]
+
+#endif
+
Added: sandbox/local/libs/local/example/p12.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p12.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,27 @@
+
+//#include <boost/local/fuction.hpp>
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include <boost/preprocessor.hpp>
+
+#define P(params, body)
+
+A(bc) X(yz) --> W(bc, yz)
+
+int main() {
+ void P( (types(const double&, const std::string&) num) (int x), {
+ std::cout << num << std::endl;
+ }) N(l)
+
+ std::vector<double> v(3);
+ v[0] = -1.0; v[1] = -2.0; v[2] = -3.0;
+ std::for_each(v.begin(), v.end(), l);
+
+ std::vector<std::string> s(3);
+ s[0] = "aa"; s[1] = "bb"; s[2] = "cc";
+ std::for_each(s.begin(), s.end(), l);
+
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/p13.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p13.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,75 @@
+
+#include <iostream>
+#include <vector>
+#include <algorithm>
+
+template<typename T1 = void, typename T2 = void, typename T3 = void>
+struct types {};
+
+template<typename F>
+struct func {};
+
+template<typename R, typename A1>
+struct func<R (A1)> {
+ typedef R (*call_ptr)(void*, A1);
+ func(void* obj, call_ptr call): obj_(obj), call_(call) {}
+ R operator()(A1 a1) { return call_(obj_, a1); }
+private:
+ void* obj_;
+ call_ptr call_;
+};
+
+template<typename R, typename A1T1, typename A1T2>
+struct func<R (types<A1T1, A1T2>)> {
+ typedef R (*call_a1t1_ptr)(void*, A1T1);
+ typedef R (*call_a1t2_ptr)(void*, A1T2);
+ func(void* obj, call_a1t1_ptr call_a1t1, call_a1t2_ptr call_a1t2):
+ obj_(obj), call_a1t1_(call_a1t1), call_a1t2_(call_a1t2) {}
+ R operator()(A1T1 a1t1) { return call_a1t1_(obj_, a1t1); }
+ R operator()(A1T2 a1t2) { return call_a1t2_(obj_, a1t2); }
+private:
+ void* obj_;
+ call_a1t1_ptr call_a1t1_;
+ call_a1t2_ptr call_a1t2_;
+};
+
+int main() {
+// void BOOST_LOCAL_FUNCTION(types(const double&, const std::string&) num,
+// const bind& sep, {
+// std::cout << num << std::endl;
+// }) BOOST_LOCAL_FUNCTION_NAME(l)
+
+ char sep = '\n';
+
+ struct local {
+ local(const char& sep): sep_(sep) {}
+ void operator()(double num) { body(sep_, num); }
+ static void call(void* obj, double num)
+ { (*static_cast<local*>(obj))(num); }
+
+ void operator()(std::string num) { body(sep_, num); }
+ static void call(void* obj, std::string num)
+ { (*static_cast<local*>(obj))(num); }
+ private:
+ const char& sep_;
+ void body(const char& sep, double num)
+ { std::cout << num << std::endl; }
+ void body(const char& sep, std::string num)
+ { std::cout << num << std::endl; }
+ } local_l(sep);
+ func<void (types<double, std::string>)> l(&local_l,
+ local_l.call, local_l.call);
+
+ std::vector<double> v(3);
+ v[0] = -1.0; v[1] = -2.0; v[2] = -3.0;
+ std::for_each(v.begin(), v.end(), l);
+ l(0);
+
+ std::vector<std::string> s(3);
+ s[0] = "aa"; s[1] = "bb"; s[2] = "cc";
+ std::for_each(s.begin(), s.end(), l);
+ l("zz");
+
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/p20.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p20.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,57 @@
+
+#include <string>
+
+std::string A(size_t arity, size_t type) {
+ return std::string("A") +
+}
+
+R operator()(A1T1);
+R operator()(A1T2);
+R operator()(A1T3);
+
+R operator()(A1T1, A2T1);
+R operator()(A1T1, A2T2);
+R operator()(A1T1, A2T3);
+//
+R operator()(A1T2, A2T1);
+R operator()(A1T2, A2T2);
+R operator()(A1T2, A2T3);
+//
+R operator()(A1T3, A2T1);
+R operator()(A1T3, A2T2);
+R operator()(A1T3, A2T3);
+
+template<R, typename A0T0, typename A0T1, typename A1T0, typename A1T1, typename A2T0> {
+} class function<
+ R (types<A0T0, A0T1>, types<A1T0, A1T1>, A2T0), 1
+> {
+ typedef void* object_ptr;
+ typedef R (*call_ptr)(object_ptr
+ , typename ::boost::call_tratis<A0T0>::param_type
+ , typename ::boost::call_tratis<A1T0>::param_type
+ , typename ::boost::call_tratis<A2T0>::param_type);
+ typedef R (*call_ptr)(object_ptr
+ , typename ::boost::call_tratis<A0T1>::param_type
+ , typename ::boost::call_tratis<A1T0>::param_type
+ , typename ::boost::call_tratis<A2T0>::param_type);
+};
+
+
+int main() {
+ size_t arity = 5;
+ size_t types = 3;
+ size_t defaults = 0;
+
+ for (a = 0; a < arity; ++a) {
+ for (t = 0; t < types; ++t) {
+ for (d = 0; d < defaults; ++d) {
+ std::cout <<
+"R operator()(A)
+
+ }
+ }
+ }
+
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/p21.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p21.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,16 @@
+
+#include <boost/preprocessor.hpp>
+
+for t in range(types):
+ for u in range(types):
+ for v in range(types):
+ print t, u, v, w
+
+#define Y(z, n, u) \
+
+#define X(z, n, u) \
+ BOOST_PP_REPEAT_ ## a(2, Y, ~)
+
+BOOST_PP_REPEAT(2, X, ~)
+
+
Added: sandbox/local/libs/local/example/p21.py
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p21.py 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,28 @@
+
+import itertools
+
+def AT(n, t): return "A" + str(n) + "T" + str(t)
+
+arity = 3
+types = 2
+
+l = []
+for n in range(0, arity):
+ for t in range(0, types):
+ l.append(AT(n, t))
+
+print l
+for s in itertools.combinations(l, 3):
+ print s
+
+for t in range(types):
+ for u in range(types):
+ for v in range(types):
+ for w in range(types):
+ print t, u, v, w
+
+print
+
+for i in range(arity):
+ print i
+
Added: sandbox/local/libs/local/example/p22.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p22.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,5 @@
+
+#include <boost/preprocessor.hpp>
+
+BOOST_PP_REPEAT_FROM_TO(0, 3, X
+
Added: sandbox/local/libs/local/example/p30.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p30.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,50 @@
+
+#include <boost/local/function.hpp>
+#include <boost/function.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include <string>
+
+template<typename F0, typename F1, typename F2 = void, typename F3 = void>
+struct overload {
+};
+
+template<typename F0R, typename F0A0, typename F1R, typename F1A0>
+struct overload<F0R (F0A0), F1R (F1A0)> {
+ overload(boost::function<F0R (F0A0)> f0, boost::function<F1R (F1A0)> f1):
+ f0_(f0), f1_(f1) {}
+ F0R operator()(F0A0 a0) const { return f0_(a0); }
+ F1R operator()(F1A0 a0) const { return f1_(a0); }
+private:
+ boost::function<F0R (F0A0)> f0_;
+ boost::function<F1R (F1A0)> f1_;
+};
+
+// More specializations to overload also with F2, F3, etc.
+
+int main() {
+ char sep = '\n';
+
+ void BOOST_LOCAL_FUNCTION_PARAMS(const double& num, const bind& sep) {
+ std::cout << num << sep;
+ } BOOST_LOCAL_FUNCTION_NAME(print_d)
+
+ void BOOST_LOCAL_FUNCTION_PARAMS(const std::string& num, const bind& sep) {
+ std::cout << num << sep;
+ } BOOST_LOCAL_FUNCTION_NAME(print_s)
+
+ overload<void (const double&), void (const std::string&)> print(
+ print_d, print_s);
+
+ std::vector<double> d(2);
+ d[0] = 1.2; d[1] = 3.4;
+ std::for_each(d.begin(), d.end(), print);
+
+ std::vector<std::string> s(3);
+ s[0] = "ab"; s[1] = "cd"; s[2] = "ef";
+ std::for_each(s.begin(), s.end(), print);
+
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/p31.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p31.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,47 @@
+
+#include <boost/local/function.hpp>
+#include <boost/function.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include <string>
+
+template<typename F, typename G>
+struct overloader {
+ overloader(F f, G g): f_(f), g_(g) {}
+ template<typename A0>
+ void operator()(A0 a0) const { return f_(a0); }
+ template<typename A0>
+ void operator()(A0 a0) const { return g_(a0); }
+private:
+ F f_;
+ G g_;
+};
+
+template<typename F, typename G>
+overloader<F, G> overload(F f, G g) { return overloader<F, G>(f, g); }
+
+int main() {
+ char sep = '\n';
+ void BOOST_LOCAL_FUNCTION_PARAMS(const double& num, const bind& sep) {
+ std::cout << num << sep;
+ } BOOST_LOCAL_FUNCTION_NAME(print_d)
+ void BOOST_LOCAL_FUNCTION_PARAMS(const std::string& num, const bind& sep) {
+ std::cout << num << sep;
+ } BOOST_LOCAL_FUNCTION_NAME(print_s)
+// overloader<void (const double&), void (const std::string&)> print_ds(
+// print_d, print_s);
+ __typeof__(overload(print_d, print_s)) print = overload(print_d, print_s);
+
+
+ std::vector<double> d(2);
+ d[0] = 1.2; d[1] = 3.4;
+ std::for_each(d.begin(), d.end(), print);
+
+ std::vector<std::string> s(3);
+ s[0] = "ab"; s[1] = "cd"; s[2] = "ef";
+ std::for_each(s.begin(), s.end(), print);
+
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/p34.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p34.cpp 2011-05-09 12:52:19 EDT (Mon, 09 May 2011)
@@ -0,0 +1,70 @@
+
+#include <boost/local/function.hpp>
+#include <boost/function.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include <string>
+
+namespace boost { namespace local { namespace function {
+
+template<typename F0, typename F1, typename F2 = void, typename F3 = void>
+struct overloaded {};
+
+// Specialization for 2 functions.
+
+template<typename F0, typename F1>
+struct overloaded<F0, F1>: F0, F1 {
+ overloaded(F0 const& f0, F1 const& f1):
+ F0(f0), F1(f1) {}
+ using F0::operator(); using F1::operator();
+};
+
+template<typename F0, typename F1>
+overloaded<F0, F1> overload(F0 const& f0, F1 const& f1) {
+ return overloaded< F0, F1 >(f0, f1);
+}
+
+template<typename F0, typename F1>
+overloaded< boost::function<F0>, boost::function<F1> >
+overload(
+ boost::local::aux::function<F0> const& f0
+ , boost::local::aux::function<F1> const& f1
+) {
+ return overloaded< boost::function<F0>, boost::function<F1> >(f0, f1);
+}
+
+}}} // namespace boost::local::function
+
+// More specializations to overload also with F2, F3, etc.
+
+int main() {
+ char sep = '\n';
+
+ void BOOST_LOCAL_FUNCTION_PARAMS(const double& item, int x, default 1, const bind& sep) {
+ std::cout << item << sep;
+ } BOOST_LOCAL_FUNCTION_NAME(print_double)
+
+ void BOOST_LOCAL_FUNCTION_PARAMS(const std::string& item, const bind& sep) {
+ std::cout << item << sep;
+ } BOOST_LOCAL_FUNCTION_NAME(print_string)
+
+ boost::local::function::overloaded<
+ boost::function< void (const double&) >
+ , boost::function< void (const std::string&) >
+ > print = boost::local::function::overload(
+ boost::function< void (const double&) >(print_double)
+ , boost::function< void (const std::string&) >(print_string)
+ );
+
+ std::vector<double> d(2);
+ d[0] = 1.2; d[1] = 3.4;
+ std::for_each(d.begin(), d.end(), print);
+
+ std::vector<std::string> s(3);
+ s[0] = "ab"; s[1] = "cd"; s[2] = "ef";
+ std::for_each(s.begin(), s.end(), print);
+
+ return 0;
+}
+
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