Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71744 - sandbox/local/libs/local/example
From: lorcaminiti_at_[hidden]
Date: 2011-05-05 14:10:20


Author: lcaminiti
Date: 2011-05-05 14:10:19 EDT (Thu, 05 May 2011)
New Revision: 71744
URL: http://svn.boost.org/trac/boost/changeset/71744

Log:
Adding polymorphism temporary examples...
Added:
   sandbox/local/libs/local/example/p00.cpp (contents, props changed)
   sandbox/local/libs/local/example/p01.cpp (contents, props changed)
   sandbox/local/libs/local/example/p02.cpp (contents, props changed)
   sandbox/local/libs/local/example/p03.cpp (contents, props changed)
   sandbox/local/libs/local/example/p10.cpp (contents, props changed)
   sandbox/local/libs/local/example/p11.cpp (contents, props changed)

Added: sandbox/local/libs/local/example/p00.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p00.cpp 2011-05-05 14:10:19 EDT (Thu, 05 May 2011)
@@ -0,0 +1,35 @@
+
+#include <iostream>
+#include <vector>
+#include <algorithm>
+
+struct global_add {
+ global_add(double& _sum, const int& _factor): sum(_sum), factor(_factor) {}
+ template<typename T>
+ inline void operator()(T num) {
+ std::cout << "sum = " << sum << " + " << factor << " * " << num <<
+ std::endl;
+ sum += factor * num;
+ }
+private:
+ double& sum;
+ const int& factor;
+};
+
+int main() {
+ double sum = 0.0;
+ int factor = 10;
+
+ global_add add(sum, factor);
+
+ v[0] = -1.0; v[1] = -2.0; v[2] = -3.0;
+ std::for_each(v.begin(), v.end(), l);
+
+ std::vector<std::string> s(3);
+ s[0] = "aa"; s[1] = "bb"; s[2] = "cc";
+ std::for_each(s.begin(), s.end(), l);
+
+ std::cout << sum << std::endl;
+ return 0;
+}
+

Added: sandbox/local/libs/local/example/p01.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p01.cpp 2011-05-05 14:10:19 EDT (Thu, 05 May 2011)
@@ -0,0 +1,31 @@
+
+#include <iostream>
+#include <vector>
+#include <algorithm>
+
+struct global_func {
+ template<typename T>
+ void operator()(T num) {
+ }
+private:
+ double& sum;
+ const int& factor;
+};
+
+int main() {
+ double sum = 0.0;
+ int factor = 10;
+
+ global_ add(sum, factor);
+
+ v[0] = -1.0; v[1] = -2.0; v[2] = -3.0;
+ std::for_each(v.begin(), v.end(), l);
+
+ std::vector<std::string> s(3);
+ s[0] = "aa"; s[1] = "bb"; s[2] = "cc";
+ std::for_each(s.begin(), s.end(), l);
+
+ std::cout << sum << std::endl;
+ return 0;
+}
+

Added: sandbox/local/libs/local/example/p02.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p02.cpp 2011-05-05 14:10:19 EDT (Thu, 05 May 2011)
@@ -0,0 +1,28 @@
+
+#include <boost/spirit/include/phoenix.hpp>
+#include <iostream>
+#include <vector>
+
+int main() {
+ using boost::phoenix::arg_names::_1;
+
+// __some_local_template_type__ local_add =
+// let(_f = cref(factor))[ref(sum) += _f * _1];
+
+// boost::phoenix::actor<boost::phoenix::argument<1> >
+// boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::plus_assign_eval, boost::fusion::vector<boost::phoenix::reference<double>, boost::phoenix::composite<boost::phoenix::multiplies_eval, boost::fusion::vector<boost::phoenix::value<int>, boost::phoenix::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >
+
+ boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::shift_left_eval, boost::fusion::vector<boost::phoenix::composite<boost::phoenix::shift_left_eval, boost::fusion::vector<boost::phoenix::reference<std::basic_ostream<char, std::char_traits<char> > >, boost::phoenix::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >, boost::phoenix::value<const char*>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >
+ f = std::cout << _1 << "\n";
+
+ std::vector<double> v(3);
+ v[0] = 1.0; v[1] = 2.0; v[2] = 3.0;
+ std::for_each(v.begin(), v.end(), f);
+
+ std::vector<std::string> s(3);
+ s[0] = "aa"; s[1] = "bb"; s[2] = "cc";
+ std::for_each(s.begin(), s.end(), std::cout << _1 << "\n");
+
+ return 0;
+}
+

