How can I enable perfect forwarding through a virtual function? I really have no desire to write every overload like in C++03.
You can't. Perfect forwarding only works by combining templates and rvalue-references, because it depends on what kind of real type T&&
evaluates to when T is specialized. You cannot mix templates and virtual functions.
However, you can might be able to solve your problem by some kind of type-erasure mechanism:
struct base {
virtual void invoke() = 0;
};
template <class T>
struct derived : public base {
derived( T&& yourval ) : m_value(std::forward(yourval)) {}
virtual void invoke() { /* operate on m_value.. */ }
T&& m_value;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With