C<X> expand( C<X> container, F<C,X,Y> functor );
where :
Parameter | Description |
---|---|
container | an STL container of type C holding objects type X |
functor | a functor taking a parameter of type X and returning a container of type C with objects of type Y |
A container of type C holding objects of type X
Calls the functor for each element in the input container and merges the resulting collections into a single one.
// source : examples/expand_example.cpp #include <iostream> #include <list> #include <algorithm> #include "sftl.h" using namespace std; // collapses a number into digits list<short> get_digits( int x ) { list<short> digits; while (x>0) { digits.push_front( x % 10 ); x/=10; } return digits; } void print( short x ) { cout << x << endl; } int main() { // create vector of numbers int numbers [] = {101,24,55,71}; list<int> v_numbers( &numbers[0], &numbers[4] ); // obtain all digits list<short> all_digits = expand( v_numbers, get_digits ); // print them apply( all_digits, print ); // prints 1 0 1 2 4 5 5 7 1 }