My task is to implement my own std::ref function. I know there is a reference_wrapper functor, which helps to the std::ref. But how could I implement these functions/classes. I think about the following:
template <class T>
struct myreference_wrapper{
T& functor;
myreference_wrapper(T& t):functor(t){}
void operator()('parameter') {
functor('parameter');
};
};
template<class T>
myreference_wrapper<T> myref(T& t){
myreference_wrapper<T> functor(t);
return functor;
}
When we call myref, we can not use template parameters, because std::ref does not use template parameters. But when we call operator() we need to know its parameters, because we want to pass them on to the functor's operator() (I signed it with 'parameter'). How does std::ref do this without any template parameter?
Aucun commentaire:
Enregistrer un commentaire