4 ms·
Is that really so different from the following C++ equivalent? auto SmallestFactor(int32_t n) -> std::pair<int32_t, bool> { ... }
by jack_h 4y ago
Is that really so different from the following C++ equivalent?
auto SmallestFactor(int32_t n) -> std::pair<int32_t, bool> { ... }
- PaulDavisThe1st 4y agoI guess I don't understand what role the -> plays there. I must be too old school, I suppose.
- alpaca128 4y agoI can't speak for the C++ example, but in your code snippet `->` points to the return type. The function takes an integer argument and effectively turns it into a tuple, so: `f(i32) -> (i32, bool)`.
- int_19h 4y agoIn this particular example, all it does is reverse the order of return type wrt arguments and function name. I still find this syntax more readable with complicated return types because you no longer have to carefully parse it to see where the type ends and the name begins. In the more general case, having the return type follow the function name means that it can reference parameters in sizeof(), decltype() etc.