gsl-lite: Comparison operator on string_spans - null-terminated and otherwise.
While testing migrating my project from Microsoft’s GSL to GSL-Lite, my tests started failing when doing string_span comparisons. This was because some string_spans were null-terminated, some were not.
Is it intended behaviour for string_spans which are identical other than one being null-terminated to be considered different?
I have been experimenting with adding an option for special string_span comparison operators that ignore the last element of the operands if they are equal to `‘\0’ - do you think this is a good approach?
My additions can be seen on my fork.
Thank you!
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (7 by maintainers)
Commits related to this issue
- string_span<> must not include terminating '\0' (issue #53) — committed to gsl-lite/gsl-lite by martinmoene 8 years ago
- Add issue #53 (a: SFINAE) — committed to gsl-lite/gsl-lite by martinmoene 8 years ago
Thanks Magnus,
Summary:
Signed/unsigned problems in basic_string_span::subspan().
And finally, when compiling with Clang-3.9, basic_string_span’s move & copy constructor SFINAE causes errors when instantiating span<char>::span(span<const char> const &) within the is_convertible check. I guess the overload should be disabled with SFINAE instead of duck typing in the body? Curiously, GCC-6.2.0 handles it just fine. I wonder which is correct? (Both are compiled with the same version of libstdc++.) As a workaround, I replaced the is_convertible test to check if the pointer types are convertible instead.
See below for:
Another point: I think it would be useful to allow operator== on directly on string_spans and types which are convertible to string_span. M-GSL does this, although it does not appear to be in the proposal.
Hi Magnus (@Sillamacka),
I’ve added
basic_string_spanin branch basic_string_span. I both looked at the proposal p0123r2 and M-GSL.Can you check if the changes fix the failures you had?
Thanks, Martin
Started to implement
basic_string_span.