c++ - boost signal with min_element -


i writing little example try understand multiple return values of boost::signal. however, result seems weired me.

#include <boost/signal.hpp>  #include <iostream>  #include <algorithm>   int func1()  {      return 3;  }   int func2()  {      return 4;  }   int func3() {     return 2; }  template <typename t>  struct min_element  {      typedef t result_type;  //result_type required boost::signal      template <typename inputiterator>      t operator()(inputiterator first, inputiterator last) const      {         std::cout<<*std::min_element(first, last)<<std::endl;  //i got 3 here         return t(first, last);      }  };   int _tmain(int argc, _tchar* argv[]) {     boost::signal<int (), min_element<std::vector<int> > > s;      s.connect(func1);      s.connect(func2);      s.connect(func3);     std::vector<int> v = s();     std::cout<<*std::min_element(v.begin(),v.end())<<std::endl; //i got 2 here     return 0; } 

the first min_element output "3" while second output "2". "2" smallest number among three. don't know what's wrong first one. in operator() tried iterate first last , got sequence "3,4,2" seems correct. why min_element give me "3" instead?

the code compiled vs2010 sp1. version of boost 1.46.1 latest one.

thanks in advance.

michael

weird. replacing operator():

t operator()(inputiterator first, inputiterator last) const  {     inputiterator result = first;      while (++first != last) { //      *result;         std::cout<<*first<<std::endl;     }      return t(); } 

works, dereference result, first , result both stuck @ 3. std::min_element doing; found implementation's source , stripped down you've seen above.

i have no idea what's going on.

this boost 1.38.0 on gcc 4.5.0.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -