Boost logo

Boost Users :

From: Benjamin Winkler (Benjamin.Winkler_at_[hidden])
Date: 2006-06-07 17:20:02


Hi,

I just downloaded the newest boost library 1.33.1 and compiled the "maximum.cpp" example
from the Signals library, which goes like this:

#include <algorithm>
#include <iostream>
#include <boost/signals/signal2.hpp>

template<typename T>
struct maximum {
  typedef T result_type;

  template<typename InputIterator>
  T operator()(InputIterator first, InputIterator last) const
  {
    if (first == last)
      throw std::runtime_error("Cannot compute maximum of zero elements!");
    return *std::max_element(first, last);
  }
};

int main()
{
  boost::signal2<int, int, int, maximum<int> > sig_max;
  sig_max.connect(std::plus<int>());
  sig_max.connect(std::multiplies<int>());
  sig_max.connect(std::minus<int>());
  sig_max.connect(std::divides<int>());

  std::cout << sig_max(5, 3) << std::endl; // prints 15

  return 0;
}

As stated, the correct result would be 15 but the output really is 8.
However, when I print the values via
  std::copy(first, last, std::ostream_iterator<T>(std::cout, " "));
I get "8 15 2 1 ", which means that the values are calculated correctly.

This error occurs with Microsoft Visual Studio 2005 (8.0) as well as MinGW 3.4.2.
I even tried replacing std::max_element() with my own function, which expectedly
didn't help.

Seems like a bug to me, but I can't track it down. Could it be some issue with
copying the iterator?

Benjamin Winkler


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