3 ms·
Isn’t your second one just a simple ternary macro to check if null and return if so?
by jimbob45 6y ago
Isn’t your second one just a simple ternary macro to check if null and return if so?
- s3cur3 6y agoNot in C++ or Swift, no—to do it in the general case requires trying to cast each member of the array to the Derived type, and returning the null optional if any of those conversions fails. E.g., given an array of Animal, you’d like to see if you can convert it to an array of Dog. Neither the compiler nor the runtime stores information on the array itself to say “it just so happens that the concrete Animal type of all the things I hold is [Dog/Cat/a mix of both],” so you have to go through the elements one by one.