[PD-ot] [PD] poor performance when saving an abstraction when many copies are loaded in a patch

Claude Heiland-Allen claudiusmaximus at goto10.org
Sat Jan 12 01:46:11 CET 2008


Hi,

Mathieu Bouchard wrote:
> The only kind of reason you'd use macros, is because C++ doesn't handle 
> function calls well. Oh, most of the time it does; but it refuses to 
> consider data types as being values. That's where I use macros instead. 
> Nowadays, I even pass macros as arguments to macros.

Isn't that what templates are for?

Here's an example I just knocked together:

//////////////////////////////////////////////////////////////////////
#include <vector>
#include <list>
#include <iostream>

template<typename C, typename T> T foldl(C v, T (*op)(T, T), T seed) {
   T x = seed;
   for (typename C::const_iterator i = v.begin(); i != v.end(); ++i) {
     x = op(x, *i);
   }
   return x;
}

template<typename T> T add(T l, T r) { return l + r; }

int main(void) {
   std::vector<double> u;
   for (double i = 0; i < 10; ++i) {
     u.push_back(i);
   }
   std::list<int> v;
   for (int i = 0; i < 10; ++i) {
     v.push_back(i);
   }
   double x = foldl(u, add, double(0));
   int    y = foldl(v, add, int(0));
   std::cout << x << std::endl << y << std::endl;
   return 0;
}
//////////////////////////////////////////////////////////////////////


Claude
-- 
http://claudiusmaximus.goto10.org




More information about the PD-ot mailing list