3 ms·
Exactly. You spell auto or an interface or base class whose derived class cannot be named. I think both are ok. In the latter case you can name the interface in
by germandiago 3y ago
Exactly. You spell auto or an interface or base class whose derived class cannot be named. I think both are ok. In the latter case you can name the interface instead of auto.
Yes, auto is a perfectly valid return type, usually quite useful in generic code.
However, in generic code, starting at C++20, I would recommend to use concepts to name a return type that can be many different thing but that is compliant with the same "compile-time" interface.
You could do:
forward_range auto f(auto && input);
You do not spell the return type but you are saying that type conforms to forward_range. Note that the auto type returned
could be one of many unrelated types and it is computed at compile-time.