I am not using C++11 (otherwise I would use lambdas)
I have iterators to an input data structure and output data structure. I want to do some operations on the input data and store the result in the output. Note that the start and end types may be different (int -> float for example).
I tried to model my function after the standard algorithms and gave it the following prototype
template<class INPUT_ITR, OUTPUT_ITR>
void f(INPUT_ITR in_it, INPUT_ITR in_it_end, OUTPUT_ITR out_it, ContextStuff)
The function does many different things depending on the context. Sometimes the function only needs to use one functor, so the line of code looks like this
transform(in_it, in_it_end, out_it, Functor1());
But sometimes the function wants to use a series of functors on each data element. Is there a way I can create a chain of functors as a single functor to use in transform? The functors for the chain will be known at compile type.
For example
transform(in_it, in_it_end, out_it, CHAIN(Functor1(), Functor2()));
Performs Functor1 on *in, then Functor2 on the result, then stores in *out.
I can inherit my functors from unary_function for the solution.
result_type
). So if you want to do this all your functors will have to have aresult_type
typedef. – FoziCHAIN
macros and classes that forward various amounts of parameters. – Fozi