/*************************************************************************
> File Name: observer.cpp
> Author:
> Mail:
> Created Time: Thu 02 Aug 2018 10:56:45 PM CST
************************************************************************/
#include<iostream>
#include <functional>
#include <vector>
template<typename RET, typename... ARGS>
class Sig
{
public:
typedef std::function<void(ARGS...)> Functor;
void Connect( Functor&& functor )
{
functor_.push_back(std::forward<Functor>(functor));
}
void Call( ARGS&&... args )
{
for( const Functor& f: functor_)
{
f(args...);
}
}
private:
std::vector<Functor> functor_;
};
int Add( int a, int b )
{
std::cout << a + b << std::endl;
return 0;
}
int Sub(int a, int b)
{
std::cout << a - b << std::endl;
return 0;
}
int Div( int a, int b )
{
std::cout << a/b << std::endl;
return 0;
}
int main()
{
Sig<int, int,int> hello;
hello.Connect(&Add);
hello.Connect(&Sub);
hello.Connect(&Div);
hello.Call( 1, 2 );
}