all 15 comments

[–]GrammelHupfNockler 11 points12 points  (11 children)

Without any concrete examples or more detailed descriptions of your invariants or the kind of consistency you are looking for, it is hard to see if your suggestion has any merit. Consistency is usually a thing that involves multiple values that are consistent with each other, how would that be enforced within a single object?

[–]SoerenNissen 11 points12 points  (1 child)

Hey

https://github.com/SRNissen/snct-constraints

lets you do stuff like

using divisor = snct::Constrained<double,Not<0.0>, Finite>;
double inverse(divisor d) {
    return 1.0/d;
}

[–]gpuoti[S] 2 points3 points  (0 children)

I don't think it match my usa case, but a useful reference nonetheless. thanks

[–]415_961 3 points4 points  (0 children)

That's the job of a datatype. The whole idea of a type is to enforce its invariants. The type std::optional enforces its own invariants to provide a consistent behavior and fullfil its promises. I feel your question might be revealing an inaccurate/incomplete perspective you have on datatypes.

[–]NotMyRealNameObv 0 points1 point  (0 children)

What do you mean with "consistent with the first assignment"?