mercredi 26 août 2015

Is expression inside decltype executed, or just being checked for validation?

By using Expression SFINAE, you can detect if some operator or operation is supported or not.

for example,

template <class T>
auto f(T& t, size_t n) -> decltype(t.reserve(n), void())
 { t.reserve(n); }

My question is that t.reserve(n) inside decltype get executed or not?

If yes, does that mean t.reserve(n) got executed twice, one inside decltype and the other one inside the function body?

If not, is it just checked for validation during compilation time? But why it is not executed, I thought all the expressions in the comma separated expression list will get executed.

Aucun commentaire:

Enregistrer un commentaire