the.bay.news

Why does Deque.at return T instead of ?T

Ziggit
Why does Deque.at return T instead of ?T
I understand that the implementation for zig 0.16.0 is pub fn at(deque: *const Self, index: usize) T { assert(index < deque.len); return deque.buffer[deque.bufferIndex(index)]; } I would have expected to be something like this. pub fn at(deque: *const Self, index: usize) ?T { if(index >= deque.len) return null return deque.buffer[deque.bufferIndex(index)]; } Is there a reason why the function does not return an optional? the optional would be better because it gives you the ...

I understand that the implementation for zig 0.16.0 is pub fn at(deque: *const Self, index: usize) T { assert(index < deque.len); return deque.buffer[deque.bufferIndex(index)]; }…

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.