Topic: basic_string, vector, and array iterators: required


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Thu, 29 Oct 2015 10:27:51 -0700 (PDT)
Raw View
------=_Part_731_73963453.1446139671222
Content-Type: multipart/alternative;
 boundary="----=_Part_732_1452777140.1446139671222"

------=_Part_732_1452777140.1446139671222
Content-Type: text/plain; charset=UTF-8

That's the question: should the standard explicitly *require* that
`basic_string`, `vector`, and `array` iterators are pointers? Along with
any similar types we get (there's been some talk about `stack_array` or
whatever).

Let's break down the use cases. That is, why do we want them to be pointers?

1) Performance.

2) The ability to use such iterators in pointer-based interfaces without
having to do `&*` on them.

3) The ability to get pointers back from pointer-based interfaces and use
them easily.

I've always felt that #1 should always be considered a question of the
implementation. I *want* the ability for debug builds to be able to do
range checking for me. I also want those checks to vanish in release builds.

But I think we can achieve #2 and #3 without needing to make them
explicitly pointers. We simply need two changes:

A) Allow these iterators of these types to be *implicitly convertible* to
pointers. That solves #2 neatly.

B) Allow users to convert a pointer to some element into an iterator. That
solves #3 neatly.

B should be a (possibly non-member) function of the *container*. That is,
you shouldn't be able to implicitly construct an iterator from a pointer.
The container ought to verify that the pointer is actually within the range
before doing so. And as a non-member function, it can be specialized/ADL'd
for different types.

Are these good ideas?

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_732_1452777140.1446139671222
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">That&#39;s the question: should the standard explicitly <i=
>require</i> that `basic_string`, `vector`, and `array` iterators are point=
ers? Along with any similar types we get (there&#39;s been some talk about =
`stack_array` or whatever).<br><br>Let&#39;s break down the use cases. That=
 is, why do we want them to be pointers?<br><br>1) Performance.<br><br>2) T=
he ability to use such iterators in pointer-based interfaces without having=
 to do `&amp;*` on them.<br><br>3) The ability to get pointers back from po=
inter-based interfaces and use them easily.<br><br>I&#39;ve always felt tha=
t #1 should always be considered a question of the implementation. I <i>wan=
t</i> the ability for debug builds to be able to do range checking for me. =
I also want those checks to vanish in release builds.<br><br>But I think we=
 can achieve #2 and #3 without needing to make them explicitly pointers. We=
 simply need two changes:<br><br>A) Allow these iterators of these types to=
 be <i>implicitly convertible</i> to pointers. That solves #2 neatly.<br><b=
r>B) Allow users to convert a pointer to some element into an iterator. Tha=
t solves #3 neatly.<br><br>B should be a (possibly non-member) function of =
the <i>container</i>. That is, you shouldn&#39;t be able to implicitly cons=
truct an iterator from a pointer. The container ought to verify that the po=
inter is actually within the range before doing so. And as a non-member fun=
ction, it can be specialized/ADL&#39;d for different types.<br><br>Are thes=
e good ideas?<br></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_732_1452777140.1446139671222--
------=_Part_731_73963453.1446139671222--

.