Discussion:
Why does span comparison compare referenced values?
(too old to reply)
Eyal Rozenberg
2018-10-11 11:54:52 UTC
Permalink
I just watched Tony Van Eerd's CppCon 2018 talk the other day, and he
brought up an apparent discrepancy in the design of std::span (or
gsl::span): A span is more of a reference-type than a value-type - sort
of a pointer and a length; and you can change values in a const span<T>
(though not in a span<const T>). Yet, when you compare spans, you
compare the pointed-to _values_. Van Eerd suggests that's inconsistent,
and his argument seems compelling.

So I went and had a look at the proposal:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0122r5.pdf

which says "span supports all the same comparison operations as a
sequential standard library container: element-wise comparison and a
total ordering by lexicographical comparison. This helps make it an
effective replacement for existing uses of sequential contiguous
container types like array or vector".

but I'm not sure I'm convinced. It sounds to me like saying that it's ok
to compare pointers by the values they point to, rather than by their
addresses, because that way they're an effective alternative to passing
by value.

My question: Has this matter been given attention by the committee? What
were the significant arguemnts made?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Tony V E
2018-10-11 13:05:13 UTC
Permalink
We are (likely) removing == completely.

https://github.com/tvaneerd/isocpp/blob/master/irregular_span.md

PS I wasn't at CppCon 2018 so it was some other conference :-)

Sent from my BlackBerry portable Babbage Device
  Original Message  
From: Eyal Rozenberg
Sent: Thursday, October 11, 2018 7:55 AM
To: ISO C++ Standard - Discussion
Reply To: std-***@isocpp.org
Subject: [std-discussion] Why does span comparison compare referenced values?


I just watched Tony Van Eerd's CppCon 2018 talk the other day, and he
brought up an apparent discrepancy in the design of std::span (or
gsl::span): A span is more of a reference-type than a value-type - sort
of a pointer and a length; and you can change values in a const span<T>
(though not in a span<const T>). Yet, when you compare spans, you
compare the pointed-to _values_. Van Eerd suggests that's inconsistent,
and his argument seems compelling.

So I went and had a look at the proposal:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0122r5.pdf

which says "span supports all the same comparison operations as a
sequential standard library container: element-wise comparison and a
total ordering by lexicographical comparison. This helps make it an
effective replacement for existing uses of sequential contiguous
container types like array or vector".

but I'm not sure I'm convinced. It sounds to me like saying that it's ok
to compare pointers by the values they point to, rather than by their
addresses, because that way they're an effective alternative to passing
by value.

My question: Has this matter been given attention by the committee? What
were the significant arguemnts made?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Ville Voutilainen
2018-10-11 13:18:43 UTC
Permalink
Post by Tony V E
We are (likely) removing == completely.
Bold prediction before it has been discussed.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Tony V E
2018-10-11 13:19:47 UTC
Permalink
It has been discussed. LEWG voted to remove ==.

Sent from my BlackBerry portable Babbage Device
  Original Message  
From: Ville Voutilainen
Sent: Thursday, October 11, 2018 9:18 AM
To: std-***@isocpp.org
Reply To: std-***@isocpp.org
Subject: Re: [std-discussion] Why does span comparison compare referenced values?
Post by Tony V E
We are (likely) removing == completely.
Bold prediction before it has been discussed.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Ville Voutilainen
2018-10-11 13:27:35 UTC
Permalink
Post by Tony V E
It has been discussed. LEWG voted to remove ==.
Ah indeed, I missed the actual proposal number.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Eyal Rozenberg
2018-10-11 16:12:01 UTC
Permalink
Sorry TonyVE, it was C++Now 2018. For anyone interested, the talk is here:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1085r0.md

But wait. You (or should I say we?) are removing equality. But... why? I
mean, pointers have equality, don't they? And you can compare C arrays
(as pointers, IIRC). What's the rationale here?

Eyal

