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

not_null cannot (and should not) be used with span #399

Open
hpesoj opened this Issue Nov 19, 2015 · 5 comments

Comments

Projects
None yet
4 participants
@hpesoj

hpesoj commented Nov 19, 2015

F.18 suggests that not_null can be used with span and string_span, but my tests would suggest otherwise. This behaviour seems correct, as arrays and strings cannot be null (null std::array or std::string anyone?) Indeed, span's operator bool() tests for "empty" status, and trying to compare a span with nullptr results in a compiler error.

@hsutter

This comment has been minimized.

Contributor

hsutter commented Dec 8, 2015

Discussed on 12-8. We are still are inclined to enable not_null be usable with span but will discuss further.

@AndrewPardoe

This comment has been minimized.

Contributor

AndrewPardoe commented Dec 8, 2015

Editors discussed 8 Dec 2015.

@hpesoj

This comment has been minimized.

hpesoj commented Dec 9, 2015

Thanks for your consideration.

As I just mentioned in Microsoft/GSL#202, if you insist on legitimising the concept of a "null span", you could introduce a special nullspan constant to use instead of nullptr. This would:

  • allow better overload resolution between pointers and spans;
  • make it clear that references/pointers and arrays are conceptually different things; and
  • still make grammatical sense with the not_null annotation.

I consider the concept of a "null array" to be conceptually unsound, but this seems like it would be a reasonable compromise.

@AndrewPardoe

This comment has been minimized.

Contributor

AndrewPardoe commented Dec 14, 2015

Editors discussed 14 Dec 2015

@AndrewPardoe

This comment has been minimized.

Contributor

AndrewPardoe commented Oct 17, 2016

Herb, please write this up. Per our discussion, suggest that we don't allow not_null for smart pointers, including span<T>. Even if we had not_null<unique_ptr<T>>,it wouldn't be movable. Checking span<T> against null is problematic anyway because you should be checking against empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment