I have an std::list > internal to a class.
I'd like to expose begin() and end() functions from this class, that
iterate over the second element of the list. So basically I want the
user of the class to only see a sequence of floats.
transform_iterator seems to fit the bill, but I think I'm seriously
overcomplicating this. I've tried the following and it's not working.
I feel like this pair_second / pair_first, and iterator should either
already all be defined somewhere that I'm just not aware of, or be
much shorter to write than this.
template
struct pair_second : public std::unary_function, const Second&>
{
const Second& operator()(std::pair& pair) const {
return pair.second; }
};
template
struct pair_first : public std::unary_function, const First&>
{
const First& operator()(std::pair& pair) const {
return pair.first; }
};
template<class pair_type>
struct first_iterator
{
typedef boost::transform_iterator<
pair_first,
typename pair_type
> type;
};
template<class pair_type>
struct second_iterator
{
typedef boost::transform_iterator<
pair_second,
typename pair_type
> type;
};
typedef typename first_iterator::type float_iterator;
float_iterator begin()
{
return float_iterator(items_.begin(), second_iterator());
}
float_iterator end()
{
return float_iterator(items_.end(), second_iterator());
}
Any advice would be appreciated.
Thanks
Zach