C++ 带有min_元件的增压信号

C++ 带有min_元件的增压信号,c++,boost,C++,Boost,我正在写一个小例子,试图理解boost::signal的多个返回值。然而,结果对我来说似乎很奇怪 #include <boost/signal.hpp> #include <iostream> #include <algorithm> int func1() { return 3; } int func2() { return 4; } int func3() { return 2; } template

我正在写一个小例子,试图理解boost::signal的多个返回值。然而,结果对我来说似乎很奇怪

#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 is required by 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;
}
#包括
#包括
#包括
int func1()
{ 
返回3;
} 
int func2()
{ 
返回4;
} 
int func3()
{
返回2;
}
模板
结构最小元素
{ 
typedef T result_type;//boost::signal需要result_type
模板
T运算符()(先输入计算器,后输入计算器)常量
{

std::cout奇怪。替换
操作符()

T运算符()(先输入位,后输入位)常量
{
输入计算器结果=第一个;
而(++第一个!=最后一个){
//*结果;
标准::cout
T operator()(InputIterator first, InputIterator last) const 
{
    InputIterator result = first;

    while (++first != last) {
//      *result;
        std::cout<<*first<<std::endl;
    }

    return T();
}