Topic: A novel(?) function object argument binding mechanism
Author: Jaakko =?iso-8859-1?Q?J=E4rvi?= <jaakko.jarvi@cs.utu.fi>
Date: 1999/10/25 Raw View
Hello,
This is an announcement of the availability of the BINDER LIBRARY. This
library implements a simple and versatile function argument binding
mechanism, which can be used with STL algorithms.
Compared to the rather limited standard binders (bind1st, bind2nd), the
library makes argument binding easy and general: arbitrary arguments of
(almost) any C++ function can be bound.
The basic idea is that the function arguments contain special
placeholders (free1 and free2 below), which indicate the unbound
arguments. For example:
double addmult(double x, double y, double z) { return x + y * z; }
vector<double> x,y,result;
...
// for each element i compute: result[i] = x[i] + y[i] * 10
transform(x.begin(), x.end(), y.begin(), result.begin(),
bind(addmult, free1, free2, 10));
...
// for each element i compute: result[i] = 10 + x[i] * -1
transform(x.begin(), x.end(), result.begin(),
bind(addmult, 10, free1, -1));
In addition to binders, the library implements a general purpose TUPLE
template. With tuples, you can write
tuple<int, int, double> add_mult_div(int a, int b) {
return make_tuple(a+b, a*b, double(a)/double(b));
}
...
int x, y; double z;
...
tie(x, y, z) = add_mult_div(1,2);
after this code, x == 3, y == 2, z == 0.5
The library + a detailed description of its functionality is available
at
www.cs.utu.fi/BL
There are some mild license conditions, but basically it is free
software. The library is more or less in an experimental phase, so
feedback is appreciated.
Best Regards
Jaakko J rvi
--
--- Jaakko J rvi, jaakko.jarvi@cs.utu.fi
--- Turku Centre for Computer Science (www.tucs.fi)
--- Lemmink isenkatu 14 A, FIN-20520 Turku, Finland
--- Phone: +358-2-333 8656, Fax: +358-2-333 8600
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]