Select Implementation using Boost.Fusion

Okay, as an exercise I implemented the select function object in terms of Boost.Fusion's at_c<> sequence accessor function. The implementation is attached -- which works with standard containers that contain either standard pairs, or fusion sequences. This implementation relies on Boost.Fusion's adapted pair implementation to turn ordinary std::pair<>'s contained in a standard container (map, vector of pairs, etc) into fusion sequences. This implementation is much shorter than the earlier versions I've posted before. Should this be part of Boost.Fusion, or if there's interest should this little utility undergo a review for inclusion in Boost? The synopsis for using this library is shown as an example below: #include <map> #include <iostream> #include <iterator> #include <string> #include <algorithm> #include <cstdlib> #include <boost/select.hpp> using namespace std; int foo(int i) { return i * 2; }; int main(int argc, char * argv[]) { map<int, string> sample; sample.insert(make_pair(1, "Hello, World!")); transform(sample.begin(), sample.end(), ostream_iterator<string>(std::cout), boost::select<1>); // print "Hello, World!" transform(sample.begin(), sample.end(), ostream_iterator<int>(std::cout), boost::select<0> | foo); // print 2 return EXIT_SUCCESS; }; -- Dean Michael C. Berris Software Engineer, Friendster, Inc.
participants (1)
-
Dean Michael Berris