Added: sandbox/local/libs/local/example/p03.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p03.cpp 2011-05-05 14:10:19 EDT (Thu, 05 May 2011)
@@ -0,0 +1,22 @@
+
+#include <boost/spirit/include/phoenix.hpp>
+#include <iostream>
+#include <vector>
+
+int main() {
+ using boost::phoenix::arg_names::_1;
+
+ boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::shift_left_eval, boost::fusion::vector<boost::phoenix::composite<boost::phoenix::shift_left_eval, boost::fusion::vector<boost::phoenix::reference<std::basic_ostream<char, std::char_traits<char> > >, boost::phoenix::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >, boost::phoenix::value<const char*>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >
+ f = std::cout << _1 << "\n";
+
+ std::vector<double> v(3);
+ v[0] = -1.0; v[1] = -2.0; v[2] = -3.0;
+ std::for_each(v.begin(), v.end(), f);
+
+ std::vector<std::string> s(3);
+ s[0] = "aa"; s[1] = "bb"; s[2] = "cc";
+ std::for_each(s.begin(), s.end(), f);
+
+ return 0;
+}
+

Added: sandbox/local/libs/local/example/p10.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p10.cpp 2011-05-05 14:10:19 EDT (Thu, 05 May 2011)
@@ -0,0 +1,33 @@
+
+#include <iostream>
+#include <vector>
+#include <algorithm>
+
+template<typename T>
+struct func {
+ func(void *obj, void (*call)(void*, T)): obj_(obj), call_(call) {}
+
+};
+
+int main() {
+ struct fctor {
+ void operator()(const double& num) const { std::cout << num << std::endl; }
+ void operator()(const std::string& num) const { std::cout << num << std::endl; }
+ };
+
+ void BOOST_LOCAL_FUNCTION_PARAMS(
+ types(const double&, const std::string&) num) {
+ std::cout << num << std::endl;
+ }
+
+ std::vector<double> v(3);
+ v[0] = -1.0; v[1] = -2.0; v[2] = -3.0;
+ std::for_each(v.begin(), v.end(), f);
+
+ std::vector<std::string> s(3);
+ s[0] = "aa"; s[1] = "bb"; s[2] = "cc";
+ std::for_each(s.begin(), s.end(), f);
+
+ return 0;
+}
+

Added: sandbox/local/libs/local/example/p11.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/p11.cpp 2011-05-05 14:10:19 EDT (Thu, 05 May 2011)
@@ -0,0 +1,23 @@
+
+#include <boost/local/fuction.hpp>
+#include <iostream>
+#include <vector>
+#include <algorithm>
+
+int main() {
+ void BOOST_LOCAL_FUNCTION_PARAMS(
+ types(const double&, const std::string&) num) {
+ std::cout << num << std::endl;
+ } BOOST_LOCAL_FUNCTION_NAME(l)
+
+ std::vector<double> v(3);
+ v[0] = -1.0; v[1] = -2.0; v[2] = -3.0;
+ std::for_each(v.begin(), v.end(), l);
+
+ std::vector<std::string> s(3);
+ s[0] = "aa"; s[1] = "bb"; s[2] = "cc";
+ std::for_each(s.begin(), s.end(), l);
+
+ return 0;
+}
+


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