I've heard that noexcept keyword is more like 'it should never throw an exception' rather than 'it doesn't'.
I don't think it's good to use noexcept keyword if I'm not sure it throws an exception or not, but noexcept keyword is sometimes related to the performance like in a move constructor.
So I tried to use noexcept qualifiers, but it gets harder if it has multiple statements in the definition and it becomes a kind of copy-and-paste thing.
template <class T>
void f(T&& t)
noexcept(noexcept(statement_1) &&
noexcept(statement_2) &&
noexcept(statement_3) &&
noexcept(statement_4) &&
noexcept(statement_5))
{
statement_1;
statement_2;
statement_3;
statement_4;
statement_5;
}
I think the compiler can figure out whether the definition of a function consists of non-throwing statements, so it will be easier to utilize noexcept if there's an expression like noexcept(auto), but it seems that there is no such thing in the standard.
Is there any way to simplify the noexcept expression?
Aucun commentaire:
Enregistrer un commentaire