Earlier quoted context omitted.
> 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 you…
Ahh you’re, right, I forgot about fully auto’d functions. I think want more structure than just auto everything, although the compilers should find mistakes with that. Concepts will be nice.
template
concept WesternishName = requires (T t) {
{ t.firstName } -> convertible_to;
{ t.lastName } -> convertible_to;
};
auto concatenate(WesternishName auto t) { return t.firstName + " " + t.lastName; }