-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
isEmpty for Deque type #14162
isEmpty for Deque type #14162
Conversation
Who thinks we should just have a template that tries to |
That, or template isEmpty(x): bool =
var result = true
for _ in x:
result = false
break
result Works for iterators and efficient for cstring/lists. |
the iterator thing should be only a overload for the other cases imo |
If you use |
you're right. however an iterator can take a lot of time to produce its first element : in this case you also need to overload isEmpty as it would be probably faster. |
I wouldn't want nim to produce C code for a 1 or 2 assignments + a loop just for an access to a len/count field in some cases. hm I don't think it would be optimized well enough but i might be wrong? |
This is how it should be done template isEmpty*(x: typed): bool = x.len == 0
# added to system.nim
proc isEmpty*(x: cstring): bool {.inline.} = x == nil or x[0] == '\0' # specialization Yes, it's a system.nim extension but a good one. |
well, an overload for cases where there is no |
Maybe Edit: The types in the |
|
I have a new name, PR can do Araq's suggestion for now but maybe with |
Closing for nim-lang/RFCs#217 -- thanks for moving the ball forward! |
We talked about implementing this for collection types; here's one.