Comments (15)
Started to implement basic_string_span
.
from gsl-lite.
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
from gsl-lite.
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::span(span 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.
from gsl-lite.
Another, simpler, approach would be in construction, i.e. ignore the null-terminator when constructing from string literal. This would cover most cases where the comparison gives unexpected results while keeping the current behaviour of the comparisons.
from gsl-lite.
Thanks Magnus,
I'll have a look at the construction-case.
Perhaps time has come to add class basic_string_span
instead of building string_span
on on span
?
from gsl-lite.
Nice! I too started thinking that ignoring the null terminator on construction is better.
With my additional comparison operator experiment, there are now four versions of the comparisons, which seems a bit too much - besides, a user might want to explicitly include the null terminator in the span and its comparisons.
from gsl-lite.
Hello, that was fast!
It did fix the problems, but I had to fix some bugs in the code first: here is the diff.
Summary: rbegin()
& rend()
should return reverse_iterator
Signed/unsigned problems in basic_string_span::subspan()
.
Default constructor for basic_string_span
was marked noexcept
, but default constructor for span
was not.
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.
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.
Thank you for your work!
from gsl-lite.
It seems the strange Clang error is triggered when calling gsl::to_string()
on any string_span.
Minimal example:
#include "gsl-lite.h"
#include <string>
int main() {
gsl::cstring_span span = "Hello world";
std::string str = gsl::to_string(span);
}
I can also confirm that it can be solved by constraining span<T>::span( span<U> const & )
with SFINAE.
from gsl-lite.
Excellent! I forgot to mention that I also changed the std::basic_string const &
-taking constructor to work with non-default char_traits
and allocator
template parameters, perhaps you should add that to the list?
from gsl-lite.
I'd noticed it though :)
from gsl-lite.
@Sillamacka , I'll first release gsl lite with basic_string_span
without its enhanced comparison as indicated below, then have a look at it:
- [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.
from gsl-lite.
Sounds good to me, explicitly constructing cstring_spans in comparisons isn't that much extra work, so I think I can deal with it :D
from gsl-lite.
It'll not take long probably...
from gsl-lite.
Published release 0.16.0 with enhanced string span comparison.
from gsl-lite.
Great! I think we can consider this issue resolved now.
from gsl-lite.
Related Issues (20)
- Migrate Travis CI jobs to other CI provider HOT 1
- `not_null<>` should be hashable HOT 2
- Should `not_null<>` be two different classes? HOT 3
- "illegal instruction" Error when using gsl::span as Kernel Parameter HOT 3
- Test compilation failures on GCC 11: error: array subscript -1 is outside array bounds of 'char[6]' [-Werror=array-bounds] HOT 7
- Test failures on s390x (GCC 10.2.1 and 11.0.1) HOT 7
- Support `narrow<>()` for types without total order
- `not_null<shared_ptr<T>>` not convertible to `weak_ptr<T>` HOT 1
- gsl_FEATURE_GSL_LITE_NAMESPACE not working HOT 3
- Definition of `fail_fast` and of `narrowing_error` triggers `clang`'s `-Wweak-vtables` HOT 2
- gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME in kernel code HOT 1
- including gsl-lite triggers `-Wuseless-cast` warnings HOT 2
- Add tests for `not_null_ic<>`
- Tests fail to compile due to -Werror=type-limits when char is unsigned HOT 6
- Add CI for non-x86 architectures
- Allow `not_null<void*>` and related. HOT 9
- `not_null`'s evaluation of nullness can lead to *very* cryptic errors. HOT 10
- Suppress warnings in lest via system include
- Comparison of `std::optional<not_null<T>>` and `not_null<T>` is ambiguous HOT 2
- gsl::span works differently than std::span in terms of type matching? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gsl-lite.