From: Andy Sawyer <[EMAIL PROTECTED]> To: Boost mailing list <[EMAIL PROTECTED]> Subject: [boost] Re: functors for taking apart std::pair? Date: Thu, 10 Jul 2003 22:10:42 +0100
>>>>> "ED" == Edward Diener <[EMAIL PROTECTED]> writes: ED> Marshall Clow wrote: >> I recently had a need for a functor to return a component of a >> std::pair, and I was surprised to see that they didn't exist >> either in the standard library or in boost. ED> Matt Austern lists in his excellent book "Generic Programming ED> and the STL" the functors select1st and select2nd for getting a ED> pair's "first" and "second" members repsectively. His note to ED> both says that they were in the original HP STL and in the SGI ED> STL although they are not present in the current C++ Standard ED> Library. Marshall's "first" and "second" are slightly different to the HP versions: template <class T1, class T2> struct first: std::unary_function< std::pair <T1, T2>, T1> ... vs. template<typename Pair> struct select1st : std::unary_function< Pair, typename Pair::first_type> ... The HP version has the advantage of working for "pair-like" pairs other than std::pair, and (IIRC) it returns a reference to (rather than a copy of) the selected member. FWIW, I've found both versions (or their moral equivalent) useful over the years. I think these disappeared from the standard around the same time as project1st/project2nd? (or at least, didn't make it in at around the same time :) Regards, Andy S. (/me disappears below the boost rader for a couple more years ;)) -- "Light thinks it travels faster than anything but it is wrong. No matter how fast light travels it finds the darkness has always got there first, and is waiting for it." -- Terry Pratchett, Reaper Man _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost