mardi 22 septembre 2015

Check if an expression compiles including all implicit conversion

Consider the following code:

void f(auto& i, auto& j)
{
    static_assert(/* SOMETHING */, "");
    // function body here...
}

I want the /* SOMETHING */ part to check whether the following code compiles (taking into account all the standard rules, like implicit conversion rules):

i += j;

I tried:

sizeof(std::declval<decltype(i)>() += std::declval<decltype(j)>());

but it fails.

What is the correct way to do it?

Aucun commentaire:

Enregistrer un commentaire