There is code that works in C ++ 11 :
#include <algorithm> #include <iostream> #include <vector> #include <utility> #include <iterator> typedef std::pair<void*, int> pair; int main(){ std::vector<pair> s; std::vector<int> r; pair p1(NULL, 42); pair p2(NULL, 100500); s.push_back(p1); s.push_back(p2); std::transform(s.begin(), s.end(), std::back_inserter(r), static_cast<const int&(*)(const pair&)>(std::get<1>)); std::copy(r.begin(), r.end(), std::ostream_iterator<int>(std::cout, " ")); } Conclusion:
42 100500
I want to implement something like this in C ++ 03 without using a custom functor / function of the type:
struct F { int operator()(const pair& p) { return p.second; } }; or
int f(const pair& p) { return p.second; } and call the form:
std::transform(s.begin(), s.end(), std::back_inserter(r), F()); Can this be done with a chain of ready-made library adapters? std::get in C ++ 03 was not yet.
I also don't want to use a manual for loop instead of transform , since this entails mentioning the types of iterators, and the algorithms are not designed to write cycles by hand.
pair...map/multimapworks withpair, but how, having driven pairs into it, then perform a detour to get the values, and not to mention the iterator already for themap(as I understand does it not roll either?) As far as I remember, there are no other standard uses for thepair. Even if there is a solution, it will be something monstrous :( - Harry