r/cpp • • 13d 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?

65 Upvotes

94 comments sorted by

View all comments

3

u/Challanger__ 13d ago
  1. please fix code formatting in post
  2. contracts may not even make it alive into the standard

5

u/Wonderful-Habit-139 13d ago

Could they make it dead into the standard?

8

u/-dag- 13d ago

They already are.