PS - I'm particularly interested in this point since I'm working on a
bit span class.
Post by Tony V E
We are (likely) removing == completely.
https://github.com/tvaneerd/isocpp/blob/master/irregular_span.md
PS I wasn't at CppCon 2018 so it was some other conference :-)
Sent from my BlackBerry portable Babbage Device
  Original Message  
From: Eyal Rozenberg
Sent: Thursday, October 11, 2018 7:55 AM
To: ISO C++ Standard - Discussion
Subject: [std-discussion] Why does span comparison compare referenced values?
I just watched Tony Van Eerd's CppCon 2018 talk the other day, and he
brought up an apparent discrepancy in the design of std::span (or
gsl::span): A span is more of a reference-type than a value-type - sort
of a pointer and a length; and you can change values in a const span<T>
(though not in a span<const T>). Yet, when you compare spans, you
compare the pointed-to _values_. Van Eerd suggests that's inconsistent,
and his argument seems compelling.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0122r5.pdf
which says "span supports all the same comparison operations as a
sequential standard library container: element-wise comparison and a
total ordering by lexicographical comparison. This helps make it an
effective replacement for existing uses of sequential contiguous
container types like array or vector".
but I'm not sure I'm convinced. It sounds to me like saying that it's ok
to compare pointers by the values they point to, rather than by their
addresses, because that way they're an effective alternative to passing
by value.
My question: Has this matter been given attention by the committee? What
were the significant arguemnts made?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Tony V E
2018-10-11 16:28:33 UTC
Permalink
Either == (deep or shallow) will be a surprise for users. 
In many ways span acts like a container, so you might expect == like a container.
In many ways span acts like a pointer, so you might expect == like a pointer.

That's why I think naming can help. span_ref vs ‎span_ptr. Or something like that. Make expectations, and design, clear.

The other answer is that the committee works by consensus. When you can't find consensus on how it should work, you can often find consensus to not have it at all.

With neither ==, at least code will be explicit. If you want deep, use std::equal. If you want shallow, look at data() and size().




Sent from my BlackBerry portable Babbage Device
  Original Message  
From: Eyal Rozenberg
Sent: Thursday, October 11, 2018 12:12 PM
To: std-***@isocpp.org; Tony V E
Subject: Re: [std-discussion] Why does span comparison compare referenced values?

Sorry TonyVE, it was C++Now 2018. For anyone interested, the talk is here:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1085r0.md

But wait. You (or should I say we?) are removing equality. But... why? I
mean, pointers have equality, don't they? And you can compare C arrays
(as pointers, IIRC). What's the rationale here?

Eyal

PS - I'm particularly interested in this point since I'm working on a
bit span class.
Post by Tony V E
We are (likely) removing == completely.
https://github.com/tvaneerd/isocpp/blob/master/irregular_span.md
PS I wasn't at CppCon 2018 so it was some other conference :-)
Sent from my BlackBerry portable Babbage Device
  Original Message  
From: Eyal Rozenberg
Sent: Thursday, October 11, 2018 7:55 AM
To: ISO C++ Standard - Discussion
Subject: [std-discussion] Why does span comparison compare referenced values?
I just watched Tony Van Eerd's CppCon 2018 talk the other day, and he
brought up an apparent discrepancy in the design of std::span (or
gsl::span): A span is more of a reference-type than a value-type - sort
of a pointer and a length; and you can change values in a const span<T>
(though not in a span<const T>). Yet, when you compare spans, you
compare the pointed-to _values_. Van Eerd suggests that's inconsistent,
and his argument seems compelling.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0122r5.pdf
which says "span supports all the same comparison operations as a
sequential standard library container: element-wise comparison and a
total ordering by lexicographical comparison. This helps make it an
effective replacement for existing uses of sequential contiguous
container types like array or vector".
but I'm not sure I'm convinced. It sounds to me like saying that it's ok
to compare pointers by the values they point to, rather than by their
addresses, because that way they're an effective alternative to passing
by value.
My question: Has this matter been given attention by the committee? What
were the significant arguemnts made?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Continue reading on narkive:
Loading...