r/cpp • u/grishavanika • 6d ago
std::contracts::controls::enforced
From P4451R2,
#include <contracts>
int f(int x)
pre<std::contracts::controls::enforced>(x > 0)
post<std::contracts::controls::enforced>(r : r > 0)
{
contract_assert<std::contracts::controls::enforced>(x > 0);
return x;
}
Long, 3 levels deep namespace? And
Because the label is found by ordinary name lookup, a namespace alias or a using-directive works
as well:
namespace scl = std::contracts::controls;
Same issue as with C++11 UDL: inconvinient to use, especially in headers, since include + alias is required - aliases will not make it better, in my opinion.
That makes me sad. Am I the only one?
68
Upvotes
View all comments
Show parent comment
0
u/13steinj 5d ago
That is a much weaker rule than the one that has spontaneously appeared in papers.
By definition, all attributes mentioned in the standard do not fall under this category. It is perfectly fine to have these contract controls be attributes.