Re: [Boost-users] Boost.Signals: strange bug in example program
-----Original Message----- From: Benjamin Winkler [mailto:Benjamin.Winkler@RWTH-Aachen.de] Sent: 07 June 2006 22:20 To: boost-users@lists.boost.org Subject: [Boost-users] Boost.Signals: strange bug in example program
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
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
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
Hello,
I tried to run this example and I got the same results, it prints 8 on
Microsoft Visual studio 2003 (7.1) as well.
I did try to debug it and ended up in "algorithm" file:
After adding cout:
template<class _FwdIt> inline
_FwdIt _Max_element(_FwdIt _First, _FwdIt _Last)
{ // find largest element, using operator<
_DEBUG_RANGE(_First, _Last);
_FwdIt _Found = _First;
cout<<*_Found<
Pranckevicius, Tadas wrote:
I tried to run this example and I got the same results, it prints 8 on Microsoft Visual studio 2003 (7.1) as well.
I did try to debug it and ended up in "algorithm" file:
After adding cout:
template<class _FwdIt> inline _FwdIt _Max_element(_FwdIt _First, _FwdIt _Last) { // find largest element, using operator< _DEBUG_RANGE(_First, _Last); _FwdIt _Found = _First; cout<<*_Found<
My Visual Studio.Net 2003 does not even have this function anywhere in the include directory. What precise version are you using? Have you replaced your standard library? Sebastian Redl
participants (2)
-
Pranckevicius, Tadas
-
Sebastian Redl