|
|
|
|
|
by jcelerier
1452 days ago
|
|
> The goal of OOP or any programming system is to help you enforce invariants to improve correctness of a program. enforcing invariants means reducing the number of types that satisfy the invariant. I wouldn't call doing what you ask for "enforcing" any invariant. > Bonus: write it for any struct containing firstName and lastName. well, auto concatenate(auto t) { return t.firstName + " " + t.lastName; }
satisfies your condition - here's one that'll also handle middle names: https://gcc.godbolt.org/z/YfTYs6MMn ; again I don't think anyone wants this when they say "enforcing invariants", this does exactly the opposite of what is actually wanted.> I guess the future of C++ is that all code ever lives in headers. or in modules, which makes it very similar than other languages with generics instantiation |
|