I've read existing questions about this standard conversion. However, I didn't find a satisfying answer.
I have this piece of code which shows that the T*
overload is chosen over the T&&
one. From what I understood, the forwarding reference overload should bind everything, unless another overload is a perfect match.
In the following code, tab
is a char const(&)[4]
.
Could someone explain to me why the array-to-pointer conversion is performed here? And if there is a way to workaround that conversion, I'm all ears!
(coliru link)
#include <utility>
template <typename T>
void f(T&& lol)
{
}
template <typename T>
void f(T* pof)
{
static_assert(sizeof(T) && false, "");
}
template <typename T>
struct S;
int main(int argc, char *argv[])
{
decltype("lol") tab = "lol";
S<decltype(tab)> s;
f("lol");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire