0

I have the following code:

template<typename T>
class Dispatcher
{
public:
    void operator()(T&& v) {}
};

struct S
{
    Dispatcher<S*> dispatcher;

    void test()
    {
        dispatcher(this);
    }
};

And it gives me an error error C2664: 'void Dispatcher<S *>::operator ()(T &&)' : cannot convert argument 1 from 'S *const ' to 'S *&&' in VisualStudio only. In gcc and clang it works ok.

I searched the documentation and the only thing I found here is: When used according to the following recipe in a function template, forwards the argument to another function with the value category it had when passed to the calling function.

Does that means perfect forwarding is guaranteed to work only with functions? Does gcc and clang are not following the standard?

nikitablack
  • 4,359
  • 2
  • 35
  • 68

0 Answers0