jeudi 23 février 2017

Why not work if an lvalue-ref-arg and an rvalue-ref-arg are passed as universal-ref args?

#include <type_traits>

template<typename T>
void f(T&& a, T&& b)
{}

int main()
{
    int n;
    f(n, std::move(n));
}

T&& is a universal reference type, so I think decltype(a) should be int& and decltype(b) should be int&&.

However, the code above generates the following error:

main.cpp(13,2): error : no matching function for call to 'f' f(n, std::move(n));

main.cpp(7,6): note: candidate template ignored: deduced conflicting types for parameter 'T' ('int &' vs. 'int')

void f(T&& a, T&& b)

1 error generated.

Why not work if an lvalue-ref-arg and an rvalue-ref-arg are passed as universal-ref args?

ps: My compiler is clang 4.0.

Aucun commentaire:

Enregistrer un commentaire