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

What is the rationnal for using signed integer as size ? #238

Closed
vlj opened this issue Jan 4, 2016 · 3 comments
Closed

What is the rationnal for using signed integer as size ? #238

vlj opened this issue Jan 4, 2016 · 3 comments
Assignees
Labels

Comments

@vlj
Copy link

vlj commented Jan 4, 2016

Hi,

I set visual studio 2015 to treat errors as warning.

With the following code snippets:

void fill_fragment_constants_buffer(gsl::span buffer, const some_pointer_type *) const
{
...
Expects(buffer.size_bytes() >= FragmentConstantOffsetCache.size() * 4u);
...
}

It fails because there's a comparaison between signed and unsigned int, revealing that buffer.size_bytes is signed, it's a ptrdiff_t.
Looking at GSL code it looks like most size_type for span are ptrdiff_t and thus are signed, however if I understand correctly span<> philosophy the size shouldn't be negative.
Can span<> encapsulate "reverse" range ?

@neilmacintosh
Copy link
Collaborator

Hi @vlj, this was discussed in #171. Essentially, the designers of the GSL believe that a signed integer is the correct choice for the indexing and measurement type. To address your second question, you are correct, the size should not be negative in a span. I'm not quite sure what you mean by a "reverse range", though.

@neilmacintosh neilmacintosh self-assigned this Jan 4, 2016
@vlj
Copy link
Author

vlj commented Jan 4, 2016

Thanks.
About reverse range, I was wondering if the possibility of having negative size was kept for span defined by pointer to the last element (and thus offset to the other end of the span is negative).

@neilmacintosh
Copy link
Collaborator

Ah, I see. No, span doesn't support negative indices or that sort of "from the end" reverse span definition.

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

2 participants