$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] Iterating over the seconds of a list of pairs
From: Björn Karlsson (Bjorn.Karlsson_at_[hidden])
Date: 2009-08-09 02:38:50
Hello Rob,
> To enable writing to the element.second, shouldn't that 'second'
> extractor return a reference?
Good point, and that's certainly possible to do. The function object needs to be changed like so (note that the argument to the function call operator is now passed as a reference rather than reference to const):
// Extract the second element of a pair
template <typename T> class pair_second_t
{
public:
typedef T& result_type;
template <typename U> result_type operator()(std::pair<U,T>& element) const
{
return element.second;
}
};
Cheers,
Bjorn Karlsson
www.skeletonsoftware.net