News for hackers. Stuff that matters.
Re:The Swift Array Design (2014) by jimbob45 on Sunday March 21, 2021 @11:30PM (#26536566)
Isn’t your second one just a simple ternary macro to check if null and return if so?
Re:The Swift Array Design (2014) by s3cur3 on Monday March 22, 2021 @06:51AM (#26539077)
Not 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.