Search code examples
sfinaervalue-referencevariadic

SFINAE with std::is_rvalue_reference for variadic template argument list fails


I try to implement a function taking a variable list of rvalue references. It looks like this:

template <
    typename... Args,
    typename = std::enable_if_t<std::conjunction<
        std::is_rvalue_reference<Args>...>::value>
>
void myfunc(Args&&... args)
{ }

When I try to call it like this:

void doit()
{
    int x;

    myfunc(std::move(x));
}

The compiler tells me that he cannot find the function. If i remove the SFINAE check it works. Do I miss something here, or is the compiler wrong? I'm using Visual Studio with toolsets v140 and v141.

Thanks in advance, Martin


Solution

  • Args is not an rvalue reference, Args&& is.

    #include <type_traits>
    #include <utility>
    
    template <
        typename... Args,
        typename = std::enable_if_t<std::conjunction<
            std::is_rvalue_reference<Args&&>...>::value>
    >
    void myfunc(Args&&... args) { }
    
    struct probe {};
    
    int main() {
        probe x;
    
        // this compiles
        myfunc(std::move(x));
    
        // this does not
        myfunc(x);
    
        return 0;
    }