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

Most upvoted comments

Thanks Magnus,

Summary:

  • rbegin() & rend() should return reverse_iterator
  • [Note: split into two functions as with span]
    Signed/unsigned problems in basic_string_span::subspan().
  • Default constructor for basic_string_span was marked noexcept, but default constructor for span was not.
  • Changed the std::basic_string const &-taking constructor to work with non-default char_traits and allocator template parameters.
  • [AIUI the workaround (and the way M-GSL goes about it) is ‘just fine’]
    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:

  • [Had noticed this, will look into it]
    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_span in 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.