Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2007-11-20 02:43:46

Hi Everyone,

I'm CC'ing Mark Rogers who, upon looking at the Author of
Boost.Functional (and I assume is the maintainer) may be able to help
out with this regard.

Recently, I've implemented a simple utility which allows users to
select the nth element of an STL pair / Boost.Tuple in conjunction
with STL algorithms. This allows precisely the following usage

std::map<int, int> int_map;
int_map[0] = 1;
int_map[1] = 2;

std::transform(int_map.begin(), int_map.end(),
  std::ostream_iterator<int>(std::cout, " "),
  boost::select<1>()); // output: "1 2 "

This is a generalization of the SGI select1st and select2nd function objects.

It also works with a container of Boost.Tuple's:

std::list<boost::tuple<double, double, double> > coord_list;
coord_list.push_back(boost::make_tuple(1.0, 2.0, 3.0));
coord_list.push_back(boost::make_tuple(4.0, 5.0, 6.0));

std::transform(coord_list.begin(), coord_list.end(),
  std::ostream_iterator<double>(std::cout, " "),
  boost::select<0>()); // output "1.0 4.0 "

I've re-attached the implementation, for comments and review for
inclusion in Boost.Functional.

Thanks very much, and I hope to hear from you guys soon.

Dean Michael C. Berris
Software Engineer, Friendster, Inc.
[+63 928 7291459]
[+1 408 4049523]

Boost list run by bdawes at, gregod at, cpdaniel at, john at