Skip to content
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
Open

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

hpesoj opened this issue Nov 19, 2015 · 5 comments
Assignees
Labels

Comments

@hpesoj
Copy link

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
Copy link
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
Copy link
Contributor

Editors discussed 8 Dec 2015.

@hpesoj
Copy link
Author

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
Copy link
Contributor

Editors discussed 14 Dec 2015

@AndrewPardoe
Copy link
Contributor

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
Labels
Projects
None yet
Development

No branches or pull requests

5 participants
@hsutter @hpesoj @AndrewPardoe @neilmacintosh and others