|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71543 - sandbox/local/libs/local/example
From: lorcaminiti_at_[hidden]
Date: 2011-04-27 14:01:31
Author: lcaminiti
Date: 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
New Revision: 71543
URL: http://svn.boost.org/trac/boost/changeset/71543
Log:
Cleaned up example dir.
Added:
sandbox/local/libs/local/example/add_function_inline.cpp (contents, props changed)
sandbox/local/libs/local/example/add_function_inline_va.cpp (contents, props changed)
Removed:
sandbox/local/libs/local/example/benchmark_boost_lambda.cpp
sandbox/local/libs/local/example/benchmark_boost_local.cpp
sandbox/local/libs/local/example/benchmark_boost_phoenix.00.cpp
sandbox/local/libs/local/example/benchmark_boost_phoenix.cpp
sandbox/local/libs/local/example/benchmark_cpp0x_lambda.cpp
sandbox/local/libs/local/example/benchmark_global_functor.cpp
sandbox/local/libs/local/example/benchmark_local_functor.cpp
sandbox/local/libs/local/example/bmc_local.cpp
sandbox/local/libs/local/example/bmc_phoenix.cpp
sandbox/local/libs/local/example/cg00.cpp
sandbox/local/libs/local/example/cl00.cpp
sandbox/local/libs/local/example/gred_add01.cpp
sandbox/local/libs/local/example/l00.cpp
sandbox/local/libs/local/example/l01.cpp
sandbox/local/libs/local/example/l02.cpp
sandbox/local/libs/local/example/l03.cpp
sandbox/local/libs/local/example/l04.cpp
sandbox/local/libs/local/example/l05.cpp
sandbox/local/libs/local/example/l06.cpp
sandbox/local/libs/local/example/l07.cpp
sandbox/local/libs/local/example/l08.cpp
sandbox/local/libs/local/example/l09.cpp
sandbox/local/libs/local/example/l10.cpp
sandbox/local/libs/local/example/optim.02.cpp
sandbox/local/libs/local/example/optim.03.cpp
sandbox/local/libs/local/example/optim.04.cpp
sandbox/local/libs/local/example/optim.05.cpp
sandbox/local/libs/local/example/optim.06.cpp
sandbox/local/libs/local/example/p00.cpp
sandbox/local/libs/local/example/tom_add_boost_local.cpp
sandbox/local/libs/local/example/tom_add_boost_phoenix.cpp
sandbox/local/libs/local/example/tom_local.cpp
sandbox/local/libs/local/example/tom_phoenix.cpp
sandbox/local/libs/local/example/tparam_trick.00.cpp
sandbox/local/libs/local/example/tparam_trick.01.cpp
sandbox/local/libs/local/example/tparam_trick.02.cpp
sandbox/local/libs/local/example/tparam_trick.03.cpp
sandbox/local/libs/local/example/tparam_trick.04.cpp
sandbox/local/libs/local/example/tparam_trick.05.cpp
sandbox/local/libs/local/example/tparam_trick.06.cpp
sandbox/local/libs/local/example/tparam_trick.07.cpp
sandbox/local/libs/local/example/tparam_trick.08.cpp
sandbox/local/libs/local/example/tparam_trick.09.cpp
sandbox/local/libs/local/example/tparam_trick.10.cpp
Text files modified:
sandbox/local/libs/local/example/add_using_global_functor.cpp | 4 ++--
sandbox/local/libs/local/example/add_using_local_functor.cpp | 4 ++--
sandbox/local/libs/local/example/chrono.py | 3 +--
sandbox/local/libs/local/example/profile_global_functor.cpp | 8 ++++----
sandbox/local/libs/local/example/profile_local_functor.cpp | 6 +++---
sandbox/local/libs/local/example/tparam_trick.cpp | 6 +++---
6 files changed, 15 insertions(+), 16 deletions(-)
Added: sandbox/local/libs/local/example/add_function_inline.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/add_function_inline.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
@@ -0,0 +1,41 @@
+
+// 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).
+
+//[ add_function_inline_cpp
+#include <boost/local/function.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+
+int main() {
+ double sum = 0.0;
+ int factor = 10;
+
+ void BOOST_LOCAL_FUNCTION_PARAMS( (double num) (const bind factor)
+ (bind& sum) ) {
+ sum += factor * num;
+ } BOOST_LOCAL_FUNCTION_NAME(inline add) // inlined local function
+
+ std::vector<double> v(1000000);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ // On some compiler (e.g., GCC) inlined local functions are more likely to
+ // be optimized for faster run-times. However, inlined local functions
+ // cannot be passed at template parameters (i.e., `std::for_each` cannot be
+ // used here).
+ // On C++03 compilers (e.g., MSVC or GCC 4.5) linining has no effect
+ // because the local function can always be optimized even if not
+ // explicitly specified inline and inlined local functions can be always be
+ // passed as template paramters.
+ for (size_t i = 0; i < v.size(); ++i) { // Can't use for_each (portably).
+ add(v[i]);
+ }
+
+ std::cout << sum << std::endl;
+ return 0;
+}
+//]
+
Added: sandbox/local/libs/local/example/add_function_inline_va.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/add_function_inline_va.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
@@ -0,0 +1,52 @@
+
+// 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/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
+
+//[ add_function_inline_va_cpp
+#include <boost/local/function.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+
+int main() {
+ double sum = 0.0;
+ int factor = 10;
+
+ void BOOST_LOCAL_FUNCTION_PARAMS(double num, const bind factor,
+ bind& sum) {
+ sum += factor * num;
+ } BOOST_LOCAL_FUNCTION_NAME(inline add) // inlined local function
+
+ std::vector<double> v(1000000);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ // On some compiler (e.g., GCC) inlined local functions are more likely to
+ // be optimized for faster run-times. However, inlined local functions
+ // cannot be passed at template parameters (i.e., `std::for_each` cannot be
+ // used here).
+ // On C++03 compilers (e.g., MSVC or GCC 4.5) linining has no effect
+ // because the local function can always be optimized even if not
+ // explicitly specified inline and inlined local functions can be always be
+ // passed as template paramters.
+ for (size_t i = 0; i < v.size(); ++i) { // Can't use for_each (portably).
+ add(v[i]);
+ }
+
+ std::cout << sum << std::endl;
+ return 0;
+}
+//]
+
+#endif
+
Modified: sandbox/local/libs/local/example/add_using_global_functor.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_using_global_functor.cpp (original)
+++ sandbox/local/libs/local/example/add_using_global_functor.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
@@ -14,7 +14,7 @@
struct global_add { // Unfortunately, boilerplate code to program the class.
global_add(double& _sum, int _factor): sum(_sum), factor(_factor) {}
- void operator()(double num) {
+ inline void operator()(double num) {
// Body uses C++ statement syntax.
sum += factor * num;
std::cout << "Summed: " << sum << std::endl;
@@ -23,7 +23,7 @@
private:
// Unfortunately, cannot bind so repeat variable types.
double& sum; // Access `sum` by reference.
- const int factor; // Make `factor` constant.
+ const int& factor; // Make `factor` constant.
};
int main() {
Modified: sandbox/local/libs/local/example/add_using_local_functor.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_using_local_functor.cpp (original)
+++ sandbox/local/libs/local/example/add_using_local_functor.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
@@ -19,7 +19,7 @@
struct local_add { // Unfortunately, boilerplate code to program the class.
local_add(double& _sum, int _factor): sum(_sum), factor(_factor) {}
- void operator()(double num) { // Body uses C++ statement syntax.
+ inline void operator()(double num) { // Body uses C++ statement syntax.
sum += factor * num;
std::cout << "Summed: " << sum << std::endl;
}
@@ -27,7 +27,7 @@
private:
// Unfortunately, cannot bind so repeat variable types.
double& sum; // Access `sum` by reference.
- const int factor; // Make `factor` constant.
+ const int& factor; // Make `factor` constant.
} add(sum, factor);
// Unfortunately, cannot pass as template parameter to `std::for_each`.
Deleted: sandbox/local/libs/local/example/benchmark_boost_lambda.cpp
==============================================================================
--- sandbox/local/libs/local/example/benchmark_boost_lambda.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,30 +0,0 @@
-
-#include <boost/lambda/lambda.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 1e4
-#define S N * 1e2
-
-int main() {
- using boost::lambda::_1;
-
- double sum = 0.0;
- int factor = 1;
-
- std::vector<double> v(S);
- std::fill(v.begin(), v.end(), 1.0);
-
- for (size_t n = 0; n < N; ++n) {
-// std::for_each(v.begin(), v.end(), (
-// sum += factor * _1
-// ));
- }
-
- std::cout << sum << std::endl;
-// assert(sum == N * S);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/benchmark_boost_local.cpp
==============================================================================
--- sandbox/local/libs/local/example/benchmark_boost_local.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,42 +0,0 @@
-
-#include <boost/chrono.hpp>
-#include <boost/local/function.hpp>
-#include <vector>
-#include <algorithm>
-#include <iostream>
-#include "benchmark_helpers.hpp"
-
-int main(int argc, char* argv[]) {
- boost::chrono::duration<double> sec;
- unsigned long loop; unsigned long size; bool verbose; double n;
- begin(argc, argv, loop, size, verbose, n);
-
- double sum = 0.0;
- int factor = 1;
-
- boost::chrono::system_clock::time_point start =
- boost::chrono::system_clock::now();
- void BOOST_LOCAL_FUNCTION_PARAMS( (const double& num)
- (bind& sum) (const bind& factor) ) {
- sum += factor * num;
- } BOOST_LOCAL_FUNCTION_NAME(add)
- sec += boost::chrono::system_clock::now() - start;
- if (verbose) {
- std::clog << "declaration run-time = " << sec.count() << "s" <<
- std::endl;
- }
-
- std::vector<double> v(size);
- std::fill(v.begin(), v.end(), 1.0);
-
- for (unsigned long i = 0; i < loop; ++i) {
- boost::chrono::system_clock::time_point start =
- boost::chrono::system_clock::now();
- std::for_each(v.begin(), v.end(), add);
- sec += boost::chrono::system_clock::now() - start;
- }
-
- end(verbose, n, sum, sec);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/benchmark_boost_phoenix.00.cpp
==============================================================================
--- sandbox/local/libs/local/example/benchmark_boost_phoenix.00.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,52 +0,0 @@
-
-#include <boost/spirit/include/phoenix.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 1e4
-#define S N * 1e2
-
-template<typename T>
-struct number_interface {
- virtual T complement(T x) = 0;
-};
-
-template<typename T>
-struct number: number_interface<T> {
- T complement(T x) { return -x; }
-};
-
-const double& identity(const double& x) { return x; }
-
-int main() {
- using boost::phoenix::let;
- using boost::phoenix::ref;
- using boost::phoenix::cref;
- using boost::phoenix::arg_names::_1;
- using boost::phoenix::local_names::_f;
- using boost::phoenix::local_names::_x;
- using boost::phoenix::bind;
-
- double sum = 0.0;
- int factor = 1;
- const double& (*p)(const double&) = &identity;
- number<double> d;
-
- std::vector<double> v(S);
- std::fill(v.begin(), v.end(), 1.0);
-
- for (size_t n = 0; n < N; ++n) {
- std::for_each(v.begin(), v.end(), let(_f = cref(factor), _x = 0.0)[
- _x = _f * bind(&identity, _1),
- _x = -bind(&number<double>::complement, d, _x),
- ref(sum) += bind(p, _x)
- ]);
- }
-
- std::cout << sum << std::endl;
- assert(sum == N * S);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/benchmark_boost_phoenix.cpp
==============================================================================
--- sandbox/local/libs/local/example/benchmark_boost_phoenix.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,31 +0,0 @@
-
-#include <boost/spirit/include/phoenix.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 1e4
-#define S N * 1e2
-
-int main() {
- using boost::phoenix::ref;
- using boost::phoenix::arg_names::_1;
-
- double sum = 0.0;
- int factor = 1;
-
- std::vector<double> v(S);
- std::fill(v.begin(), v.end(), 1.0);
-
- for (size_t n = 0; n < N; ++n) {
- std::for_each(v.begin(), v.end(), (
- ref(sum) += factor * _1
- ));
- }
-
- std::cout << sum << std::endl;
- assert(sum == N * S);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/benchmark_cpp0x_lambda.cpp
==============================================================================
--- sandbox/local/libs/local/example/benchmark_cpp0x_lambda.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,24 +0,0 @@
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-#define N 10000
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(N * 100);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
- std::for_each(v.begin(), v.end(), [&sum, factor](double num) {
- sum += factor * num;
- });
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/benchmark_global_functor.cpp
==============================================================================
--- sandbox/local/libs/local/example/benchmark_global_functor.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,37 +0,0 @@
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 1e4
-#define S N * 1e2
-
-struct global_add {
- global_add(double& _sum, int _factor): sum(_sum), factor(_factor) {}
- void operator()(const double& num) {
- sum += factor * num;
- }
-private:
- double& sum;
- const int factor;
-};
-
-int main() {
- double sum = 0.0;
- int factor = 1;
-
- std::vector<double> v(S);
- std::fill(v.begin(), v.end(), 1.0);
-
- global_add add(sum, factor);
-
- for (size_t n = 0; n < N; ++n) {
-// std::for_each(v.begin(), v.end(), add);
- }
-
- std::cout << sum << std::endl;
-// assert(sum == N * S);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/benchmark_local_functor.cpp
==============================================================================
--- sandbox/local/libs/local/example/benchmark_local_functor.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,36 +0,0 @@
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cmath>
-#include <cassert>
-
-int main(int argc, char* argv[]) {
- assert(argc == 2);
- unsigned long n = sqrt(double(atol(argv[1])));
-
- double sum = 0.0;
- int factor = 1;
-
- struct local_add {
- local_add(double& _sum, int _factor): sum(_sum), factor(_factor) {}
- void operator()(const double& num) {
- sum += factor * num;
- }
- private:
- double& sum;
- const int factor;
- };
- local_add add(sum, factor);
-
- std::vector<double> v(n);
- std::fill(v.begin(), v.end(), 1.0);
- for (unsigned long i = 0; i < n; ++i) {
-// for (size_t j = 0; j < v.size(); ++j) add(v[j]); // Can't use for_each.
- }
-
- std::cout << sum << std::endl;
-// assert(sum == n * n);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/bmc_local.cpp
==============================================================================
--- sandbox/local/libs/local/example/bmc_local.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,33 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-#define N 30000
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(N);
- std::fill(v.begin(), v.end(), 10);
-
- void BOOST_LOCAL_FUNCTION_PARAMS( (double num)
- (bind& sum) (const bind factor)
- ) {
- sum += factor * num;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- for (size_t n = 0; n < N; ++n) {
- std::for_each(v.begin(), v.end(), add);
-// for (size_t i = 0; i < v.size(); ++i) {
-// sum += factor * v[i];//10;
-// add(v[i]);
-// }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/bmc_phoenix.cpp
==============================================================================
--- sandbox/local/libs/local/example/bmc_phoenix.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,29 +0,0 @@
-
-#include <boost/spirit/include/phoenix.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- using boost::phoenix::let;
- using boost::phoenix::local_names::_f;
- using boost::phoenix::cref;
- using boost::phoenix::ref;
- using boost::phoenix::arg_names::_1;
- using boost::phoenix::val;
-
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
- for (size_t n = 0; n < 10000; ++n) {
- std::for_each(v.begin(), v.end(), (
- ref(sum) += factor * _1
- ));
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/cg00.cpp
==============================================================================
--- sandbox/local/libs/local/example/cg00.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,38 +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>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
- struct global_add {
- global_add(double& _sum, int _factor): sum(_sum), factor(_factor) {}
- void operator()(double num) {
- sum += factor * num;
- }
- private:
- double& sum;
- const int factor;
- };
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
- global_add add(sum, factor);
-
- for(int i = 0; i < 10000; ++i) {
- std::for_each(v.begin(), v.end(), add);
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Modified: sandbox/local/libs/local/example/chrono.py
==============================================================================
--- sandbox/local/libs/local/example/chrono.py (original)
+++ sandbox/local/libs/local/example/chrono.py 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
@@ -4,8 +4,7 @@
import os
cmd = ""
-for arg in sys.argv[1:]:
- cmd += str(arg) + " "
+for arg in sys.argv[1:]: cmd += str(arg) + " "
start = time.time()
ret = os.system(cmd)
Deleted: sandbox/local/libs/local/example/cl00.cpp
==============================================================================
--- sandbox/local/libs/local/example/cl00.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,39 +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>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
- struct local_add {
- local_add(double& _sum, int _factor): sum(_sum), factor(_factor) {}
- void operator()(double num) {
- sum += factor * num;
- }
- private:
- double& sum;
- const int factor;
- };
- local_add add(sum, factor);
-
- for (int i = 0; i < 10000; ++i) {
- for (size_t j = 0; j < v.size(); ++j) {
- add(v[j]);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/gred_add01.cpp
==============================================================================
--- sandbox/local/libs/local/example/gred_add01.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,36 +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).
-
-//[ add_cpp
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
-
- std::fill(v.begin(), v.end(), 10);
-
- void BOOST_LOCAL_FUNCTION_PARAMS( (double& num)
- (const bind& factor) (bind& sum) ) {
- sum += factor * num;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- for(int i = 0; i < 10000; ++i)
- {
- std::for_each(v.begin(), v.end(), add);
- }
-
- std::cout << sum << std::endl;
-
- return 0;
-}
-//]
-
Deleted: sandbox/local/libs/local/example/l00.cpp
==============================================================================
--- sandbox/local/libs/local/example/l00.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,31 +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>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
- void BOOST_LOCAL_FUNCTION_PARAMS( (double num)
- (const bind factor) (bind& sum) ) {
- sum += factor * num;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- for(int i = 0; i < 10000; ++i) {
- std::for_each(v.begin(), v.end(), add);
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/l01.cpp
==============================================================================
--- sandbox/local/libs/local/example/l01.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,68 +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>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
-void (*ERROR_missing_result_type_before_the_local_function_parameter_macro_id20)(); typedef void (*boost_local_auxXdeduce_result_tag20)( int ERROR_missing_result_type_before_the_local_function_parameter_macro_id20); typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref( ERROR_missing_result_type_before_the_local_function_parameter_macro_id20, (boost_local_auxXdeduce_result_tag20)0)))) boost_local_auxXdeduce_result_wrap20; typedef boost_local_auxXdeduce_result_wrap20::type boost_local_auxXdeduce_result_capture20; struct boost_local_auxXdeduce_result_params20 { typedef boost_local_auxXdeduce_result_capture20 function_ptr_type; }; typedef boost::remove_pointer< boost_local_auxXdeduce_result_params20::function_ptr_type >::type boost_local_auxXdeduce_result_function_type20; typedef boost::function_traits< boost_local_auxXdeduce_result_function_type20>::result_type boost_local_auxXresult_type20; typedef void (*boost_se_tag_0_20)(int factor ); typedef void (*boos
t_se_tag_1_20)(int & sum ); typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0)))) boost_se_wrapped_t_0_20; typedef boost_se_wrapped_t_0_20::type boost_se_capture_t_0_20; typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_20)0)))) boost_se_wrapped_t_1_20; typedef boost_se_wrapped_t_1_20::type boost_se_capture_t_1_20; struct boost_se_params_t_20 { typedef boost_se_capture_t_0_20 boost_se_param_t_0_20; typedef boost_se_capture_t_1_20 boost_se_param_t_1_20; boost::scope_exit::aux::member< boost_se_param_t_0_20, boost_se_tag_0_20 > boost_se_param_0_20; boost::scope_exit::aux::member< boost_se_param_t_1_20, boost_se_tag_1_20 > boost_se_param_1_20; } boost_local_auxXparams20 = { { boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0) } , { boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_20)0) } }; boost::scope_exit::aux::declared< boost::scope_
exit::aux::resolve< sizeof(boost_local_auxXargs) >::cmp1<0>::cmp2 > boost_local_auxXargs; boost_local_auxXargs.value = &boost_local_auxXparams20;
-
-
- class boost_local_auxXfunctor20
- //: public ::boost::local::aux::abstract_function< boost_local_auxXresult_type20 ( double num ), 0 >
- {
- typedef boost_local_auxXresult_type20 (boost_local_auxXfunction_type) ( double num );
- public:
- explicit boost_local_auxXfunctor20( void* binding_data, double& _sum, int _factor)
- : boost_local_auxXbinds(static_cast< boost_se_params_t_20*>(binding_data)) , sum_(_sum), factor_(_factor)
- { /*boost_local_auxXinit_recursion();*/ }
-
- boost_local_auxXresult_type20 operator()( ::boost::function_traits< boost_local_auxXfunction_type>::arg1_type arg1 )
- { return boost_local_auxXbody(
- sum_//boost_local_auxXbinds-> boost_se_param_0_20.value
- , boost_local_auxXbinds-> boost_se_param_1_20.value , arg1 );
- }
- private:
-// typedef ::boost::local::function<boost_local_auxXfunction_type, 0 > boost_local_auxXfunctor_type;
-// typedef ::boost::add_const< boost_se_params_t_20:: boost_se_param_t_0_20 >::type factorXboost_local_auxXtypeof_type ;
-// typedef boost_se_params_t_20:: boost_se_param_t_1_20 & sumXboost_local_auxXtypeof_type ;
- boost_se_params_t_20* boost_local_auxXbinds;
- double& sum_;
- const int factor_;
-// boost::scope_exit::aux::undeclared boost_local_auxXargs;
-
- boost_local_auxXresult_type20 boost_local_auxXbody(
- ::boost::add_const< boost_se_params_t_20:: boost_se_param_t_0_20 >::type factor
- , /*boost_se_params_t_20:: boost_se_param_t_1_20*/double & sum , double num ) const {
- sum += factor * num;
- }
-// public:
-// boost_local_auxXfunctor_type add;
-// private:
-// void boost_local_auxXinit_recursion() {
-// //add = *this;
-// }
- } boost_local_auxXfunctorXadd( boost_local_auxXargs.value, sum, factor);
- // __typeof__(boost::type_of::ensure_obj(boost_local_auxXfunctorXadd.add)) const add(boost_local_auxXfunctorXadd);
-
- for(int i = 0; i < 10000; ++i) {
- for(size_t j = 0; j < v.size(); ++j) {
- boost_local_auxXfunctorXadd(v[j]);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/l02.cpp
==============================================================================
--- sandbox/local/libs/local/example/l02.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,78 +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>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
-void (*ERROR_missing_result_type_before_the_local_function_parameter_macro_id20)(); typedef void (*boost_local_auxXdeduce_result_tag20)( int ERROR_missing_result_type_before_the_local_function_parameter_macro_id20); typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref( ERROR_missing_result_type_before_the_local_function_parameter_macro_id20, (boost_local_auxXdeduce_result_tag20)0)))) boost_local_auxXdeduce_result_wrap20; typedef boost_local_auxXdeduce_result_wrap20::type boost_local_auxXdeduce_result_capture20; struct boost_local_auxXdeduce_result_params20 { typedef boost_local_auxXdeduce_result_capture20 function_ptr_type; }; typedef boost::remove_pointer< boost_local_auxXdeduce_result_params20::function_ptr_type >::type boost_local_auxXdeduce_result_function_type20; typedef boost::function_traits< boost_local_auxXdeduce_result_function_type20>::result_type boost_local_auxXresult_type20; typedef void (*boost_se_tag_0_20)(int factor ); typedef void (*boos
t_se_tag_1_20)(int & sum ); typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0)))) boost_se_wrapped_t_0_20; typedef boost_se_wrapped_t_0_20::type boost_se_capture_t_0_20; typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_20)0)))) boost_se_wrapped_t_1_20; typedef boost_se_wrapped_t_1_20::type boost_se_capture_t_1_20; struct boost_se_params_t_20 { typedef boost_se_capture_t_0_20 boost_se_param_t_0_20; typedef boost_se_capture_t_1_20 boost_se_param_t_1_20; boost::scope_exit::aux::member< boost_se_param_t_0_20, boost_se_tag_0_20 > boost_se_param_0_20; boost::scope_exit::aux::member< boost_se_param_t_1_20, boost_se_tag_1_20 > boost_se_param_1_20; } boost_local_auxXparams20 = { { boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0) } , { boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_20)0) } }; boost::scope_exit::aux::declared< boost::scope_
exit::aux::resolve< sizeof(boost_local_auxXargs) >::cmp1<0>::cmp2 > boost_local_auxXargs; boost_local_auxXargs.value = &boost_local_auxXparams20;
-
-
- class boost_local_auxXfunctor20
- //: public ::boost::local::aux::abstract_function< boost_local_auxXresult_type20 ( double num ), 0 >
- {
- //typedef boost_local_auxXresult_type20 (boost_local_auxXfunction_type) ( double num );
- public:
- explicit boost_local_auxXfunctor20(void* binding_data, double& _sum, int _factor)
- : boost_local_auxXbinds(static_cast< boost_se_params_t_20*>(binding_data)) , sum_(_sum), factor_(_factor)
- {
- /*boost_local_auxXinit_recursion();*/
-// int f = 0;
-// sum_ = boost_local_auxXbinds-> boost_se_param_1_20.value;
- factor_ = boost_local_auxXbinds-> boost_se_param_0_20.value;
- std::cout << factor_ << std::endl;
- }
-
- void operator()( /*::boost::function_traits< boost_local_auxXfunction_type>::arg1_type*/double arg1 )
- { return boost_local_auxXbody(
- //boost_local_auxXbinds-> boost_se_param_0_20.value
- 10//factor_
- ,
- //boost_local_auxXbinds-> boost_se_param_1_20.value
- sum_
- , arg1 );
- }
- private:
-// typedef ::boost::local::function<boost_local_auxXfunction_type, 0 > boost_local_auxXfunctor_type;
-// typedef ::boost::add_const< boost_se_params_t_20:: boost_se_param_t_0_20 >::type factorXboost_local_auxXtypeof_type ;
-// typedef boost_se_params_t_20:: boost_se_param_t_1_20 & sumXboost_local_auxXtypeof_type ;
- boost_se_params_t_20* boost_local_auxXbinds;
- double& sum_;
- int factor_;
-// boost::scope_exit::aux::undeclared boost_local_auxXargs;
-
- void boost_local_auxXbody(
- /*::boost::add_const< boost_se_params_t_20:: boost_se_param_t_0_20 >::type*/const int factor
- , /*boost_se_params_t_20:: boost_se_param_t_1_20*/double & sum , double num ) const {
- sum += factor * num;
- }
-// public:
-// boost_local_auxXfunctor_type add;
-// private:
-// void boost_local_auxXinit_recursion() {
-// //add = *this;
-// }
- } boost_local_auxXfunctorXadd(boost_local_auxXargs.value, sum, factor);
- // __typeof__(boost::type_of::ensure_obj(boost_local_auxXfunctorXadd.add)) const add(boost_local_auxXfunctorXadd);
-
- for(int i = 0; i < 10000; ++i) {
- for(size_t j = 0; j < v.size(); ++j) {
- boost_local_auxXfunctorXadd(v[j]);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/l03.cpp
==============================================================================
--- sandbox/local/libs/local/example/l03.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,52 +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>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
-void (*ERROR_missing_result_type_before_the_local_function_parameter_macro_id20)(); typedef void (*boost_local_auxXdeduce_result_tag20)( int ERROR_missing_result_type_before_the_local_function_parameter_macro_id20); typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref( ERROR_missing_result_type_before_the_local_function_parameter_macro_id20, (boost_local_auxXdeduce_result_tag20)0)))) boost_local_auxXdeduce_result_wrap20; typedef boost_local_auxXdeduce_result_wrap20::type boost_local_auxXdeduce_result_capture20; struct boost_local_auxXdeduce_result_params20 { typedef boost_local_auxXdeduce_result_capture20 function_ptr_type; }; typedef boost::remove_pointer< boost_local_auxXdeduce_result_params20::function_ptr_type >::type boost_local_auxXdeduce_result_function_type20; typedef boost::function_traits< boost_local_auxXdeduce_result_function_type20>::result_type boost_local_auxXresult_type20; typedef void (*boost_se_tag_0_20)(int factor ); typedef void (*boos
t_se_tag_1_20)(int & sum ); typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0)))) boost_se_wrapped_t_0_20; typedef boost_se_wrapped_t_0_20::type boost_se_capture_t_0_20; typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_20)0)))) boost_se_wrapped_t_1_20; typedef boost_se_wrapped_t_1_20::type boost_se_capture_t_1_20; struct boost_se_params_t_20 { typedef boost_se_capture_t_0_20 boost_se_param_t_0_20; typedef boost_se_capture_t_1_20 boost_se_param_t_1_20; boost::scope_exit::aux::member< boost_se_param_t_0_20, boost_se_tag_0_20 > boost_se_param_0_20; boost::scope_exit::aux::member< boost_se_param_t_1_20, boost_se_tag_1_20 > boost_se_param_1_20; } boost_local_auxXparams20 = { { boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0) } , { boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_20)0) } }; boost::scope_exit::aux::declared< boost::scope_
exit::aux::resolve< sizeof(boost_local_auxXargs) >::cmp1<0>::cmp2 > boost_local_auxXargs; boost_local_auxXargs.value = &boost_local_auxXparams20;
-
- std::cout << boost_local_auxXparams20.boost_se_param_0_20.value << std::endl;
-
- class boost_local_auxXfunctor20 {
- public:
- explicit boost_local_auxXfunctor20(double& _sum, int _factor):
- sum_(_sum), factor_(_factor) {
- }
- void operator()(double num) {
- return boost_local_auxXbody(factor_, sum_, num);
- }
- private:
- boost_se_params_t_20* boost_local_auxXbinds;
- double& sum_;
- int factor_;
-
- void boost_local_auxXbody(const int factor, double & sum, double num)
- const {
- sum += factor * num;
- }
- } boost_local_auxXfunctorXadd(boost_local_auxXargs.value, sum, factor);
-
-
- for(int i = 0; i < 10000; ++i) {
- for(size_t j = 0; j < v.size(); ++j) {
- boost_local_auxXfunctorXadd(v[j]);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/l04.cpp
==============================================================================
--- sandbox/local/libs/local/example/l04.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,51 +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>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
-
-void (*ERROR_missing_result_type_before_the_local_function_parameter_macro_id20)(); typedef void (*boost_local_auxXdeduce_result_tag20)( int ERROR_missing_result_type_before_the_local_function_parameter_macro_id20); typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref( ERROR_missing_result_type_before_the_local_function_parameter_macro_id20, (boost_local_auxXdeduce_result_tag20)0)))) boost_local_auxXdeduce_result_wrap20; typedef boost_local_auxXdeduce_result_wrap20::type boost_local_auxXdeduce_result_capture20; struct boost_local_auxXdeduce_result_params20 { typedef boost_local_auxXdeduce_result_capture20 function_ptr_type; }; typedef boost::remove_pointer< boost_local_auxXdeduce_result_params20::function_ptr_type >::type boost_local_auxXdeduce_result_function_type20; typedef boost::function_traits< boost_local_auxXdeduce_result_function_type20>::result_type boost_local_auxXresult_type20; typedef void (*boost_se_tag_0_20)(int factor ); typedef void (*boos
t_se_tag_1_20)(int & sum ); typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0)))) boost_se_wrapped_t_0_20; typedef boost_se_wrapped_t_0_20::type boost_se_capture_t_0_20; typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_20)0)))) boost_se_wrapped_t_1_20; typedef boost_se_wrapped_t_1_20::type boost_se_capture_t_1_20; struct boost_se_params_t_20 { typedef boost_se_capture_t_0_20 boost_se_param_t_0_20; typedef boost_se_capture_t_1_20 boost_se_param_t_1_20; boost::scope_exit::aux::member< boost_se_param_t_0_20, boost_se_tag_0_20 > boost_se_param_0_20; boost::scope_exit::aux::member< boost_se_param_t_1_20, boost_se_tag_1_20 > boost_se_param_1_20; } boost_local_auxXparams20 = { { boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0) } , { boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_20)0) } }; boost::scope_exit::aux::declared< boost::scope_
exit::aux::resolve< sizeof(boost_local_auxXargs) >::cmp1<0>::cmp2 > boost_local_auxXargs; boost_local_auxXargs.value = &boost_local_auxXparams20;
-
- std::cout << boost_local_auxXparams20.boost_se_param_0_20.value << std::endl;
-
- class local_add {
- public:
- explicit local_add(double& _sum, int _factor):
- sum_(_sum), factor_(_factor) {
- }
- void operator()(double num) {
- return body(factor_, sum_, num);
- }
- private:
- double& sum_;
- int factor_;
-
- void body(const int factor, double& sum, double num)
- const {
- sum += factor * num;
- }
- } add(sum, factor);
-
- for (size_t i = 0; i < 10000; ++i) {
- for (size_t j = 0; j < v.size(); ++j) {
- add(v[j]);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/l05.cpp
==============================================================================
--- sandbox/local/libs/local/example/l05.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,80 +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>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
-
- //void (*ERROR_missing_result_type_before_the_local_function_parameter_macro_id20)(); typedef void (*boost_local_auxXdeduce_result_tag20)( int ERROR_missing_result_type_before_the_local_function_parameter_macro_id20); typedef __typeof__(boost::type_of::ensure_obj(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref( ERROR_missing_result_type_before_the_local_function_parameter_macro_id20, (boost_local_auxXdeduce_result_tag20)0)))) boost_local_auxXdeduce_result_wrap20; typedef boost_local_auxXdeduce_result_wrap20::type boost_local_auxXdeduce_result_capture20; struct boost_local_auxXdeduce_result_params20 { typedef boost_local_auxXdeduce_result_capture20 function_ptr_type; }; typedef boost::remove_pointer< boost_local_auxXdeduce_result_params20::function_ptr_type >::type boost_local_auxXdeduce_result_function_type20; typedef boost::function_traits< boost_local_auxXdeduce_result_function_type20>::result_type boost_local_auxXresult_type20;
-
- typedef void (*boost_se_tag_0_20)(int factor);
-// typedef void (*boost_se_tag_1_20)(int & sum);
-
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap(
- boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0)))
- boost_se_wrapped_t_0_20;
- typedef boost_se_wrapped_t_0_20::type boost_se_capture_t_0_20;
-
-// typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap(
-// boost::scope_exit::aux::deref(&sum, (boost_se_tag_1_20)0)))
-// boost_se_wrapped_t_1_20;
-// typedef boost_se_wrapped_t_1_20::type boost_se_capture_t_1_20;
-
- struct boost_se_params_t_20 {
- typedef boost_se_capture_t_0_20 boost_se_param_t_0_20;
-// typedef boost_se_capture_t_1_20 boost_se_param_t_1_20;
-
- boost::scope_exit::aux::member<boost_se_param_t_0_20,
- boost_se_tag_0_20> boost_se_param_0_20;
-// boost::scope_exit::aux::member<boost_se_param_t_1_20,
-// boost_se_tag_1_20> boost_se_param_1_20;
- } boost_local_auxXparams20 = {
- { boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0) }
-// , { boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_20)0) }
- };
- boost::scope_exit::aux::declared<boost::scope_exit::aux::resolve<
- sizeof(boost_local_auxXargs)>::cmp1<0>::cmp2> boost_local_auxXargs;
- boost_local_auxXargs.value = &boost_local_auxXparams20;
-
- std::cout << boost_local_auxXparams20.boost_se_param_0_20.value << std::endl;
-
- class local_add {
- public:
- explicit local_add(double& _sum, int _factor):
- sum_(_sum), factor_(_factor) {
- }
- void operator()(double num) {
- return body(factor_, sum_, num);
- }
- private:
- double& sum_;
- int factor_;
-
- void body(const int factor, double& sum, double num)
- const {
- sum += factor * num;
- }
- } add(sum, factor);
-
- for (size_t i = 0; i < 10000; ++i) {
- for (size_t j = 0; j < v.size(); ++j) {
- add(v[j]);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/l06.cpp
==============================================================================
--- sandbox/local/libs/local/example/l06.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,66 +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>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
- typedef void (*boost_se_tag_0_20)(int factor);
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap(
- boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0)))
- boost_se_wrapped_t_0_20;
- typedef boost_se_wrapped_t_0_20::type boost_se_capture_t_0_20;
-
- struct boost_se_params_t_20 {
- typedef boost_se_capture_t_0_20 boost_se_param_t_0_20;
-
- boost::scope_exit::aux::member<boost_se_param_t_0_20,
- boost_se_tag_0_20> boost_se_param_0_20;
- } boost_local_auxXparams20 = {
- { boost::scope_exit::aux::deref(factor, (boost_se_tag_0_20)0) }
- };
- boost::scope_exit::aux::declared<boost::scope_exit::aux::resolve<
- sizeof(boost_local_auxXargs)>::cmp1<0>::cmp2> boost_local_auxXargs;
- boost_local_auxXargs.value = &boost_local_auxXparams20;
-
- std::cout << boost_local_auxXparams20.boost_se_param_0_20.value << std::endl;
-
- class local_add {
- public:
- explicit local_add(double& _sum, int _factor):
- sum_(_sum), factor_(_factor) {
- }
- void operator()(double num) {
- return body(factor_, sum_, num);
- }
- private:
- double& sum_;
- int factor_;
-
- void body(const int factor, double& sum, double num)
- const {
- sum += factor * num;
- }
- } add(sum, factor);
-
- for (size_t i = 0; i < 10000; ++i) {
- for (size_t j = 0; j < v.size(); ++j) {
- add(v[j]);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/l07.cpp
==============================================================================
--- sandbox/local/libs/local/example/l07.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,60 +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>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
- typedef void (*tag)(int factor);
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap(
- boost::scope_exit::aux::deref(factor, (tag)0))) wrapped_t;
- typedef wrapped_t::type capture_t;
-
- struct params_t {
- typedef capture_t param_t;
- boost::scope_exit::aux::member<param_t, tag> param;
- } params = {
- { boost::scope_exit::aux::deref(factor, (tag)0) }
- };
-
- std::cout << params.param.value << std::endl;
-
- class local_add {
- public:
- explicit local_add(double& _sum, int _factor):
- sum_(_sum), factor_(_factor) {
- }
- void operator()(double num) {
- return body(factor_, sum_, num);
- }
- private:
- double& sum_;
- int factor_;
-
- void body(const int factor, double& sum, double num)
- const {
- sum += factor * num;
- }
- } add(sum, 10);
-
- for (size_t i = 0; i < 10000; ++i) {
- for (size_t j = 0; j < v.size(); ++j) {
- add(v[j]);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/l08.cpp
==============================================================================
--- sandbox/local/libs/local/example/l08.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,56 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- typedef void (*tag)(int factor);
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap(
- boost::scope_exit::aux::deref(factor, (tag)0))) wrapped_t;
- typedef wrapped_t::type capture_t;
- struct params_t {
- typedef capture_t param_t;
- boost::scope_exit::aux::member<param_t, tag> param;
- } params = {
- { boost::scope_exit::aux::deref(factor, (tag)0) }
- };
-
-
- std::vector<double> v(1000000);
- std::cout << params.param.value << std::endl;
-
-
- class local_add {
- public:
- explicit local_add(double& _sum, int _factor):
- sum_(_sum), factor_(_factor) {
- }
- void operator()(double num) {
- return body(factor_, sum_, num);
- }
- private:
- double& sum_;
- int factor_;
-
- void body(const int factor, double& sum, double num)
- const {
- sum += factor * num;
- }
- } add(sum, factor);
-
- std::fill(v.begin(), v.end(), 10);
- for (size_t i = 0; i < 10000; ++i) {
- for (size_t j = 0; j < v.size(); ++j) {
- //add(v[j]);
- add(10);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/l09.cpp
==============================================================================
--- sandbox/local/libs/local/example/l09.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,55 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- typedef void (*tag)(int factor);
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap(
- boost::scope_exit::aux::deref(factor, (tag)0))) wrapped_t;
- typedef wrapped_t::type capture_t;
- struct params_t {
- typedef capture_t param_t;
- boost::scope_exit::aux::member<param_t, tag> param;
- } params = {
- { boost::scope_exit::aux::deref(factor, (tag)0) }
- };
-
-
- std::cout << params.param.value << std::endl;
- std::vector<double> v(1000000);
-
-
- class local_add {
- public:
- explicit local_add(double& _sum, int _factor):
- sum_(_sum), factor_(_factor) {
- }
- void operator()(double num) {
- return body(factor_, sum_, num);
- }
- private:
- double& sum_;
- int factor_;
-
- void body(const int factor, double& sum, double num)
- const {
- sum += factor * num;
- }
- } add(sum, factor);
-
- std::fill(v.begin(), v.end(), 10);
- for (size_t i = 0; i < 10000; ++i) {
- for (size_t j = 0; j < v.size(); ++j) {
- add(v[j]);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/l10.cpp
==============================================================================
--- sandbox/local/libs/local/example/l10.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,60 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
-// typedef void (*tag)(int factor);
-// typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap(
-// boost::scope_exit::aux::deref(factor, (tag)0))) wrapped_t;
-// typedef wrapped_t::type capture_t;
-// struct params_t {
-// typedef capture_t param_t;
-// boost::scope_exit::aux::member<param_t, tag> param;
-// } params = {
-//#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
-// {
-//#endif
-// boost::scope_exit::aux::deref(factor, (tag)0)
-//#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
-// }
-//#endif
-// };
-
-// std::vector<double> v(1000000);
-// std::cout << params.param.value << std::endl;
-
-
- class local_add {
- public:
- explicit local_add(double& _sum):
- sum_(_sum) {
- }
- void operator()(double num) {
- return body(sum_, num);
- }
- private:
- double& sum_;
-
- void body(double& sum, double num)
- const {
- sum += 10 * num;
- }
- } add(sum);
-
- //std::fill(v.begin(), v.end(), 10);
- for (size_t i = 0; i < 10000; ++i) {
- for (size_t j = 0; j < 1000000; ++j) {
- //add(v[j]);
- add(10);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/optim.02.cpp
==============================================================================
--- sandbox/local/libs/local/example/optim.02.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,164 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-// This is a non-local functor so it can be passed as template parameter.
-// obj will be of local class type so it cannot be passed as template param (it is instead handled as a generic void pointer and the call function will cast it).
-template< typename R, typename A0, size_t defaults >
-class casting_function {
- typedef R (*call_function)(void* obj, A0);
-public:
- // public
- explicit casting_function(void* obj = 0, call_function call = 0): obj_(obj), call_(call) {}
- /* implicit for GCC */ casting_function(casting_function const& other): obj_(other.obj_), call_(other.call_) {}
- // precondition: set
- inline void operator()(A0 num) { call_(obj_, num); } // function pointer call cannot be inlined
- // private
- inline void set(void* obj = 0, call_function call = 0) { obj_ = obj; call_ = call; }
-private:
- void* obj_;
- call_function call_;
-};
-
-int main() {
- double sum = 0.0;
- int factor = 1;
-
- void (*ERROR_missing_result_type_before_the_local_function_parameter_macro_id19)(); typedef void (*boost_local_auxXdeduce_result_tag19)( int ERROR_missing_result_type_before_the_local_function_parameter_macro_id19);
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref( ERROR_missing_result_type_before_the_local_function_parameter_macro_id19, (boost_local_auxXdeduce_result_tag19)0))) boost_local_auxXdeduce_result_wrap19;
- typedef boost_local_auxXdeduce_result_wrap19::type boost_local_auxXdeduce_result_capture19;
- struct boost_local_auxXdeduce_result_params19 { typedef boost_local_auxXdeduce_result_capture19 function_ptr_type; };
- typedef boost::remove_pointer< boost_local_auxXdeduce_result_params19::function_ptr_type >::type boost_local_auxXdeduce_result_function_type19;
- typedef boost::function_traits< boost_local_auxXdeduce_result_function_type19>::result_type boost_local_auxXresult_type19;
- typedef void (*boost_se_tag_0_19)(int & factor );
- typedef void (*boost_se_tag_1_19)(int & sum );
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& factor, (boost_se_tag_0_19)0))) boost_se_wrapped_t_0_19;
- typedef boost_se_wrapped_t_0_19::type boost_se_capture_t_0_19;
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_19)0))) boost_se_wrapped_t_1_19;
- typedef boost_se_wrapped_t_1_19::type boost_se_capture_t_1_19;
- struct boost_se_params_t_19 {
- typedef boost_se_capture_t_0_19 boost_se_param_t_0_19;
- typedef boost_se_capture_t_1_19 boost_se_param_t_1_19;
- boost::scope_exit::aux::member< boost_se_param_t_0_19, boost_se_tag_0_19 > boost_se_param_0_19;
- boost::scope_exit::aux::member< boost_se_param_t_1_19, boost_se_tag_1_19 > boost_se_param_1_19;
- } boost_local_auxXparams19 = {
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- {
-#endif
- boost::scope_exit::aux::deref(& factor, (boost_se_tag_0_19)0)
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- }
-#endif
- ,
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- {
-#endif
- boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_19)0)
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- }
-#endif
- };
- boost::scope_exit::aux::declared< boost::scope_exit::aux::resolve< sizeof(boost_local_auxXargs) >::cmp1<0>::cmp2 > boost_local_auxXargs;
- boost_local_auxXargs.value = &boost_local_auxXparams19;
-
- class boost_local_auxXfunctor19
- : public ::boost::local::aux::abstract_function< boost_local_auxXresult_type19 ( const double& num ), 0 >
- {
- typedef boost_local_auxXresult_type19 (boost_local_auxXfunction_type) ( const double& num );
- public:
- explicit boost_local_auxXfunctor19(void* binding_data):
- boost_local_auxXbinds(static_cast< boost_se_params_t_19*>(binding_data))
- , factor(boost_local_auxXbinds->boost_se_param_0_19.value)
- , sum(boost_local_auxXbinds-> boost_se_param_1_19.value)
- {
- boost_local_auxXinit_recursion();
- }
- boost_local_auxXresult_type19 operator()(::boost::call_traits< ::boost::function_traits<boost_local_auxXfunction_type>::arg1_type>::param_type arg1) {
- return boost_local_auxXbody(arg1);
- }
- private:
- typedef ::boost::local::function<boost_local_auxXfunction_type, 0 > boost_local_auxXfunctor_type;
- typedef ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & factorXboost_local_auxXtypeof_type ;
- typedef boost_se_params_t_19:: boost_se_param_t_1_19 & sumXboost_local_auxXtypeof_type ;
- boost_se_params_t_19* boost_local_auxXbinds;
- boost::scope_exit::aux::undeclared boost_local_auxXargs;
-
- ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & factor;
- boost_se_params_t_19:: boost_se_param_t_1_19 & sum;
-
- boost_local_auxXresult_type19 boost_local_auxXbody(const double& num) const {
- sum += factor * num;
- }
-
- private:
- boost_local_auxXfunctor_type add;
- private:
- void boost_local_auxXinit_recursion() { add = *this; }
- } add_bl(boost_local_auxXargs.value);
- ::boost::local::function< boost_local_auxXresult_type19 ( const double& num ), 0 > add_f(add_bl);
-
- class local_add
-// Cannot use virtual-base trick because it prevents optimizations also when passing the local functor as template param on C++03.
-// Use casting trick instead to allow for C++03 optimizations.
-// : public ::boost::local::aux::abstract_function<boost_local_auxXresult_type19 (const double& num), 0>
- {
- // Function and functor types.
- typedef boost_local_auxXresult_type19 (boost_local_auxXfunction_type) (const double& num);
- typedef casting_function< boost_local_auxXresult_type19, const double&, 0 > casting_function_type;
- // For local-typeof.
- typedef ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & factorXboost_local_auxXtypeof_type ;
- typedef boost_se_params_t_19:: boost_se_param_t_1_19 & sumXboost_local_auxXtypeof_type ;
- public:
- explicit local_add(void* binds):
- bind1(static_cast< boost_se_params_t_19* >(binds)->boost_se_param_0_19.value)
- , bind2(static_cast< boost_se_params_t_19* >(binds)->boost_se_param_1_19.value)
- {}
- // Leave here even if call is used so this class can be used as functor for C++03 optimizations.
- inline boost_local_auxXresult_type19 operator()(const double& num) {
- return body(
- //boost_local_auxXbinds-> boost_se_param_0_19.value, boost_local_auxXbinds-> boost_se_param_1_19.value
- bind1, bind2
- , num);
- }
- // To pass local function as tparam on non C++03.
- inline static boost_local_auxXresult_type19 call(void* obj, const double& num) {
- return static_cast<local_add*>(obj)->operator()(num);
- }
- private:
- // Use binds as single mem vars instead of accessing `boost_se_params_t_19* boost_local_auxXbinds` all the times improves performance.
- // Always add ref because these data must just reference the actual data stored in the params struct declared outside this class (and passed to the ctor by
- // ptr).
- ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & bind1;
- boost_se_params_t_19:: boost_se_param_t_1_19 & bind2;
- // For nesting.
- boost::scope_exit::aux::undeclared boost_local_auxXargs;
- // Body.
- inline boost_local_auxXresult_type19 body(const int& factor, double& sum, const double& num) const {
- sum += factor * num;
- }
- public:
- // This must always be the non-local functor even if optimizing because it cannot be a ref to this local functors because ctor cannot init the ref because it
- // does not know the local function name.
- casting_function_type add;
- inline void init_recursion(casting_function_type& fctor) { add = fctor; } // cannot call from ctor to allow for opt
- } add_fctor(boost_local_auxXargs.value);
- BOOST_TYPEOF(add_fctor.add) add;
- add_fctor.init_recursion(add);
- add.set(&add_fctor, &add_fctor.call); // cannot set in ctor before init_recursion to allow for opt
-
- std::vector<double> v(1e4 * 1e2);
- std::fill(v.begin(), v.end(), 1.0);
-
- for (size_t n = 0; n < 1e4; ++n) {
- std::for_each(v.begin(), v.end(), add_fctor);
-// for (size_t i = 0; i < v.size(); ++i) add_lf(v[i]);
- }
-
- std::cout << sum << std::endl;
- assert(sum == 1e4 * 1e4 * 1e2);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/optim.03.cpp
==============================================================================
--- sandbox/local/libs/local/example/optim.03.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,164 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-// This is a non-local functor so it can be passed as template parameter.
-// obj will be of local class type so it cannot be passed as template param (it is instead handled as a generic void pointer and the call function will cast it).
-template< typename R, typename A0, size_t defaults >
-class casting_function {
- typedef R (*call_function)(void* obj, A0);
-public:
- // public
- explicit casting_function(void* obj = 0, call_function call = 0): obj_(obj), call_(call) {}
- /* implicit for GCC */ casting_function(casting_function const& other): obj_(other.obj_), call_(other.call_) {}
- // precondition: set
- inline void operator()(A0 num) { call_(obj_, num); } // function pointer call cannot be inlined
- // private
- inline void set(void* obj = 0, call_function call = 0) { obj_ = obj; call_ = call; }
-private:
- void* obj_;
- call_function call_;
-};
-
-int main() {
- double sum = 0.0;
- int factor = 1;
-
- void (*ERROR_missing_result_type_before_the_local_function_parameter_macro_id19)(); typedef void (*boost_local_auxXdeduce_result_tag19)( int ERROR_missing_result_type_before_the_local_function_parameter_macro_id19);
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref( ERROR_missing_result_type_before_the_local_function_parameter_macro_id19, (boost_local_auxXdeduce_result_tag19)0))) boost_local_auxXdeduce_result_wrap19;
- typedef boost_local_auxXdeduce_result_wrap19::type boost_local_auxXdeduce_result_capture19;
- struct boost_local_auxXdeduce_result_params19 { typedef boost_local_auxXdeduce_result_capture19 function_ptr_type; };
- typedef boost::remove_pointer< boost_local_auxXdeduce_result_params19::function_ptr_type >::type boost_local_auxXdeduce_result_function_type19;
- typedef boost::function_traits< boost_local_auxXdeduce_result_function_type19>::result_type boost_local_auxXresult_type19;
- typedef void (*boost_se_tag_0_19)(int & factor );
- typedef void (*boost_se_tag_1_19)(int & sum );
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& factor, (boost_se_tag_0_19)0))) boost_se_wrapped_t_0_19;
- typedef boost_se_wrapped_t_0_19::type boost_se_capture_t_0_19;
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_19)0))) boost_se_wrapped_t_1_19;
- typedef boost_se_wrapped_t_1_19::type boost_se_capture_t_1_19;
- struct boost_se_params_t_19 {
- typedef boost_se_capture_t_0_19 boost_se_param_t_0_19;
- typedef boost_se_capture_t_1_19 boost_se_param_t_1_19;
- boost::scope_exit::aux::member< boost_se_param_t_0_19, boost_se_tag_0_19 > boost_se_param_0_19;
- boost::scope_exit::aux::member< boost_se_param_t_1_19, boost_se_tag_1_19 > boost_se_param_1_19;
- } boost_local_auxXparams19 = {
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- {
-#endif
- boost::scope_exit::aux::deref(& factor, (boost_se_tag_0_19)0)
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- }
-#endif
- ,
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- {
-#endif
- boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_19)0)
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- }
-#endif
- };
- boost::scope_exit::aux::declared< boost::scope_exit::aux::resolve< sizeof(boost_local_auxXargs) >::cmp1<0>::cmp2 > boost_local_auxXargs;
- boost_local_auxXargs.value = &boost_local_auxXparams19;
-
- class boost_local_auxXfunctor19
- : public ::boost::local::aux::abstract_function< boost_local_auxXresult_type19 ( const double& num ), 0 >
- {
- typedef boost_local_auxXresult_type19 (boost_local_auxXfunction_type) ( const double& num );
- public:
- explicit boost_local_auxXfunctor19(void* binding_data):
- boost_local_auxXbinds(static_cast< boost_se_params_t_19*>(binding_data))
- , factor(boost_local_auxXbinds->boost_se_param_0_19.value)
- , sum(boost_local_auxXbinds-> boost_se_param_1_19.value)
- {
- boost_local_auxXinit_recursion();
- }
- boost_local_auxXresult_type19 operator()(::boost::call_traits< ::boost::function_traits<boost_local_auxXfunction_type>::arg1_type>::param_type arg1) {
- return boost_local_auxXbody(arg1);
- }
- private:
- typedef ::boost::local::function<boost_local_auxXfunction_type, 0 > boost_local_auxXfunctor_type;
- typedef ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & factorXboost_local_auxXtypeof_type ;
- typedef boost_se_params_t_19:: boost_se_param_t_1_19 & sumXboost_local_auxXtypeof_type ;
- boost_se_params_t_19* boost_local_auxXbinds;
- boost::scope_exit::aux::undeclared boost_local_auxXargs;
-
- ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & factor;
- boost_se_params_t_19:: boost_se_param_t_1_19 & sum;
-
- boost_local_auxXresult_type19 boost_local_auxXbody(const double& num) const {
- sum += factor * num;
- }
-
- private:
- boost_local_auxXfunctor_type add;
- private:
- void boost_local_auxXinit_recursion() { add = *this; }
- } add_bl(boost_local_auxXargs.value);
- ::boost::local::function< boost_local_auxXresult_type19 ( const double& num ), 0 > add_f(add_bl);
-
- class local_add
-// Cannot use virtual-base trick because it prevents optimizations also when passing the local functor as template param on C++03.
-// Use casting trick instead to allow for C++03 optimizations.
-// : public ::boost::local::aux::abstract_function<boost_local_auxXresult_type19 (const double& num), 0>
- {
- // Function and functor types.
- typedef boost_local_auxXresult_type19 (boost_local_auxXfunction_type) (const double& num);
- typedef casting_function< boost_local_auxXresult_type19, const double&, 0 > casting_function_type;
- // For local-typeof.
- typedef ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & factorXboost_local_auxXtypeof_type ;
- typedef boost_se_params_t_19:: boost_se_param_t_1_19 & sumXboost_local_auxXtypeof_type ;
- public:
- explicit local_add(void* binds):
- bind1(static_cast< boost_se_params_t_19* >(binds)->boost_se_param_0_19.value)
- , bind2(static_cast< boost_se_params_t_19* >(binds)->boost_se_param_1_19.value)
- {}
- // Leave here even if call is used so this class can be used as functor for C++03 optimizations.
- inline boost_local_auxXresult_type19 operator()(const double& num) {
- return body(
- //boost_local_auxXbinds-> boost_se_param_0_19.value, boost_local_auxXbinds-> boost_se_param_1_19.value
- bind1, bind2
- , num);
- }
- // To pass local function as tparam on non C++03.
- inline static boost_local_auxXresult_type19 call(void* obj, const double& num) {
- return static_cast<local_add*>(obj)->operator()(num);
- }
- private:
- // Use binds as single mem vars instead of accessing `boost_se_params_t_19* boost_local_auxXbinds` all the times improves performance.
- // Always add ref because these data must just reference the actual data stored in the params struct declared outside this class (and passed to the ctor by
- // ptr).
- ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & bind1;
- boost_se_params_t_19:: boost_se_param_t_1_19 & bind2;
- // For nesting.
- boost::scope_exit::aux::undeclared boost_local_auxXargs;
- // Body.
- inline boost_local_auxXresult_type19 body(const int& factor, double& sum, const double& num) const {
- sum += factor * num;
- }
- public:
- // This must always be the non-local functor even if optimizing because it cannot be a ref to this local functors because ctor cannot init the ref because it
- // does not know the local function name.
- casting_function_type add;
- inline void init_recursion(casting_function_type& fctor) { add = fctor; } // cannot call from ctor to allow for opt
- } add_fctor(boost_local_auxXargs.value);
- BOOST_TYPEOF(add_fctor.add) add;
- add_fctor.init_recursion(add);
- add.set(&add_fctor, &add_fctor.call); // cannot set in ctor before init_recursion to allow for opt
-
- std::vector<double> v(1e4 * 1e2);
- std::fill(v.begin(), v.end(), 1.0);
-
- for (size_t n = 0; n < 1e4; ++n) {
- std::for_each(v.begin(), v.end(), add_fctor);
-// for (size_t i = 0; i < v.size(); ++i) add_lf(v[i]);
- }
-
- std::cout << sum << std::endl;
- assert(sum == 1e4 * 1e4 * 1e2);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/optim.04.cpp
==============================================================================
--- sandbox/local/libs/local/example/optim.04.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,144 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-// This is a non-local functor so it can be passed as template parameter.
-// obj will be of local class type so it cannot be passed as template param (it is instead handled as a generic void pointer and the call function will cast it).
-template< typename R, typename A0, size_t defaults >
-class casting_function {
- typedef R (*call_type_0)(void*, A0);
- typedef R (*call_type_1)(void*);
-public:
- // public
-// inline explicit casting_function(): obj_(), call0_(), call1_() {}
-// inline /* implicit for GCC */ casting_function(const casting_function& other): obj_(other.obj_), call0_(other.call0_), call1_(other.call1_) {}
- inline void init(void* obj, call_type_0 call0, call_type_1 call1) { obj_ = obj; call0_ = call0; call1_ = call1; }
- inline void operator()(A0 num) { call0_(obj_, num); } // function pointer call cannot be inlined
- inline void operator()() { call1_(obj_); }
- // private
-private:
- void* obj_;
- call_type_0 call0_;
- call_type_1 call1_;
-};
-
-int main() {
- double sum = 0.0;
- int factor = 1;
-
- void (*ERROR_missing_result_type_before_the_local_function_parameter_macro_id19)(); typedef void (*boost_local_auxXdeduce_result_tag19)( int ERROR_missing_result_type_before_the_local_function_parameter_macro_id19);
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref( ERROR_missing_result_type_before_the_local_function_parameter_macro_id19, (boost_local_auxXdeduce_result_tag19)0))) boost_local_auxXdeduce_result_wrap19;
- typedef boost_local_auxXdeduce_result_wrap19::type boost_local_auxXdeduce_result_capture19;
- struct boost_local_auxXdeduce_result_params19 { typedef boost_local_auxXdeduce_result_capture19 function_ptr_type; };
- typedef boost::remove_pointer< boost_local_auxXdeduce_result_params19::function_ptr_type >::type boost_local_auxXdeduce_result_function_type19;
- typedef boost::function_traits< boost_local_auxXdeduce_result_function_type19>::result_type boost_local_auxXresult_type19;
- typedef void (*boost_se_tag_0_19)(int & factor );
- typedef void (*boost_se_tag_1_19)(int & sum );
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& factor, (boost_se_tag_0_19)0))) boost_se_wrapped_t_0_19;
- typedef boost_se_wrapped_t_0_19::type boost_se_capture_t_0_19;
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_19)0))) boost_se_wrapped_t_1_19;
- typedef boost_se_wrapped_t_1_19::type boost_se_capture_t_1_19;
- struct boost_se_params_t_19 {
- typedef boost_se_capture_t_0_19 boost_se_param_t_0_19;
- typedef boost_se_capture_t_1_19 boost_se_param_t_1_19;
- boost::scope_exit::aux::member< boost_se_param_t_0_19, boost_se_tag_0_19 > boost_se_param_0_19;
- boost::scope_exit::aux::member< boost_se_param_t_1_19, boost_se_tag_1_19 > boost_se_param_1_19;
- } boost_local_auxXparams19 = {
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- {
-#endif
- boost::scope_exit::aux::deref(& factor, (boost_se_tag_0_19)0)
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- }
-#endif
- ,
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- {
-#endif
- boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_19)0)
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- }
-#endif
- };
- boost::scope_exit::aux::declared< boost::scope_exit::aux::resolve< sizeof(boost_local_auxXargs) >::cmp1<0>::cmp2 > boost_local_auxXargs;
- boost_local_auxXargs.value = &boost_local_auxXparams19;
-
- class local_add
-// Cannot use virtual-base trick because it prevents optimizations also when passing the local functor as template param on C++03.
-// Use casting trick instead to allow for C++03 optimizations.
-// : public ::boost::local::aux::abstract_function<boost_local_auxXresult_type19 (const double& num), 0>
- {
- // Function and functor types.
- typedef boost_local_auxXresult_type19 (boost_local_auxXfunction_type) (const double& num);
- typedef casting_function< boost_local_auxXresult_type19, const double&, 0 > casting_function_type;
- // For local-typeof.
- typedef ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & factorXboost_local_auxXtypeof_type ;
- typedef boost_se_params_t_19:: boost_se_param_t_1_19 & sumXboost_local_auxXtypeof_type ;
- public:
- inline explicit local_add(void* binds):
- bind1(static_cast< boost_se_params_t_19* >(binds)->boost_se_param_0_19.value)
- , bind2(static_cast< boost_se_params_t_19* >(binds)->boost_se_param_1_19.value)
- {}
- // Leave here even if call is used so this class can be used as functor for C++03 optimizations.
- inline boost_local_auxXresult_type19 operator()(const double& num) {
- return body(bind1, bind2, num);
- }
- inline boost_local_auxXresult_type19 operator()() {
- return body(bind1, bind2);
- }
- // To pass local function as tparam on non C++03.
- inline static boost_local_auxXresult_type19 call0(void* obj, const double& num) {
- return static_cast<local_add*>(obj)->operator()(num);
- }
- inline static boost_local_auxXresult_type19 call1(void* obj) {
- return static_cast<local_add*>(obj)->operator()();
- }
- inline static void init_functor(void* object, casting_function_type& fctor) {
- fctor.init(object, &call0, &call1); // here knows default_counts
- }
- private:
- // Use binds as single mem vars instead of accessing `boost_se_params_t_19* boost_local_auxXbinds` all the times improves performance.
- // Always add ref because these data must just reference the actual data stored in the params struct declared outside this class (and passed to the ctor by
- // ptr).
- ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & bind1;
- boost_se_params_t_19:: boost_se_param_t_1_19 & bind2;
- // For nesting.
- boost::scope_exit::aux::undeclared boost_local_auxXargs;
- // Body.
- inline boost_local_auxXresult_type19 body(
- ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type& factor
- , boost_se_params_t_19:: boost_se_param_t_1_19& sum
- , const double& num = 0.0) const {
- sum += factor * num;
- }
- public:
- // This must always be the non-local functor even if optimizing because it cannot be a ref to this local functors because ctor cannot init the ref because it
- // does not know the local function name.
- casting_function_type add;
- inline void init_recursion(casting_function_type& fctor) { add = fctor; } // cannot call from ctor to allow for opt
- } add_fctor(boost_local_auxXargs.value);
- BOOST_TYPEOF(add_fctor.add) add;
- add_fctor.init_recursion(add);
- add_fctor.init_functor(&add_fctor, add);
-
-// add_fctor(1.23);
-// add_fctor();
-// add(3.21);
-// add();
-
- std::vector<double> v(1e4 * 1e2);
- std::fill(v.begin(), v.end(), 1.0);
-
- for (size_t n = 0; n < 1e4; ++n) {
- std::for_each(v.begin(), v.end(), add_fctor);
-// for (size_t i = 0; i < v.size(); ++i) add_lf(v[i]);
- }
-
- std::cout << sum << std::endl;
- assert(sum == 1e4 * 1e4 * 1e2);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/optim.05.cpp
==============================================================================
--- sandbox/local/libs/local/example/optim.05.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,142 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-// This is a non-local functor so it can be passed as template parameter.
-// obj will be of local class type so it cannot be passed as template param (it is instead handled as a generic void pointer and the call function will cast it).
-template< typename R, typename A0, size_t defaults >
-class casting_function {
- typedef R (*call_type_0)(void*, A0);
- typedef R (*call_type_1)(void*);
-public:
- // public
-// inline explicit casting_function(): obj_(), call0_(), call1_() {}
-// inline /* implicit for GCC */ casting_function(const casting_function& other): obj_(other.obj_), call0_(other.call0_), call1_(other.call1_) {}
- inline void init(void* obj, call_type_0 call0, call_type_1 call1) { obj_ = obj; call0_ = call0; call1_ = call1; }
- inline void operator()(A0 num) { call0_(obj_, num); } // function pointer call cannot be inlined
- inline void operator()() { call1_(obj_); }
- // private
-private:
- void* obj_;
- call_type_0 call0_;
- call_type_1 call1_;
-};
-
-template< typename R, typename A0, size_t defaults >
-class casting_function0 {
- typedef R (*call_type_0)(void*, A0);
-public:
- inline void boost_local_auxXinit_call(void* obj, call_type_0 call0) { obj_ = obj; call0_ = call0; }
- inline void operator()(A0 arg0) { call0_(obj_, arg0); }
-private:
- void* obj_;
- call_type_0 call0_;
-};
-
-int main() {
- double sum = 0.0;
- int factor = 1;
-
- void (*ERROR_missing_result_type_before_the_local_function_parameter_macro_id19)(); typedef void (*boost_local_auxXdeduce_result_tag19)( int ERROR_missing_result_type_before_the_local_function_parameter_macro_id19);
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref( ERROR_missing_result_type_before_the_local_function_parameter_macro_id19, (boost_local_auxXdeduce_result_tag19)0))) boost_local_auxXdeduce_result_wrap19;
- typedef boost_local_auxXdeduce_result_wrap19::type boost_local_auxXdeduce_result_capture19;
- struct boost_local_auxXdeduce_result_params19 { typedef boost_local_auxXdeduce_result_capture19 function_ptr_type; };
- typedef boost::remove_pointer< boost_local_auxXdeduce_result_params19::function_ptr_type >::type boost_local_auxXdeduce_result_function_type19;
- typedef boost::function_traits< boost_local_auxXdeduce_result_function_type19>::result_type boost_local_auxXresult_type19;
- typedef void (*boost_se_tag_0_19)(int & factor );
- typedef void (*boost_se_tag_1_19)(int & sum );
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& factor, (boost_se_tag_0_19)0))) boost_se_wrapped_t_0_19;
- typedef boost_se_wrapped_t_0_19::type boost_se_capture_t_0_19;
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_19)0))) boost_se_wrapped_t_1_19;
- typedef boost_se_wrapped_t_1_19::type boost_se_capture_t_1_19;
- struct boost_se_params_t_19 {
- typedef boost_se_capture_t_0_19 boost_se_param_t_0_19;
- typedef boost_se_capture_t_1_19 boost_se_param_t_1_19;
- boost::scope_exit::aux::member< boost_se_param_t_0_19, boost_se_tag_0_19 > boost_se_param_0_19;
- boost::scope_exit::aux::member< boost_se_param_t_1_19, boost_se_tag_1_19 > boost_se_param_1_19;
- } boost_local_auxXparams19 = {
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- {
-#endif
- boost::scope_exit::aux::deref(& factor, (boost_se_tag_0_19)0)
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- }
-#endif
- ,
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- {
-#endif
- boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_19)0)
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- }
-#endif
- };
- boost::scope_exit::aux::declared< boost::scope_exit::aux::resolve< sizeof(boost_local_auxXargs) >::cmp1<0>::cmp2 > boost_local_auxXargs;
- boost_local_auxXargs.value = &boost_local_auxXparams19;
-
- class boost_local_auxXfunctor19 {
- typedef boost_local_auxXresult_type19 (boost_local_auxXfunction_type) (const double& num);
-// typedef ::boost::local::function< boost_local_auxXfunction_type, 0 > boost_local_auxXfunctor_type;
- typedef casting_function0< boost_local_auxXresult_type19, const double&, 0 > boost_local_auxXfunctor_type;
-
- typedef ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & factorXboost_local_auxXtypeof_type ;
- typedef boost_se_params_t_19:: boost_se_param_t_1_19 & sumXboost_local_auxXtypeof_type ;
-
- public:
- inline explicit boost_local_auxXfunctor19(void* bindings):
- boost_local_auxXbind0( static_cast< boost_se_params_t_19* >(bindings)->boost_se_param_0_19.value )
- , boost_local_auxXbind1( static_cast< boost_se_params_t_19* >(bindings)->boost_se_param_1_19.value )
- {}
-
- inline boost_local_auxXresult_type19 operator()(
- ::boost::call_traits< ::boost::function_traits< boost_local_auxXfunction_type >::arg1_type >::param_type arg1) {
- return boost_local_auxXbody(boost_local_auxXbind0, boost_local_auxXbind1, arg1);
- }
- inline static boost_local_auxXresult_type19 boost_local_auxXcall0(void* obj, const double& num) {
- return static_cast<boost_local_auxXfunctor19*>(obj)->operator()(num);
- }
- inline static void boost_local_auxXinit_call(void* object, boost_local_auxXfunctor_type& functor) {
- functor.boost_local_auxXinit_call(object, &boost_local_auxXcall0 );
- }
- private:
- ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & boost_local_auxXbind0;
- boost_se_params_t_19:: boost_se_param_t_1_19 & boost_local_auxXbind1;
-
- boost::scope_exit::aux::undeclared boost_local_auxXargs;
-
- inline boost_local_auxXresult_type19 boost_local_auxXbody(
- ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type& factor
- , boost_se_params_t_19:: boost_se_param_t_1_19& sum
- , const double& num
- ) const {
- sum += factor * num;
- }
- public:
- boost_local_auxXfunctor_type add;
- inline void boost_local_auxXinit_recursion(boost_local_auxXfunctor_type& functor) { add = functor; }
- } add(boost_local_auxXargs.value);
- BOOST_TYPEOF(add.add) boost_local_auxXadd;
- add.boost_local_auxXinit_recursion(boost_local_auxXadd);
- add.boost_local_auxXinit_call(&add, boost_local_auxXadd);
-
-// add_fctor(1.23);
-// add_fctor();
-// add(3.21);
-// add();
-
- std::vector<double> v(1e4 * 1e2);
- std::fill(v.begin(), v.end(), 1.0);
-
- for (size_t n = 0; n < 1e4; ++n) {
- std::for_each(v.begin(), v.end(), add);
-// for (size_t i = 0; i < v.size(); ++i) add_lf(v[i]);
- }
-
- std::cout << sum << std::endl;
- assert(sum == 1e4 * 1e4 * 1e2);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/optim.06.cpp
==============================================================================
--- sandbox/local/libs/local/example/optim.06.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,159 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-template< typename F, size_t defaults = 0 >
-struct casting_function {};
-
-/*
-template< typename R, typename A0 >
-class casting_function< R (A0), 0 > {
- typedef R (*call_type_0)(void*, A0);
-public:
- inline void init(void* obj, call_type_0 call0) { obj_ = obj; call0_ = call0; }
- inline void operator()(A0 num) { call0_(obj_, num); }
-private:
- void* obj_;
- call_type_0 call0_;
- void* call1_;
- void* call2_;
-};
-*/
-
-template< typename R, typename A0 >
-class casting_function< R (A0), 0 > {
- typedef void* object_ptr;
- typedef R (*call_ptr0)(object_ptr , typename ::boost::call_traits<A0 >::param_type);
-public:
- inline void init(object_ptr object, call_ptr0 call0) {
- object_ = object;
- call0_ = call0;
- }
- inline R operator()( typename ::boost::call_traits<A0 >::param_type a0) const { return call0_(object_ , a0); }
-private:
- object_ptr object_;
- call_ptr0 call0_;
- void* call1_;
- void* call2_;
-};
-
-int main() {
- double sum = 0.0;
- int factor = 1;
-
- void (*ERROR_missing_result_type_before_the_local_function_parameter_macro_id19)(); typedef void (*boost_local_auxXdeduce_result_tag19)( int ERROR_missing_result_type_before_the_local_function_parameter_macro_id19);
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref( ERROR_missing_result_type_before_the_local_function_parameter_macro_id19, (boost_local_auxXdeduce_result_tag19)0))) boost_local_auxXdeduce_result_wrap19;
- typedef boost_local_auxXdeduce_result_wrap19::type boost_local_auxXdeduce_result_capture19;
- struct boost_local_auxXdeduce_result_params19 { typedef boost_local_auxXdeduce_result_capture19 function_ptr_type; };
- typedef boost::remove_pointer< boost_local_auxXdeduce_result_params19::function_ptr_type >::type boost_local_auxXdeduce_result_function_type19;
- typedef boost::function_traits< boost_local_auxXdeduce_result_function_type19>::result_type boost_local_auxXresult_type19;
- typedef void (*boost_se_tag_0_19)(int & factor );
- typedef void (*boost_se_tag_1_19)(int & sum );
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& factor, (boost_se_tag_0_19)0))) boost_se_wrapped_t_0_19;
- typedef boost_se_wrapped_t_0_19::type boost_se_capture_t_0_19;
- typedef BOOST_TYPEOF(boost::scope_exit::aux::wrap( boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_19)0))) boost_se_wrapped_t_1_19;
- typedef boost_se_wrapped_t_1_19::type boost_se_capture_t_1_19;
- struct boost_se_params_t_19 {
- typedef boost_se_capture_t_0_19 boost_se_param_t_0_19;
- typedef boost_se_capture_t_1_19 boost_se_param_t_1_19;
- boost::scope_exit::aux::member< boost_se_param_t_0_19, boost_se_tag_0_19 > boost_se_param_0_19;
- boost::scope_exit::aux::member< boost_se_param_t_1_19, boost_se_tag_1_19 > boost_se_param_1_19;
- } boost_local_auxXparams19 = {
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- {
-#endif
- boost::scope_exit::aux::deref(& factor, (boost_se_tag_0_19)0)
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- }
-#endif
- ,
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- {
-#endif
- boost::scope_exit::aux::deref(& sum, (boost_se_tag_1_19)0)
-#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
- }
-#endif
- };
- boost::scope_exit::aux::declared< boost::scope_exit::aux::resolve< sizeof(boost_local_auxXargs) >::cmp1<0>::cmp2 > boost_local_auxXargs;
- boost_local_auxXargs.value = &boost_local_auxXparams19;
-
- class local_add
-// Cannot use virtual-base trick because it prevents optimizations also when passing the local functor as template param on C++03.
-// Use casting trick instead to allow for C++03 optimizations.
-// : public ::boost::local::aux::abstract_function<boost_local_auxXresult_type19 (const double& num), 0>
- {
- // Function and functor types.
- typedef boost_local_auxXresult_type19 (boost_local_auxXfunction_type) (const double& num);
- typedef casting_function< boost_local_auxXfunction_type, 0 > casting_function_type;
- // For local-typeof.
- typedef ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & factorXboost_local_auxXtypeof_type ;
- typedef boost_se_params_t_19:: boost_se_param_t_1_19 & sumXboost_local_auxXtypeof_type ;
- public:
- inline explicit local_add(void* binds):
- bind1(static_cast< boost_se_params_t_19* >(binds)->boost_se_param_0_19.value)
- , bind2(static_cast< boost_se_params_t_19* >(binds)->boost_se_param_1_19.value)
- {}
- // Leave here even if call is used so this class can be used as functor for C++03 optimizations.
- inline boost_local_auxXresult_type19 operator()(::boost::call_traits< ::boost::function_traits< boost_local_auxXfunction_type>::arg1_type>::param_type arg1) {
- return body(bind1, bind2, arg1);
- }
- inline boost_local_auxXresult_type19 operator()() {
- return body(bind1, bind2);
- }
- // To pass local function as tparam on non C++03.
- inline static boost_local_auxXresult_type19 call0(void* obj, const double& num) {
- return static_cast<local_add*>(obj)->operator()(num);
- }
- inline static boost_local_auxXresult_type19 call1(void* obj) {
- return static_cast<local_add*>(obj)->operator()();
- }
- inline static void init_functor(void* object, casting_function_type& fctor) {
- fctor.init(object, &call0); // here knows default_counts
- }
- private:
- // Use binds as single mem vars instead of accessing `boost_se_params_t_19* boost_local_auxXbinds` all the times improves performance.
- // Always add ref because these data must just reference the actual data stored in the params struct declared outside this class (and passed to the ctor by
- // ptr).
- ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type & bind1;
- boost_se_params_t_19:: boost_se_param_t_1_19 & bind2;
- // For nesting.
- boost::scope_exit::aux::undeclared boost_local_auxXargs;
- // Body.
- inline boost_local_auxXresult_type19 body(
- ::boost::add_const< boost_se_params_t_19:: boost_se_param_t_0_19 >::type& factor
- , boost_se_params_t_19:: boost_se_param_t_1_19& sum
- , const double& num = 0.0) const {
- sum += factor * num;
- }
- public:
- // This must always be the non-local functor even if optimizing because it cannot be a ref to this local functors because ctor cannot init the ref because it
- // does not know the local function name.
- casting_function_type add;
- inline void init_recursion(casting_function_type& fctor) { add = fctor; } // cannot call from ctor to allow for opt
- } add_fctor(boost_local_auxXargs.value);
- BOOST_TYPEOF(add_fctor.add) add;
- add_fctor.init_recursion(add);
- add_fctor.init_functor(&add_fctor, add);
-
-// add_fctor(1.23);
-// add_fctor();
-// add(3.21);
-// add();
-
- std::vector<double> v(1e4 * 1e2);
- std::fill(v.begin(), v.end(), 1.0);
-
- for (size_t n = 0; n < 1e4; ++n) {
- std::for_each(v.begin(), v.end(), add_fctor);
-// for (size_t i = 0; i < v.size(); ++i) add_lf(v[i]);
- }
-
- std::cout << sum << std::endl;
- assert(sum == 1e4 * 1e4 * 1e2);
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/p00.cpp
==============================================================================
--- sandbox/local/libs/local/example/p00.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,28 +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/spirit/include/phoenix.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
-
- for(int i = 0; i < 10000; ++i) {
- std::for_each(v.begin(), v.end(), (
- boost::phoenix::ref(sum) += factor * boost::phoenix::arg_names::_1
- ));
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Modified: sandbox/local/libs/local/example/profile_global_functor.cpp
==============================================================================
--- sandbox/local/libs/local/example/profile_global_functor.cpp (original)
+++ sandbox/local/libs/local/example/profile_global_functor.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
@@ -5,9 +5,9 @@
#include <iostream>
#include "profile_helpers.hpp"
-struct add_global_functor {
- add_global_functor(double& sum_, const int& factor_):
- sum(sum_), factor(factor_) {}
+struct global_add {
+ global_add(double& _sum, const int& _factor):
+ sum(_sum), factor(_factor) {}
inline void operator()(const double& num) {
sum += factor * num;
}
@@ -25,7 +25,7 @@
boost::chrono::system_clock::time_point start =
boost::chrono::system_clock::now();
- add_global_functor add(sum, factor);
+ global_add add(sum, factor);
boost::chrono::duration<double> decl_sec =
boost::chrono::system_clock::now() - start;
Modified: sandbox/local/libs/local/example/profile_local_functor.cpp
==============================================================================
--- sandbox/local/libs/local/example/profile_local_functor.cpp (original)
+++ sandbox/local/libs/local/example/profile_local_functor.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
@@ -14,9 +14,9 @@
boost::chrono::system_clock::time_point start =
boost::chrono::system_clock::now();
- struct add_local_functor {
- add_local_functor(double& sum_, const int& factor_):
- sum(sum_), factor(factor_) {}
+ struct local_add {
+ local_add(double& _sum, const int& _factor):
+ sum(_sum), factor(_factor) {}
inline void operator()(const double& num) {
sum += factor * num;
}
Deleted: sandbox/local/libs/local/example/tom_add_boost_local.cpp
==============================================================================
--- sandbox/local/libs/local/example/tom_add_boost_local.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,25 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- void BOOST_LOCAL_FUNCTION_PARAMS( (const double& num)
- (bind& sum) (const bind& factor) ) {
- sum += factor * num;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- std::vector<double> v(1000000);
- std::fill(v.begin(), v.end(), 10);
- for (size_t i = 0; i < 10000; ++i) {
- std::for_each(v.begin(), v.end(), add);
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tom_add_boost_phoenix.cpp
==============================================================================
--- sandbox/local/libs/local/example/tom_add_boost_phoenix.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,25 +0,0 @@
-
-#include <boost/spirit/include/phoenix.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(1000000);
-
- std::fill(v.begin(), v.end(), 10);
-
- for(int i = 0; i < 10000; ++i)
- {
- std::for_each(v.begin(), v.end(), (
- boost::phoenix::ref(sum) += factor * boost::phoenix::arg_names::_1
- ));
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tom_local.cpp
==============================================================================
--- sandbox/local/libs/local/example/tom_local.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,26 +0,0 @@
-
-#include <boost/local/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- void BOOST_LOCAL_FUNCTION_PARAMS( (double num)
- (bind& sum) (const bind factor) ) {
- sum += factor * num;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- std::vector<double> v(100000);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t i = 0; i < 10000; ++i) {
- std::for_each(v.begin(), v.end(), add);
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tom_phoenix.cpp
==============================================================================
--- sandbox/local/libs/local/example/tom_phoenix.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,23 +0,0 @@
-
-#include <boost/spirit/include/phoenix.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- std::vector<double> v(100000);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t i = 0; i < 10000; ++i) {
- std::for_each(v.begin(), v.end(), (
- boost::phoenix::ref(sum) += factor * boost::phoenix::arg_names::_1
- ));
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.00.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.00.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,51 +0,0 @@
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-#define N 10000
-
-struct abstract_function {
- virtual void operator()() = 0;
-};
-
-struct function {
- function(abstract_function& ref): ptr_(&ref) {}
- void operator()() { return ptr_->operator()(); }
-private:
- abstract_function* ptr_;
-};
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct add_function: abstract_function {
- add_function(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
- void operator()() { return body(sum_, factor_); }
- private:
- double& sum_;
- const int& factor_;
- void body(double& sum, const int& factor) {
- sum += factor * 10;
- }
- };
- add_function functor_add(sum, factor);
- function add(functor_add);
-
- std::vector<double> v(N * 100);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
- for (size_t i = 0; i < v.size(); ++i) {
-// functor_add(v[i]); // (1)
- add(); // (2)
- }
- // std::for_each(v.begin(), v.end(), add); // (3) OK add as tparam!
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.01.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.01.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,54 +0,0 @@
-
-#include <boost/function.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-
-#define N 10000
-
-struct abstract_function {
- virtual void operator()() = 0;
-};
-
-struct function {
- function(abstract_function& ref): ptr_(&ref) {}
- void operator()() { return ptr_->operator()(); }
-private:
- abstract_function* ptr_;
-};
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct add_function: abstract_function {
- add_function(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
- void operator()() { return body(sum_, factor_); }
- static void f(const double& x) {}
- double& sum_;
- const int& factor_;
- void body(double& sum, const int& factor) {
- sum += factor * 10;
- }
- };
- add_function functor_add(sum, factor);
-// boost::function<void ()> add(functor_add);
- void (add_function::*f)() = add_function::operator();
- functor_addf();
-
- std::vector<double> v(N * 100);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
- for (size_t i = 0; i < v.size(); ++i) {
-// functor_add(v[i]); // (1)
- f(10); // (2)
- }
-// std::for_each(v.begin(), v.end(), f); // (3) OK add as tparam!
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.02.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.02.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,73 +0,0 @@
-
-//#include <boost/spirit/include/phoenix.hpp>
-#include <boost/function.hpp>
-#include <boost/bind.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 10000
-
-struct abstract_function {
- virtual void operator()(const double&) = 0;
-};
-
-struct function {
- function(void* obj, void (*call)(void*, const double&)):
- obj_(obj), call_(call) {}
- inline void operator()(const double& arg1) { call_(obj_, arg1); }
-private:
- void* obj_;
- void (*call_)(void*, const double&);
-};
-
-void call(void* obj, const double& num) {}
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct add_function: abstract_function {
- add_function(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
- void operator()(const double& num) { body(sum_, factor_, num); }
- static void call(void* obj, const double& num) {
- static_cast<add_function*>(obj)->operator()(num);
-// add_function* self = static_cast<add_function*>(obj);
-// return self->body(self->sum_, self->factor_, num);
- }
- private:
- double& sum_;
- const int& factor_;
- void body(double& sum, const int& factor, const double& num) {
- sum += factor * num;
- }
- };
- add_function adder(sum, factor);
- function add(&adder, &add_function::call);
-
- std::vector<double> v(N * 100);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
- for (size_t i = 0; i < v.size(); ++i) {
-// adder(v[i]); // (1)
-// add_function::call(&adder, v[i]);
-// add(v[i]);
- boost::bind(add_function::call, (void*)&adder, _1)(v[i]);
-// v[i];
-// add(); // (2)
-// add_function::call(&adder);
-// add(v[i]);
- }
-// std::for_each(v.begin(), v.end(), add); // (3) OK add as tparam!
-// std::for_each(v.begin(), v.end(),
-// boost::phoenix::val(adder.f(10))
-// );
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.03.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.03.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,69 +0,0 @@
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 10000
-
-struct base_function {
- virtual void operator()(const double&) {
- std::cout << "parent\n";
- }
-};
-
-struct function {
- function(void* obj, void (*call)(void*, const double&)):
- obj_(obj), call_(call) {}
- inline void operator()(const double& arg1) {
- call_(obj_, arg1);
- }
-private:
- void* obj_;
- void (*call_)(void*, const double&);
-};
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct local_add: base_function {
- local_add(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
- void operator()(const double& num) { body(sum_, factor_, num); }
- static void call(void* obj, const double& num)
- { static_cast<local_add*>(obj)->operator()(num); }
- private:
- double& sum_;
- const int& factor_;
- void body(double& sum, const int& factor, const double& num) {
- sum += factor * num;
- }
- };
- local_add add_l(sum, factor);
- base_function& add_b = add_l;
- function add_f(&add_l, local_add::call);
-
- void* obj_ = &add_l;
- register void (*call_)(void*, const double&) = &local_add::call;
-
- std::vector<double> v(N * 100);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
-// std::for_each(v.begin(), v.end(), add_l); // Error.
-// std::for_each(v.begin(), v.end(), add_b);
-// std::for_each(v.begin(), v.end(), add_f);
- for (size_t i = 0; i < v.size(); ++i) {
-// add_l(v[i]);
-// add_b(v[i]);
-// add_f(v[i]);
-// local_add::call(&add_l, v[i]);
- call_(obj_, v[i]);
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.04.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.04.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,53 +0,0 @@
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 10000
-
-//struct func {
-// func(void* obj, void (*call)(void*, const double&)):
-// obj_(obj), call_(call) {}
-// inline void operator()(const double& num) { call_(obj_, num); }
-//private:
-// void* obj_;
-// void (*call_)(void*, const double&);
-};
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct local_add {
- local_add(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
- void operator()(const double& num) { body(sum_, factor_, num); }
- static void call(void* obj, const double& num)
- { static_cast<local_add*>(obj)->operator()(num); }
- private:
- double& sum_;
- const int& factor_;
- void body(double& sum, const int& factor, const double& num) {
- sum += factor * num;
- }
- };
- local_add add_l(sum, factor);
- void* obj_ = &add_l;
- void (*call_)(void*, const double&) = &local_add::call;
-// func add_f(&add_l, &local_add::call);
-
- std::vector<double> v(N);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
- for (size_t i = 0; i < v.size(); ++i) {
-// local_add::call(&add_l, v[i]); // (1) runs in 16s
- call_(obj_, v[i]); // (2) runs in 16s
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.05.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.05.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,43 +0,0 @@
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 10000
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct local_add {
- local_add(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
- void operator()(const double& num) { body(sum_, factor_, num); }
- static void call(void* obj, const double& num)
- { static_cast<local_add*>(obj)->operator()(num); }
- private:
- double& sum_;
- const int& factor_;
- void body(double& sum, const int& factor, const double& num) {
- sum += factor * num;
- }
- };
- local_add add_l(sum, factor);
- void* obj_ = &add_l;
- void (*call_)(void*, const double&) = &local_add::call;
-
- std::vector<double> v(N * 100);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
- for (size_t i = 0; i < v.size(); ++i) {
-// local_add::call(&add_l, v[i]); // (1) runs in 16s
- call_(obj_, v[i]); // (2) runs in
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.06.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.06.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,54 +0,0 @@
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 10000
-
-struct func {
- func(void* obj, void (*call)(void*, const double&)):
- obj_(obj), call_(call) {}
- inline void operator()(const double& num) { call_(obj_, num); }
-private:
- void* obj_;
- void (*call_)(void*, const double&);
-};
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct local_add {
- local_add(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
- void operator()(const double& num) { body(sum_, factor_, num); }
- static void call(void* obj, const double& num)
- { static_cast<local_add*>(obj)->operator()(num); }
- private:
- double& sum_;
- const int& factor_;
- void body(double& sum, const int& factor, const double& num) {
- sum += factor * num;
- }
- };
- local_add add_l(sum, factor);
- void* obj_ = &add_l;
- void (*call_)(void*, const double&) = &local_add::call;
- func add_f(&add_l, &local_add::call);
-
- std::vector<double> v(N * 10);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
- for (size_t i = 0; i < v.size(); ++i) {
-// local_add::call(&add_l, v[i]); // (1) runs in 19s
-// call_(obj_, v[i]); // (2) runs in 20s
-// add_f(v[i]); // (3) runs in 23s
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.07.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.07.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,67 +0,0 @@
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 10000
-
-struct abstract_func {
- virtual void operator()(const double&) = 0;
-};
-
-struct virtual_func {
- virtual_func(abstract_func& ref): ptr_(&ref) {}
- inline void operator()(const double& num) { (*ptr_)(num); }
-private:
- abstract_func* ptr_;
-};
-
-struct casting_func {
- casting_func(void* obj, void (*call)(void*, const double&)):
- obj_(obj), call_(call) {}
- inline void operator()(const double& num) { call_(obj_, num); }
-private:
- void* obj_;
- void (*call_)(void*, const double&);
-};
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct local_add: abstract_func {
- local_add(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
- void operator()(const double& num) { body(sum_, factor_, num); }
- static void call(void* obj, const double& num)
- { static_cast<local_add*>(obj)->operator()(num); }
- private:
- double& sum_;
- const int& factor_;
- void body(double& sum, const int& factor, const double& num) {
- sum += factor * num;
- }
- };
- local_add add_l(sum, factor);
- void* obj_ = &add_l;
- void (*call_)(void*, const double&) = &local_add::call;
- casting_func add_c(&add_l, &local_add::call);
- virtual_func add_v(add_l);
-
- std::vector<double> v(N * 10);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
- for (size_t i = 0; i < v.size(); ++i) {
-// local_add::call(&add_l, v[i]); // (1) runs in 19s
-// call_(obj_, v[i]); // (2) runs in 20s
-// add_c(v[i]); // (3) runs in 23s (or 25s w/ abstract_func base)
- add_v(v[i]); // (4) runs in 21s
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.08.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.08.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,72 +0,0 @@
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 1e4
-#define S N * 1e2
-
-struct func_if {
- inline virtual void operator()(const double&) = 0;
-};
-
-struct virtual_func {
- explicit virtual_func(func_if& ref): ptr_(&ref) {}
- inline void operator()(const double& num) { (*ptr_)(num); }
-private:
- func_if* ptr_;
-};
-
-struct casting_func {
- explicit casting_func(void* obj, void (*call)(void*, const double&)):
- obj_(obj), call_(call) {}
- inline void operator()(const double& num) { call_(obj_, num); }
-private:
- void* obj_;
- void (*call_)(void*, const double&);
-};
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct local_add: func_if {
- explicit local_add(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
- inline void operator()(const double& num) { body(sum_, factor_, num); }
- inline static void call(void* obj, const double& num) {
- local_add* self = static_cast<local_add*>(obj);
- self->body(self->sum_, self->factor_, num);
- }
- private:
- double& sum_;
- const int& factor_;
- inline void body(double& sum, const int& factor, const double& num) {
- sum += factor * num;
- }
- };
- local_add add_local(sum, factor);
-
- void* obj = &add_local;
- void (*call)(void*, const double&) = &local_add::call;
-
- casting_func add_casting(&add_local, &local_add::call);
- virtual_func add_virtual(add_local);
-
- std::vector<double> v(S);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
- for (size_t i = 0; i < v.size(); ++i) {
-// local_add::call(&add_local, v[i]); // (1) runs in 19s
-// call(obj, v[i]); // (2) runs in 20s
-// add_casting(v[i]); // (3) runs in 23s (or 25s w/ func_if base)
- add_virtual(v[i]); // (4) runs in 21s
- }
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.09.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.09.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,91 +0,0 @@
-
-// Tricks to "pass" a local class as a template parameter.
-
-// compile-time: $ time g++ -O3 -Wall <THIS_FILE>
-// run-time: $ time ./a
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-#define N 1e4
-#define S N * 1e2
-
-// Trick A: Virtual Base
-
-struct func_if {
- inline virtual void __attribute__((always_inline)) operator()(
- const double&) {} // virtual call cannot be inlined
-};
-
-struct virtual_func {
- explicit virtual_func(func_if& ref): ptr_(&ref) {}
- inline void __attribute__((always_inline)) operator()(const double& num)
- { (*ptr_)(num); }
-private:
- func_if* ptr_;
-};
-
-// Trick B: Casting Function Pointer
-
-struct casting_func {
- explicit casting_func(void* obj, void (*call)(void*, const double&)):
- obj_(obj), call_(call) {}
- inline void __attribute__((always_inline)) operator()(const double& num)
- { call_(obj_, num); } // function pointer call cannot be inlined
-private:
- void* obj_;
- void (*call_)(void*, const double&);
-};
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct local_add
- : func_if
- {
- explicit local_add(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
- inline void __attribute__((always_inline)) operator()(
- const double& num) { body(sum_, factor_, num); }
-// inline static void __attribute__((always_inline)) call(
-// void* obj, const double& num) {
-// local_add* self = static_cast<local_add*>(obj);
-// self->body(self->sum_, self->factor_, num);
-// }
- private:
- double& sum_;
- const int& factor_;
- inline void __attribute__((always_inline)) body(
- double& sum, const int& factor, const double& num) {
- sum += factor * num;
- }
- };
- local_add add_local(sum, factor);
-
-// void* obj = &add_local;
-// void (*call)(void*, const double&) = &local_add::call;
-
-// casting_func add_casting(&add_local, &local_add::call);
- virtual_func add_virtual(add_local);
-
- std::vector<double> v(S);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
-// for (size_t i = 0; i < v.size(); ++i) {
-// add_local(v[i]); // (1) runs in 16s
-// call(obj, v[i]); // (2) runs in 16s
-// add_casting(v[i]); // (3) runs in 40s
-// add_virtual(v[i]); // (4) runs in 47s
-// }
- std::for_each(v.begin(), v.end(), add_casting); // (5) runs in 40s
-// std::for_each(v.begin(), v.end(), add_virtual); // (6) runs in 46s
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Deleted: sandbox/local/libs/local/example/tparam_trick.10.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.10.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
+++ (empty file)
@@ -1,85 +0,0 @@
-
-// Tricks to "pass" a local class as a template parameter.
-
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include <cassert>
-
-// Trick A: Virtual Base
-
-struct func_if {
- inline virtual void operator()(
- const double&) {} // virtual call cannot be inlined
-};
-
-struct virtual_func {
- explicit virtual_func(func_if& ref): ptr_(&ref) {}
- inline void operator()(const double& num)
- { (*ptr_)(num); }
-private:
- func_if* ptr_;
-};
-
-// Trick B: Casting Function Pointer
-
-struct casting_func {
- explicit casting_func(void* obj, void (*call)(void*, const double&)):
- obj_(obj), call_(call) {}
- inline void operator()(const double& num)
- { call_(obj_, num); } // function pointer call cannot be inlined
-private:
- void* obj_;
- void (*call_)(void*, const double&);
-};
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- struct local_add
-// : func_if
- {
- explicit local_add(double& _sum, const int& _factor):
- sum_(_sum), factor_(_factor) {}
-// inline void operator()(
-// const double& num) { body(sum_, factor_, num); }
- inline static void call(
- void* obj, const double& num) {
- local_add* self = static_cast<local_add*>(obj);
- self->body(self->sum_, self->factor_, num);
- }
- private:
- double& sum_;
- const int& factor_;
- inline void body(
- double& sum, const int& factor, const double& num) {
- sum += factor * num;
- }
- };
- local_add add_local(sum, factor);
-
-// void* obj = &add_local;
-// void (*call)(void*, const double&) = &local_add::call;
-
- casting_func add_casting(&add_local, &local_add::call);
-// virtual_func add_virtual(add_local);
-
- std::vector<double> v(S);
- std::fill(v.begin(), v.end(), 10);
-
- for (size_t n = 0; n < N; ++n) {
-// for (size_t i = 0; i < v.size(); ++i) {
-// add_local(v[i]); // (1) runs in 16s
-// call(obj, v[i]); // (2) runs in 16s
-// add_casting(v[i]); // (3) runs in 40s
-// add_virtual(v[i]); // (4) runs in 47s
-// }
- std::for_each(v.begin(), v.end(), add_casting); // (5) runs in 40s(40s)
-// std::for_each(v.begin(), v.end(), add_virtual); // (6) runs in 46s(42s)
- }
-
- std::cout << sum << std::endl;
- return 0;
-}
-
Modified: sandbox/local/libs/local/example/tparam_trick.cpp
==============================================================================
--- sandbox/local/libs/local/example/tparam_trick.cpp (original)
+++ sandbox/local/libs/local/example/tparam_trick.cpp 2011-04-27 14:01:25 EDT (Wed, 27 Apr 2011)
@@ -24,11 +24,11 @@
= 0; // virtual call cannot be inlined
};
struct virtual_func {
- explicit virtual_func(func_interface& ref): ptr_(&ref) {}
+ explicit virtual_func(func_interface& func): func_(&func) {}
inline void operator()(const double& num)
- { (*ptr_)(num); }
+ { (*func_)(num); }
private:
- func_interface* ptr_;
+ func_interface* func_;
};
int main() {
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