Boost logo

Boost Users :

Subject: Re: [Boost-users] [signals] What's special about iterators passed to combiners?
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2010-05-14 09:21:56


On 14 May 2010 15:13, Boris Schaeling <boris_at_[hidden]> wrote:
> A reader of my book noticed that the sample program at
> http://en.highscore.de/cpp/boost/src/4.2.8/main.cpp which uses a combiner to
> return the smallest value of all slot values is buggy. The combiner's
> implementation is rather simple as iterators are simply forwarded to
> std::min_element():
>
> template <typename T>
> struct min_element
> {
>  typedef T result_type;
>
>  template <typename InputIterator>
>  T operator()(InputIterator first, InputIterator last) const
>  {
>    return *std::min_element(first, last);
>  }
> };
>

Your choice of typename here has me worried, since std::min_element
requires ForwardIterators, not InputIterators. That's also the
explanation for your last code example; it uses the iterators in a way
not allowed for input iterators.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net