Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem, in short:
In other words, currently
bool
conversion is done from the data pointer, not from the size pointer. I think it should depend on the size rather than on the data, to make life easier when writing parsers and such. The following code will cycle forever, becauseinput
is always some non-null pointer, even though size eventually becomes zero and one has to pay extra attention and say!input.empty()
or something:That's not really intuitive, as e.g.
std::istream
also returnsfalse
when reaching EOF.So, fixing the bool conversion like this (as partially done in the PR already) seems like a good idea (for me at least), but there's one problem -- the bool conversion operator is disabled on MSVC as it causes ambiguities for
operator+
, basically clashing with the pointer conversion operator, even though the bool conversion is explicit, due to implicit backwards compatibility with shit old C++ code (/permissive
). So there are the following options:explicit operator bool()
like it currently is (return _data;
) and update the documentation to say it basically doesn't do what would one expect. That makes it consistent with MSVC, but practically useless and potentially dangerous if accidentally used for the wrong purpose./permissive-
on everyone. Would mean dropping MSVC 2017 support, as it's known to be crashy and buggy in some cases.Add an explicit branch to the constructor which sets the data pointer toNot an option, since a lot code relies on a distinction between a null empty view and a non-null empty view.nullptr
in case size is zero. That makes it consistent with Array behavior, but might break some code. (I know about at least one case in the OpenDDL parse where I'm treating zero-sized nullptr view and zero-sized non-nullptr view differently -- the first one indicating a parse error, the second indicating EOF.)Another possibility, in a different direction than this PR:
true
only if both size is nonzero and pointer is non-null?To ensure consistency, this applies also to the
StaticArrayView
, but there zero-sized views are problematic at the moment due to some non-ISO-standard zero-sized arrays being present in function signatures.Does not apply to the new
StringView
classes, as there I deliberately don't haveconst char*
conversion -- simply because not every view is null terminated and this would be a very convenient footgun.Opinions? Thank you :)