I've always seen std::forward being utilized as below, utilized inside a template function
template<class T>
void foo(T&& arg): bar(std::forward<T>(arg)){}
Suppose I want to do this.
class A
{
private:
std::function<void()> bar;
public:
template<class T>
void foo(T&& arg): bar(std::forward<T>(arg)){}
}
Since bar already has its type defined. Can I rewrite it by directly specifying T as std::function >? Compiler doesn't seem happy about it. Why?
class A
{
private:
std::function<void()> bar;
public:
void foo(std::function<void()>&& arg): bar(std::forward<std::function<void()>>(arg)){}
}
Aucun commentaire:
Enregistrer un commentaire