Interesting, I haven't thought about using it in C++ before.<p>It's an idea that has existed for a long time in languages geared toward safety-critical systems.<p>E.g. Derived Types in Ada: <a href="https://fsharpforfunandprofit.com/posts/designing-with-types-discovering-the-domain/" rel="nofollow">https://fsharpforfunandprofit.com/posts/designing-with-types...</a><p>It is sometimes used in Ocaml or F# for domain-specific types: <a href="https://fsharpforfunandprofit.com/posts/discriminated-unions/#single-cases" rel="nofollow">https://fsharpforfunandprofit.com/posts/discriminated-unions...</a>
This is a very useful methodology. There's a similar blog post called "parse, don't validate" [1] which is very good.<p>[1] <a href="https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/" rel="nofollow">https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...</a>