boost::bind 패러디
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
//#include <boost/bind.hpp>
namespace
{
class placeholder {};
placeholder _1;
}
template <typename R,typename T, typename Arg>
class simple_bind_t
{
public:
typedef R (T::*fn)(Arg);
simple_bind_t(fn f,const T& t):fn_(f),t_(t)
{}
R operator()(Arg a)
{
return (t_.*fn_)(a);
}
private:
fn fn_;
T t_;
};
template <typename R, typename T, typename Arg>
simple_bind_t<R,T,Arg> simple_bind(
R (T::*fn)(Arg),
const T& t,
const placeholder&)
{
std::cout << typeid(R).name() << std::endl
<< typeid(T).name() << std::endl
<< typeid(Arg).name() << std::endl;
return simple_bind_t<R,T,Arg>(fn,t);
}
class Test
{
public:
void do_stuff(const std::vector<int>& v)
{
std::copy(v.begin(),v.end(),
std::ostream_iterator<int>(std::cout," "));
}
};
template <typename R,typename T,typename Arg>
int my_mem_fun(R (T::*f)(Arg))
{
std::cout << typeid(R).name() << std::endl
<< typeid(T).name() << std::endl
<< typeid(Arg).name() << std::endl;
return 1;
}
class Cla1
{
public:
std::vector<int> fun1(float val)
{
return std::vector<int>();
}
};
int main()
{
Test t;
std::vector<int> vec;
vec.push_back(42);
vec.push_back(55);
vec.push_back(88);
simple_bind(&Test::do_stuff,t,_1)(vec);
my_mem_fun(&Cla1::fun1);
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Error configuring application listener of class org.springframework.web.context.ContextLoaderListeneSolution: 1. Copy org.springframework.web-3.0.5.RELEASE.jar to the WEB-INF/lib directory 2. Add in web.xml contextConfig...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.