-
Notifications
You must be signed in to change notification settings - Fork 738
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
Remove operator bool() from array_view implementation #140
Comments
Agree with the removal.
|
I agree, operator bool() is ambiguous here. We can check for a zero-length range with |
|
Is it a design decision to omit |
@ilyapopov No, just an implementation omission for the moment.
|
I'd love to see operator bool for ranges. :p http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3509.htm |
Consider what you would expect this code to do:
I would suggest that, if it is kept, |
@hpesoj operator bool() will not be kept. |
Damn, why not? I love operator book.
|
@OlafvdSpek back to my original comment: |
@neilmacintosh Okay! |
@neilmacintosh I'm familiar with the argument but I think it's kinda silly. It just takes some time to get used to.. AFAIK containers and ranges don't really have a null-state, they do have an empty state. |
Also note that you can't use empty() in a if (auto s = f()) context. |
@OlafvdSpek |
Why would you expect that? |
Because I'm used to it from checking pointers. So in my mind I read |
@Horstling In #202 I just made an extensive argument against the concept of a "null array". If |
@Horstling Numbers and iostreams can be checked like that too.. so it seems there's a problem with your thinking. ;) |
@hpesoj @OlafvdSpek |
@OlafvdSpek A lot of people (me included) consider implicit |
@hpesoj If statements are considered explicit conversions to bool. |
@Horstling Numbers don't have empty and null states, containers don't have null states and most ranges don't have null states. |
@Horstling I'm happy with removal of However, there is no ambiguity with regards to the "null" status of the array. Arrays cannot be null, and the belief that they can stems from a confusion about what an array is, which most likely stems from the way C/C++98 represents both optional values and arrays using pointers, and the associated bad practice of representing an optional value and an array using a single pointer. |
@OlafvdSpek But like I said, the whole discussion is the best point for not offering a bool conversion: There are very different opinions about what this conversion should do, so whatever it would do, some users would be surprised. Which is bad. |
@OlafvdSpek Okay, then I meant any conversion to |
@Horstling Talking about a null-sh state is confusing and suggestive. Question is, does a type have a natural mapping to bool? Pointers do, IMO numbers do too and IMO containers / ranges do as well. Let me ask, how often do you use is_null (for ranges)? What ranges are you currently using? |
Note that for string_view there were requests to guarantee data() wouldn't return null, effectively removing the null-state. |
Removing the null-state and having a I agree that the null-state is a relict from good ol' C arrays, and it might be a good idea to get this sorted out. But even if you remove the null-state from ranges, a |
If anyone isn't convinced that a "null span/array" isn't a thing, run this code:
@OlafvdSpek @Horstling I have realised that my rationale for disliking Therefore, I probably have to oppose
Using this criterion, numbers and ranges should not implement |
Why would your null_array require special care? A (for) loop over it works just fine. |
@OlafvdSpek It doesn't require special care, because
But this isn't even what we are discussing. It was just an example of how arrays could have valid/invalid states, and why this would be evil. And I suppose it depends on what you mean by "indistinguishable". But yeah, my point was that if |
@Horstling @hpesoj This conversation appears to have veered a little off-topic. I have now removed |
The operator encourages a usage pattern that is unclear about what property of the
array_view
is being tested.The text was updated successfully, but these errors were encountered: