Topic: Draft proposal - std::recover: undoing type erasure


Author: David Krauss <potswa@gmail.com>
Date: Wed, 9 Sep 2015 18:52:06 +0800
Raw View
--Apple-Mail=_486EABA8-E6D7-4EFB-875B-DEE6ED20BDDB
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

Major revision!

It=E2=80=99s renamed to recover, dropping _cast.

unique_ptr and polymorphic smart pointers are now first-class ErasureTypes.=
 Raw pointers aren=E2=80=99t, but you can substitute observer_ptr.

The semantics of type-erased objects vs. references are refined. The erstwh=
ile conversion function is split into complete_object_address and referent_=
address.

Deeper analysis is added, including why ADL is avoided, what classes have t=
rouble with the concept, and how to fix them.

A reference implementation and a complete example class are included right =
in the text.

Many errors fixed and points clarified.

Share and enjoy.

bit.ly/reccast <http://bit.ly/reccast>

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--Apple-Mail=_486EABA8-E6D7-4EFB-875B-DEE6ED20BDDB
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; -webk=
it-line-break: after-white-space;" class=3D"">Major revision!<div class=3D"=
"><br class=3D""></div><div class=3D"">It=E2=80=99s renamed to <font face=
=3D"Courier" class=3D"">recover</font>, dropping <font face=3D"Courier" cla=
ss=3D"">_cast</font>.<br class=3D""><div class=3D""><br class=3D""></div><d=
iv class=3D""><font face=3D"Courier" class=3D"">unique_ptr</font> and polym=
orphic smart pointers are now first-class ErasureTypes. Raw pointers aren=
=E2=80=99t, but you can substitute <font face=3D"Courier" class=3D"">observ=
er_ptr</font>.</div><div class=3D""><br class=3D""></div><div class=3D"">Th=
e semantics of type-erased objects vs. references are refined. The erstwhil=
e conversion function is split into&nbsp;<font face=3D"Courier" class=3D"">=
complete_object_address</font>&nbsp;and <font face=3D"Courier" class=3D"">r=
eferent_address</font>.</div><div class=3D""><br class=3D""></div><div clas=
s=3D"">Deeper analysis is added, including why ADL is avoided, what classes=
 have trouble with the concept, and how to fix them.</div><div class=3D""><=
br class=3D""></div><div class=3D"">A reference implementation and a comple=
te example class are included right in the text.</div><div class=3D""><br c=
lass=3D""></div><div class=3D"">Many errors fixed and points clarified.</di=
v><div class=3D""><br class=3D""></div><div class=3D"">Share and enjoy.</di=
v><div class=3D""><br class=3D""></div><div class=3D""><a href=3D"http://bi=
t.ly/reccast" class=3D"">bit.ly/reccast</a></div><div class=3D""><br class=
=3D""></div></div></body></html>

<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 />

--Apple-Mail=_486EABA8-E6D7-4EFB-875B-DEE6ED20BDDB--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 9 Sep 2015 15:44:02 +0300
Raw View
On 9 September 2015 at 13:52, David Krauss <potswa@gmail.com> wrote:
> Major revision!
> It=E2=80=99s renamed to recover, dropping _cast.

return -ETOOVAGUENAME;

This is not an improvement.

> unique_ptr and polymorphic smart pointers are now first-class ErasureType=
s.

"Polymorphic smart pointers"? That seems like a mis-description because
shared_ptr is not an ErasureType, yet it sure as hell is a polymorphic smar=
t
pointer.

> Raw pointers aren=E2=80=99t, but you can substitute observer_ptr.

This facility needs RTFM every time it's used...

--=20

---=20
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 e=
mail 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-proposa=
ls/.

.


Author: David Krauss <potswa@gmail.com>
Date: Wed, 9 Sep 2015 21:28:06 +0800
Raw View
--Apple-Mail=_C6AEEC07-C82F-4ABA-A503-50A1CE3FC752
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9309=E2=80=9309, at 8:44 PM, Ville Voutilainen <ville.vouti=
lainen@gmail.com> wrote:
>=20
> On 9 September 2015 at 13:52, David Krauss <potswa@gmail.com> wrote:
>> Major revision!
>> It=E2=80=99s renamed to recover, dropping _cast.
>=20
> return -ETOOVAGUENAME;
>=20
> This is not an improvement.

The problem with =E2=80=9C_cast=E2=80=9D  is that it suggests the result is=
 always the type given in the template argument. That=E2=80=99s the trap an=
y_cast fell into.

recover<T> works like get<T>. Both vague names. I=E2=80=99m open to suggest=
ions=E2=80=A6

>> unique_ptr and polymorphic smart pointers are now first-class ErasureTyp=
es.
>=20
> "Polymorphic smart pointers"? That seems like a mis-description because
> shared_ptr is not an ErasureType, yet it sure as hell is a polymorphic sm=
art
> pointer.

shared_ptr<T> with polymorphic T is now an ErasureType. If T is not polymor=
phic, then it=E2=80=99s not an ErasureType.

Is this not what you intended to suggest before? I intended to take your ad=
vice.

>> Raw pointers aren=E2=80=99t, but you can substitute observer_ptr.
>=20
> This facility needs RTFM every time it's used...

The problem with raw pointers is that the function is already overloaded on=
 ErasureType *.

Since it=E2=80=99s =E2=80=9Cnot a=E2=80=9D cast, perhaps I should remove th=
at overload and bless pointers to polymorphic classes.

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--Apple-Mail=_C6AEEC07-C82F-4ABA-A503-50A1CE3FC752
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9309=
=E2=80=9309, at 8:44 PM, Ville Voutilainen &lt;<a href=3D"mailto:ville.vout=
ilainen@gmail.com" class=3D"">ville.voutilainen@gmail.com</a>&gt; wrote:</d=
iv><br class=3D"Apple-interchange-newline"><div class=3D"">On 9 September 2=
015 at 13:52, David Krauss &lt;<a href=3D"mailto:potswa@gmail.com" class=3D=
"">potswa@gmail.com</a>&gt; wrote:<br class=3D""><blockquote type=3D"cite" =
class=3D"">Major revision!<br class=3D"">It=E2=80=99s renamed to recover, d=
ropping _cast.<br class=3D""></blockquote><br class=3D"">return -ETOOVAGUEN=
AME;<br class=3D""><br class=3D"">This is not an improvement.<br class=3D""=
></div></blockquote><div><br class=3D""></div><div>The problem with =E2=80=
=9C<font face=3D"Courier" class=3D"">_cast</font>=E2=80=9D &nbsp;is that it=
 suggests the result is always the type given in the template argument. Tha=
t=E2=80=99s the trap <font face=3D"Courier" class=3D"">any_cast</font> fell=
 into.</div><div><br class=3D""></div><div><font face=3D"Courier" class=3D"=
">recover&lt;T&gt;</font> works like <font face=3D"Courier" class=3D"">get&=
lt;T&gt;</font>. Both vague names. I=E2=80=99m open to suggestions=E2=80=A6=
</div><br class=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><=
blockquote type=3D"cite" class=3D"">unique_ptr and polymorphic smart pointe=
rs are now first-class ErasureTypes.<br class=3D""></blockquote><br class=
=3D"">"Polymorphic smart pointers"? That seems like a mis-description becau=
se<br class=3D"">shared_ptr is not an ErasureType, yet it sure as hell is a=
 polymorphic smart<br class=3D"">pointer.<br class=3D""></div></blockquote>=
<div><br class=3D""></div><div><font face=3D"Courier" class=3D"">shared_ptr=
&lt;T&gt;</font> with polymorphic <font face=3D"Courier" class=3D"">T</font=
> is now an ErasureType. If <font face=3D"Courier" class=3D"">T</font> is n=
ot polymorphic, then it=E2=80=99s not an ErasureType.</div><div><br class=
=3D""></div><div>Is this not what you intended to suggest before? I intende=
d to take your advice.</div><br class=3D""><blockquote type=3D"cite" class=
=3D""><div class=3D""><blockquote type=3D"cite" class=3D"">Raw pointers are=
n=E2=80=99t, but you can substitute observer_ptr.<br class=3D""></blockquot=
e><br class=3D"">This facility needs RTFM every time it's used...<br class=
=3D""></div></blockquote></div><br class=3D""><div class=3D"">The problem w=
ith raw pointers is that the function is already overloaded on ErasureType =
*.</div><div class=3D""><br class=3D""></div><div class=3D"">Since it=E2=80=
=99s =E2=80=9Cnot a=E2=80=9D cast, perhaps I should remove that overload an=
d bless pointers to polymorphic classes.</div><div class=3D""><br class=3D"=
"></div></body></html>

<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 />

--Apple-Mail=_C6AEEC07-C82F-4ABA-A503-50A1CE3FC752--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 9 Sep 2015 16:36:13 +0300
Raw View
On 9 September 2015 at 16:28, David Krauss <potswa@gmail.com> wrote:
> "Polymorphic smart pointers"? That seems like a mis-description because
> shared_ptr is not an ErasureType, yet it sure as hell is a polymorphic sm=
art
> pointer.
>
>
> shared_ptr<T> with polymorphic T is now an ErasureType. If T is not
> polymorphic, then it=E2=80=99s not an ErasureType.

Ok, I read the paper as still saying that recover() doesn't support shared_=
ptr
"because that would be inappropriate".

> Is this not what you intended to suggest before? I intended to take your
> advice.

Sounds good to me.

> Raw pointers aren=E2=80=99t, but you can substitute observer_ptr.
>
>
> This facility needs RTFM every time it's used...
>
>
> The problem with raw pointers is that the function is already overloaded =
on
> ErasureType *.
>
> Since it=E2=80=99s =E2=80=9Cnot a=E2=80=9D cast, perhaps I should remove =
that overload and bless
> pointers to polymorphic classes.

That would sound more palatable to me. If it supports smart pointers but no=
t raw
pointers, I'm sure some would like that, but to me that sounds inconsistent=
..

--=20

---=20
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 e=
mail 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-proposa=
ls/.

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Wed, 9 Sep 2015 19:39:45 +0200
Raw View
Le 09/09/15 15:28, David Krauss a =C3=A9crit :
>> On 2015=E2=80=9309=E2=80=9309, at 8:44 PM, Ville Voutilainen <ville.vout=
ilainen@gmail.com> wrote:
>>
>> On 9 September 2015 at 13:52, David Krauss <potswa@gmail.com> wrote:
>>> Major revision!
>>> It=E2=80=99s renamed to recover, dropping _cast.
>> return -ETOOVAGUENAME;
>>
>> This is not an improvement.
> The problem with =E2=80=9C_cast=E2=80=9D  is that it suggests the result =
is always the type given in the template argument. That=E2=80=99s the trap =
any_cast fell into.
Well any_cast works like that as any is a type erasure for value types.=20
Could you clarify on which traps any_cast fell into?

>
> recover<T> works like get<T>. Both vague names. I=E2=80=99m open to sugge=
stions=E2=80=A6
>
>>> unique_ptr and polymorphic smart pointers are now first-class ErasureTy=
pes.
>> "Polymorphic smart pointers"? That seems like a mis-description because
>> shared_ptr is not an ErasureType, yet it sure as hell is a polymorphic s=
mart
>> pointer.
> shared_ptr<T> with polymorphic T is now an ErasureType. If T is not polym=
orphic, then it=E2=80=99s not an ErasureType.
This is the case already for optional<T> and variant<Ts...>. Instead of=20
talking of erased types we can talk of sum types.
any and function can be seen as the sum type of all the types that=20
satisfy the specific requirements.
optional<T>is the sum type of T and nullopt_t.
shared_ptr can be seen as a sum type of any type derived from T and=20
nullptr_t.
The same for any smart pointer or a raw pointer.

This is why I suggest to call this generic cast working on sum types=20
just sum_cast.

std::get works on product types (pair, tuple, array) and we are sure=20
that the function will succeed, as the check is done at compile time.
This is why get is appropriated here, while _cast is more appropriated=20
when the function can fail.

Vicente

P.S. future<T> can be seen also as a sum type of T and exception_ptr.

--=20

---=20
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 e=
mail 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-proposa=
ls/.

.


Author: David Krauss <potswa@gmail.com>
Date: Thu, 10 Sep 2015 20:06:01 +0800
Raw View
--Apple-Mail=_89BFB145-C988-40A8-B8B6-016269DD4D5B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

(Hopefully) final draft posted. Reload for joy: bit.ly/reccast <http://bit.=
ly/reccast>

I tried supporting polymorphic raw pointers, but without the ErasureClass *=
 overload you can=E2=80=99t escape the conversion failure exception, forcin=
g type-switches to call e.verify_type<T>()=E2=80=A6 which can=E2=80=99t be =
done on raw pointers, so it=E2=80=99s a catch-22. So, observer_ptr will hav=
e to be good enough. The draft with raw pointer support is saved here <http=
s://www.dropbox.com/s/ewnctuf1454kqce/recover_native.pdf?dl=3D0>.


> On 2015=E2=80=9309=E2=80=9310, at 1:39 AM, Vicente J. Botet Escriba <vice=
nte.botet@wanadoo.fr> wrote:
>=20
> Well any_cast works like that as any is a type erasure for value types. C=
ould you clarify on which traps any_cast fell into?

It will convert an rvalue into an lvalue.

int & x =3D std::experimental::any_cast< int & >( std::experimental::any( 5=
 ) );

It=E2=80=99s not as generic as it should be. The caller is required to supp=
ly an exact const and lvalue/rvalue qualification.

template< typename E >
void pass_foo( E && e ) {
    // Pass with rvalue and const qualification of e. any_cast can=E2=80=99=
t do this.
    func( std::recover< foo >( std::forward< E >( e ) ) );
}

This is especially significant for optional, which is a very tightly-wrappi=
ng proxy.

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--Apple-Mail=_89BFB145-C988-40A8-B8B6-016269DD4D5B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D"">(Hopefully) final =
draft posted. Reload for joy: <a href=3D"http://bit.ly/reccast" class=3D"">=
bit.ly/reccast</a><div class=3D""><br class=3D""></div><div class=3D"">I tr=
ied supporting polymorphic raw pointers, but without the <font face=3D"Cour=
ier" class=3D"">ErasureClass *</font> overload you can=E2=80=99t escape the=
 conversion failure exception, forcing type-switches to call <font face=3D"=
Courier" class=3D"">e.verify_type&lt;T&gt;()</font>=E2=80=A6 which can=E2=
=80=99t be done on raw pointers, so it=E2=80=99s a catch-22. So, <font face=
=3D"Courier" class=3D"">observer_ptr</font> will have to be good enough. Th=
e draft with raw pointer support is saved&nbsp;<a href=3D"https://www.dropb=
ox.com/s/ewnctuf1454kqce/recover_native.pdf?dl=3D0" class=3D"">here</a>.</d=
iv><div class=3D""><br class=3D""></div><div class=3D""><br class=3D""><div=
><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9309=E2=
=80=9310, at 1:39 AM, Vicente J. Botet Escriba &lt;<a href=3D"mailto:vicent=
e.botet@wanadoo.fr" class=3D"">vicente.botet@wanadoo.fr</a>&gt; wrote:</div=
><br class=3D"Apple-interchange-newline"><div class=3D"">Well any_cast work=
s like that as any is a type erasure for value types. Could you clarify on =
which traps any_cast fell into?</div></blockquote><div><br class=3D""></div=
><div>It will convert an rvalue into an lvalue.</div><div><br class=3D""></=
div><div><font face=3D"Courier" class=3D"">int &amp; x =3D std::experimenta=
l::any_cast&lt; int &amp; &gt;( std::experimental::any( 5 ) );<br class=3D"=
"></font><br class=3D""></div>It=E2=80=99s not as generic as it should be. =
The caller is required to supply an exact const and lvalue/rvalue qualifica=
tion.</div><div><br class=3D""></div><div><font face=3D"Courier" class=3D""=
>template&lt; typename E &gt;</font></div><div><font face=3D"Courier" class=
=3D"">void pass_foo( E &amp;&amp; e ) {</font></div><div><font face=3D"Cour=
ier" class=3D"">&nbsp; &nbsp;</font><span style=3D"font-family: Courier;" c=
lass=3D"">&nbsp;</span><span style=3D"font-family: Courier;" class=3D"">// =
Pass with rvalue and const qualification of e. any_cast can=E2=80=99t do th=
is.</span></div><div><font face=3D"Courier" class=3D"">&nbsp; &nbsp; func( =
std::recover&lt; foo &gt;( std::forward&lt; E &gt;( e ) ) );</font></div><d=
iv><font face=3D"Courier" class=3D"">}</font></div><div><br class=3D""></di=
v><div>This is especially significant for <font face=3D"Courier" class=3D""=
>optional</font>, which is a very tightly-wrapping proxy.</div><div><br cla=
ss=3D""></div></div></body></html>

<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 />

--Apple-Mail=_89BFB145-C988-40A8-B8B6-016269DD4D5B--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 20 Sep 2015 10:04:42 +0200
Raw View
This is a multi-part message in MIME format.
--------------020105030207070108070503
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 10/09/15 14:06, David Krauss a =C3=A9crit :
> (Hopefully) final draft posted. Reload for joy: bit.ly/reccast <http://bi=
t.ly/reccast>
>
> I tried supporting polymorphic raw pointers, but without the ErasureClass=
 * overload you can=E2=80=99t escape the conversion failure exception, forc=
ing type-switches to call e.verify_type<T>()=E2=80=A6 which can=E2=80=99t b=
e done on raw pointers, so it=E2=80=99s a catch-22. So, observer_ptr will h=
ave to be good enough. The draft with raw pointer support is saved here <ht=
tps://www.dropbox.com/s/ewnctuf1454kqce/recover_native.pdf?dl=3D0>.
>
>
>
Hi David, I know that it is very late for changes.

The paper is missing the definition of recover when the parameter is a=20
pointer (=C2=A73.3), however you define it in =C2=A75.

template< typename T, typename ErasureClass >
constexpr auto * recover( ErasureClass * e ) noexcept;

Does this function has as pre-condition that the passed pointer is not=20
nullptr?
If not, you should check it in

     e->template verify_type< T >();

and I guess that the result will be nullptr. Then the function can=20
return either nullptr when the passed parameter is nullptr or when the=20
stored type is not T.

Wondering if instead of the overloaded recover function the interface of=20
this function couldn't be spited into 4 functions: holds/has, deref,=20
value and get_address_of .

This interface is more in line with the smart pointer interface, but=20
extended to types and indexes, bool(ptr) becomes holds<T>(s), *ptr=20
becomes deref<T>(s), ptr.get() becomes get_address_of(s) and we add an=20
additional safe getter value.

     * get_address_of<T>(s) must returns nullptr if the stored=20
type/index is not the requested one. (This is similar to your=20
recover<T>(&s), but has a reference as parameter)

     * holds<T>(s) is true if get_address_of<T>(s) !=3D nullptr.

     * deref<T>(s) has as precondition that holds<T> is true and returns=20
(object *) recover_address( &s, std::is_reference< T >{} ).

     * value<T>(s) Let ptr =3D get_address_of<T>(s). throws a bad access=20
exception if ptr=3D=3Dnullptr otherwise returns *ptr;

Note that none of these functions have a reference as parameter.

We can have also the index variants when the number of possible types is=20
know at compile time: holds<I>, deref<I>, value<I> and get_address_of<I> .

Vicente



--=20

---=20
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 e=
mail 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-proposa=
ls/.

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

<html>
  <head>
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">Le 10/09/15 14:06, David Krauss a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote
      cite=3D"mid:C81CF8E1-A45F-4B67-BF9D-CEED28E7C784@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">(Hopefully) final draft posted. Reload for joy: bit.ly=
/reccast <a class=3D"moz-txt-link-rfc2396E" href=3D"http://bit.ly/reccast">=
&lt;http://bit.ly/reccast&gt;</a>

I tried supporting polymorphic raw pointers, but without the ErasureClass *=
 overload you can=E2=80=99t escape the conversion failure exception, forcin=
g type-switches to call e.verify_type&lt;T&gt;()=E2=80=A6 which can=E2=80=
=99t be done on raw pointers, so it=E2=80=99s a catch-22. So, observer_ptr =
will have to be good enough. The draft with raw pointer support is saved he=
re <a class=3D"moz-txt-link-rfc2396E" href=3D"https://www.dropbox.com/s/ewn=
ctuf1454kqce/recover_native.pdf?dl=3D0">&lt;https://www.dropbox.com/s/ewnct=
uf1454kqce/recover_native.pdf?dl=3D0&gt;</a>.



</pre>
    </blockquote>
    <font size=3D"+1">Hi David, I know that it is very late for changes.<br=
>
      <br>
      The paper is missing the definition of recover when the parameter
      is a pointer (=C2=A73.3), however you define it in =C2=A75.<br>
      <br>
      template&lt; typename T, typename ErasureClass &gt;<br>
      constexpr auto * recover( ErasureClass * e ) noexcept;<br>
      <br>
      Does this function has as pre-condition that the passed pointer is
      not nullptr? <br>
      If not, you should check it in <br>
      <br>
    </font><font size=3D"+1">
      <meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf=
-8">
      =C2=A0=C2=A0=C2=A0 e-&gt;template verify_type&lt; T &gt;();<br>
      <br>
      and I guess that the result will be nullptr. Then the function can
      return either nullptr when the passed parameter is nullptr or when
      the stored type is not T.<br>
      <br>
      Wondering if instead of the overloaded recover function the
      interface of this function couldn't be spited into 4 functions:
      holds/has, deref, value and get_address_of .<br>
      <br>
      This interface is more in line with the smart pointer interface,
      but extended to types and indexes, bool(ptr) becomes
      holds&lt;T&gt;(s), *ptr becomes deref&lt;T&gt;(s), ptr.get()
      becomes get_address_of(s) and we add an additional safe getter
      value.<br>
      <br>
      =C2=A0=C2=A0=C2=A0 * get_address_of&lt;T&gt;(s) must returns nullptr =
if the
      stored type/index is not the requested one. (This is similar to
      your recover&lt;T&gt;(&amp;s), but has a reference as parameter)<br>
      <br>
      =C2=A0=C2=A0=C2=A0 * holds&lt;T&gt;(s) is true if get_address_of&lt;T=
&gt;(s) !=3D
      nullptr.<br>
      <br>
      =C2=A0=C2=A0=C2=A0 * deref&lt;T&gt;(s) has as precondition that holds=
&lt;T&gt; is
      true and returns (object *) recover_address( &amp;s,
      std::is_reference&lt; T &gt;{} ).<br>
      <br>
      =C2=A0=C2=A0=C2=A0 * value&lt;T&gt;(s) Let ptr =3D get_address_of&lt;=
T&gt;(s).
      throws a bad access exception if ptr=3D=3Dnullptr otherwise returns
      *ptr;<br>
      <br>
      Note that none of these functions have a reference as parameter.<br>
      <br>
      We can have also the index variants when the number of possible
      types is know at compile time: holds&lt;I&gt;, deref&lt;I&gt;,
      value&lt;I&gt; and get_address_of&lt;I&gt; . <br>
      <br>
      Vicente<br>
    </font><font size=3D"+1">
    </font><br>
    <br>
    <br>
  </body>
</html>

<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 />

--------------020105030207070108070503--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 20 Sep 2015 10:31:20 +0200
Raw View
This is a multi-part message in MIME format.
--------------000906010106080206090803
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 20/09/15 10:04, Vicente J. Botet Escriba a =C3=A9crit :
> Le 10/09/15 14:06, David Krauss a =C3=A9crit :
>> (Hopefully) final draft posted. Reload for joy: bit.ly/reccast=20
>> <http://bit.ly/reccast>
>>
>> I tried supporting polymorphic raw pointers, but without the=20
>> ErasureClass * overload you can=E2=80=99t escape the conversion failure=
=20
>> exception, forcing type-switches to call e.verify_type<T>()=E2=80=A6 whi=
ch=20
>> can=E2=80=99t be done on raw pointers, so it=E2=80=99s a catch-22. So, o=
bserver_ptr=20
>> will have to be good enough. The draft with raw pointer support is=20
>> saved here=20
>> <https://www.dropbox.com/s/ewnctuf1454kqce/recover_native.pdf?dl=3D0>.
>>
>>
>>
> Hi David, I know that it is very late for changes.
>
> The paper is missing the definition of recover when the parameter is a=20
> pointer (=C2=A73.3), however you define it in =C2=A75.
>
> template< typename T, typename ErasureClass >
> constexpr auto * recover( ErasureClass * e ) noexcept;
>
> Does this function has as pre-condition that the passed pointer is not=20
> nullptr?
> If not, you should check it in
>
>     e->template verify_type< T >();
>
> and I guess that the result will be nullptr. Then the function can=20
> return either nullptr when the passed parameter is nullptr or when the=20
> stored type is not T.
>
> Wondering if instead of the overloaded recover function the interface=20
> of this function couldn't be spited into 4 functions: holds/has,=20
> deref, value and get_address_of .
>
> This interface is more in line with the smart pointer interface, but=20
> extended to types and indexes, bool(ptr) becomes holds<T>(s), *ptr=20
> becomes deref<T>(s), ptr.get() becomes get_address_of(s) and we add an=20
> additional safe getter value.
>
>     * get_address_of<T>(s) must returns nullptr if the stored=20
> type/index is not the requested one. (This is similar to your=20
> recover<T>(&s), but has a reference as parameter)
>
>     * holds<T>(s) is true if get_address_of<T>(s) !=3D nullptr.
>
>     * deref<T>(s) has as precondition that holds<T> is true and=20
> returns (object *) recover_address( &s, std::is_reference< T >{} ).
>
>     * value<T>(s) Let ptr =3D get_address_of<T>(s). throws a bad access=
=20
> exception if ptr=3D=3Dnullptr otherwise returns *ptr;
>
> Note that none of these functions have a reference as parameter.
>
> We can have also the index variants when the number of possible types=20
> is know at compile time: holds<I>, deref<I>, value<I> and=20
> get_address_of<I> .
>
>
More thoughts. Imagine that we wrap an ErasureClass by selecting just a=20
possible type.

     template <class T, class ErasureClass>
     struct select_type {
     ...
     };
     template <class T, class ErasureClass>
     select_type<T, ErasureClass> select(ErasureClass&&);

This projection should behave as a optional<T> and so we could define=20
the typical operator bool(), operator*() and get() (and even=20
operator->()) on this class. And have

     any a;
     // ...
     auto& api =3D select<int>(a)
     if (api) return *api;

     int * ptr =3D api.get();

     api->f(); // for some function T::f()

The suggested interface goes in this direction

     any a;

     // ...

     if (holds<int>(a)) return deref<int>(a);

     int* ptr =3D get_address<int>(a);


Any interest in select_type?

Vicente


--=20

---=20
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 e=
mail 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-proposa=
ls/.

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

<html>
  <head>
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">Le 20/09/15 10:04, Vicente J. Botet
      Escriba a =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote cite=3D"mid:55FE689A.5080806@wanadoo.fr" type=3D"cite">Le
      10/09/15 14:06, David Krauss a =C3=A9crit :
      <br>
      <blockquote type=3D"cite">(Hopefully) final draft posted. Reload for
        joy: bit.ly/reccast <a class=3D"moz-txt-link-rfc2396E" href=3D"http=
://bit.ly/reccast">&lt;http://bit.ly/reccast&gt;</a>
        <br>
        <br>
        I tried supporting polymorphic raw pointers, but without the
        ErasureClass * overload you can=E2=80=99t escape the conversion fai=
lure
        exception, forcing type-switches to call
        e.verify_type&lt;T&gt;()=E2=80=A6 which can=E2=80=99t be done on ra=
w pointers,
        so it=E2=80=99s a catch-22. So, observer_ptr will have to be good
        enough. The draft with raw pointer support is saved here
<a class=3D"moz-txt-link-rfc2396E" href=3D"https://www.dropbox.com/s/ewnctu=
f1454kqce/recover_native.pdf?dl=3D0">&lt;https://www.dropbox.com/s/ewnctuf1=
454kqce/recover_native.pdf?dl=3D0&gt;</a>.<br>
        <br>
        <br>
        <br>
      </blockquote>
      Hi David, I know that it is very late for changes.
      <br>
      <br>
      The paper is missing the definition of recover when the parameter
      is a pointer (=C2=A73.3), however you define it in =C2=A75.
      <br>
      <br>
      template&lt; typename T, typename ErasureClass &gt;
      <br>
      constexpr auto * recover( ErasureClass * e ) noexcept;
      <br>
      <br>
      Does this function has as pre-condition that the passed pointer is
      not nullptr?
      <br>
      If not, you should check it in
      <br>
      <br>
      =C2=A0=C2=A0=C2=A0 e-&gt;template verify_type&lt; T &gt;();
      <br>
      <br>
      and I guess that the result will be nullptr. Then the function can
      return either nullptr when the passed parameter is nullptr or when
      the stored type is not T.
      <br>
      <br>
      Wondering if instead of the overloaded recover function the
      interface of this function couldn't be spited into 4 functions:
      holds/has, deref, value and get_address_of .
      <br>
      <br>
      This interface is more in line with the smart pointer interface,
      but extended to types and indexes, bool(ptr) becomes
      holds&lt;T&gt;(s), *ptr becomes deref&lt;T&gt;(s), ptr.get()
      becomes get_address_of(s) and we add an additional safe getter
      value.
      <br>
      <br>
      =C2=A0=C2=A0=C2=A0 * get_address_of&lt;T&gt;(s) must returns nullptr =
if the
      stored type/index is not the requested one. (This is similar to
      your recover&lt;T&gt;(&amp;s), but has a reference as parameter)
      <br>
      <br>
      =C2=A0=C2=A0=C2=A0 * holds&lt;T&gt;(s) is true if get_address_of&lt;T=
&gt;(s) !=3D
      nullptr.
      <br>
      <br>
      =C2=A0=C2=A0=C2=A0 * deref&lt;T&gt;(s) has as precondition that holds=
&lt;T&gt; is
      true and returns (object *) recover_address( &amp;s,
      std::is_reference&lt; T &gt;{} ).
      <br>
      <br>
      =C2=A0=C2=A0=C2=A0 * value&lt;T&gt;(s) Let ptr =3D get_address_of&lt;=
T&gt;(s).
      throws a bad access exception if ptr=3D=3Dnullptr otherwise returns
      *ptr;
      <br>
      <br>
      Note that none of these functions have a reference as parameter.
      <br>
      <br>
      We can have also the index variants when the number of possible
      types is know at compile time: holds&lt;I&gt;, deref&lt;I&gt;,
      value&lt;I&gt; and get_address_of&lt;I&gt; .
      <br>
      <br>
      <br>
    </blockquote>
    More thoughts. Imagine that we wrap an ErasureClass by selecting
    just a possible type.<br>
    <br>
    =C2=A0=C2=A0=C2=A0 template &lt;class T, class ErasureClass&gt;<br>
    =C2=A0=C2=A0=C2=A0 struct select_type {<br>
    =C2=A0=C2=A0=C2=A0 ...<br>
    =C2=A0=C2=A0=C2=A0 };<br>
    =C2=A0=C2=A0=C2=A0 template &lt;class T, class ErasureClass&gt;<br>
    =C2=A0=C2=A0=C2=A0 select_type&lt;T, ErasureClass&gt;
    select(ErasureClass&amp;&amp;);<br>
    <br>
    This projection should behave as a optional&lt;T&gt; and so we could
    define the typical operator bool(), operator*() and get() (and even
    operator-&gt;()) on this class. And have<br>
    <br>
    =C2=A0=C2=A0=C2=A0 any a; <br>
    =C2=A0=C2=A0=C2=A0 // ...<br>
    =C2=A0=C2=A0=C2=A0 auto&amp; api =3D select&lt;int&gt;(a)<br>
    =C2=A0=C2=A0=C2=A0 if (api) return *api;<br>
    =C2=A0=C2=A0=C2=A0 <br>
    =C2=A0=C2=A0=C2=A0 int * ptr =3D api.get();<br>
    <br>
    =C2=A0=C2=A0=C2=A0 api-&gt;f(); // for some function T::f()<br>
    <br>
    The suggested interface goes in this direction<br>
    <br>
    =C2=A0=C2=A0=C2=A0 any a;
    <p> =C2=A0=C2=A0=C2=A0 // ...</p>
    <p> =C2=A0=C2=A0=C2=A0 if (holds&lt;int&gt;(a)) return deref&lt;int&gt;=
(a);</p>
    <p> </p>
    <p> =C2=A0=C2=A0=C2=A0 int* ptr =3D get_address&lt;int&gt;(a);</p>
    <title></title>
    <meta name=3D"GENERATOR" content=3D"OpenOffice.org 3.3 (Unix)">
    <style type=3D"text/css">
 <!--
  @page { margin: 2cm }
  P { margin-bottom: 0.21cm }
 -->
 </style><br>
    Any interest in select_type?<br>
    <br>
    Vicente<br>
    <br>
    <br>
  </body>
</html>

<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 />

--------------000906010106080206090803--

.


Author: David Krauss <potswa@gmail.com>
Date: Sun, 20 Sep 2015 17:16:15 +0800
Raw View
--Apple-Mail=_A67B7E36-E0D4-4F2F-B38C-78B9226088F7
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9309=E2=80=9320, at 4:04 PM, Vicente J. Botet Escriba <vice=
nte.botet@wanadoo.fr> wrote:
>=20
> Hi David, I know that it is very late for changes.

There=E2=80=99s too late and there=E2=80=99s still on time :)

> The paper is missing the definition of recover when the parameter is a po=
inter (=C2=A73.3), however you define it in =C2=A75.

The requires and returns paragraphs in =C2=A73.3 are intended as the normat=
ive definition. Also it=E2=80=99s mentioned in the second paragraph, =E2=80=
=9CGiven a pointer argument, the result is a pointer=E2=80=A6=E2=80=9D

Would you suggest adding something more?

> template< typename T, typename ErasureClass >
> constexpr auto * recover( ErasureClass * e ) noexcept;
>=20
> Does this function has as pre-condition that the passed pointer is not nu=
llptr?=20

The intent isn=E2=80=99t that the user would be keeping pointers to Erasure=
Class types, so really I forgot to think about nullptr. N4542 also forgets =
about it.

It=E2=80=99s checked by any_cast, it=E2=80=99s a common expectation, and th=
e compiler can elide the check when the argument is an address-of expressio=
n, so I think recover should support it as well.

> If not, you should check it in=20
>=20
>     e->template verify_type< T >();
>=20
> and I guess that the result will be nullptr. Then the function can return=
 either nullptr when the passed parameter is nullptr or when the stored typ=
e is not T.
>=20
> Wondering if instead of the overloaded recover function the interface of =
this function couldn't be spited into 4 functions: holds/has, deref, value =
and get_address_of .

The proposal already has four functions=E2=80=A6 this seems to be getting c=
omplicated.

> This interface is more in line with the smart pointer interface, but exte=
nded to types and indexes, bool(ptr) becomes holds<T>(s), *ptr becomes dere=
f<T>(s), ptr.get() becomes get_address_of(s) and we add an additional safe =
getter value.
>=20
>     * get_address_of<T>(s) must returns nullptr if the stored type/index =
is not the requested one. (This is similar to your recover<T>(&s), but has =
a reference as parameter)

Yes, splitting out the pointer case would make the overloading more uniform=
.. Covariance between pointers and references makes sense for a cast, but re=
cover isn=E2=80=99t a cast (any more).

I=E2=80=99ll definitely think about this.

>     * holds<T>(s) is true if get_address_of<T>(s) !=3D nullptr.

This is just the same as s.verify_type<T>(), no?

>     * deref<T>(s) has as precondition that holds<T> is true and returns (=
object *) recover_address( &s, std::is_reference< T >{} ).

This is just equivalent to (T*) s.complete_object_address(). (Or the equiva=
lent with s.referent_address().) Why should there be a shortcut? The user s=
hould safely obtain a named reference at the start of the scope where T is =
statically determined.

>     * value<T>(s) Let ptr =3D get_address_of<T>(s). throws a bad access e=
xception if ptr=3D=3Dnullptr otherwise returns *ptr;

This is the original case of recover<T>(s). I think the name value is too g=
eneral.

> Note that none of these functions have a reference as parameter.

Wait, so the user has to always pass a pointer to ErasureClass? That doesn=
=E2=80=99t seem to make sense=E2=80=A6 also it contradicts your get_address=
_of description. I=E2=80=99ll assume you meant =E2=80=9Call=E2=80=9D not =
=E2=80=9Cnone.=E2=80=9D

> We can have also the index variants when the number of possible types is =
know at compile time: holds<I>, deref<I>, value<I> and get_address_of<I> .=
=20

This only applies to variant; it would clutter the generic interface.


> On 2015=E2=80=9309=E2=80=9320, at 4:31 PM, Vicente J. Botet Escriba <vice=
nte.botet@wanadoo.fr> wrote:
>=20
> Any interest in select_type?


Such a generic adaptor could be defined in terms of recover. It might be a =
later proposal.

Adaptors will work much better given generalized lifetime extension=E2=80=
=A6 I need to finish revising that proposal.

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--Apple-Mail=_A67B7E36-E0D4-4F2F-B38C-78B9226088F7
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9309=
=E2=80=9320, at 4:04 PM, Vicente J. Botet Escriba &lt;<a href=3D"mailto:vic=
ente.botet@wanadoo.fr" class=3D"">vicente.botet@wanadoo.fr</a>&gt; wrote:</=
div><br class=3D"Apple-interchange-newline"><div class=3D"">
 =20
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
" class=3D"">
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000" class=3D"">
    <div class=3D"moz-cite-prefix">Hi David, I know that it is very late fo=
r changes.</div></div></div></blockquote><div><br class=3D""></div><div>The=
re=E2=80=99s too late and there=E2=80=99s still on time :)</div><br class=
=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><div bgcolor=3D"=
#FFFFFF" text=3D"#000000" class=3D""><font class=3D"">The paper is missing =
the definition of recover when the parameter
      is a pointer (=C2=A73.3), however you define it in =C2=A75.<br class=
=3D""></font></div></div></blockquote><div><br class=3D""></div><div>The <i=
 class=3D"">requires</i>&nbsp;and <i class=3D"">returns</i>&nbsp;paragraphs=
 in =C2=A73.3 are intended as the normative definition. Also it=E2=80=99s m=
entioned in the second paragraph, =E2=80=9CGiven a pointer argument, the re=
sult is a pointer=E2=80=A6=E2=80=9D</div><div><br class=3D""></div><div>Wou=
ld you suggest adding something more?</div><br class=3D""><blockquote type=
=3D"cite" class=3D""><div class=3D""><div bgcolor=3D"#FFFFFF" text=3D"#0000=
00" class=3D""><font class=3D"">template&lt; typename T, typename ErasureCl=
ass &gt;<br class=3D"">
      constexpr auto * recover( ErasureClass * e ) noexcept;<br class=3D"">
      <br class=3D"">
      Does this function has as pre-condition that the passed pointer is
      not nullptr? <br class=3D""></font></div></div></blockquote><div><br =
class=3D""></div><div>The intent isn=E2=80=99t that the user would be keepi=
ng pointers to ErasureClass types, so really I forgot to think about <font =
face=3D"Courier" class=3D"">nullptr</font>. N4542 also forgets about it.</d=
iv><div><br class=3D""></div><div>It=E2=80=99s checked by <font face=3D"Cou=
rier" class=3D"">any_cast</font>, it=E2=80=99s a common expectation, and th=
e compiler can elide the check when the argument is an address-of expressio=
n, so I think <font face=3D"Courier" class=3D"">recover</font> should suppo=
rt it as well.</div><br class=3D""><blockquote type=3D"cite" class=3D""><di=
v class=3D""><div bgcolor=3D"#FFFFFF" text=3D"#000000" class=3D""><font cla=
ss=3D"">
      If not, you should check it in <br class=3D"">
      <br class=3D"">
    </font><font class=3D"">
      <meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf=
-8" class=3D"">
      &nbsp;&nbsp;&nbsp; e-&gt;template verify_type&lt; T &gt;();<br class=
=3D"">
      <br class=3D"">
      and I guess that the result will be nullptr. Then the function can
      return either nullptr when the passed parameter is nullptr or when
      the stored type is not T.<br class=3D"">
      <br class=3D"">
      Wondering if instead of the overloaded recover function the
      interface of this function couldn't be spited into 4 functions:
      holds/has, deref, value and get_address_of .<br class=3D""></font></d=
iv></div></blockquote><div><br class=3D""></div><div>The proposal already h=
as four functions=E2=80=A6 this seems to be getting complicated.</div><br c=
lass=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><div bgcolor=
=3D"#FFFFFF" text=3D"#000000" class=3D""><font class=3D"">This interface is=
 more in line with the smart pointer interface,
      but extended to types and indexes, bool(ptr) becomes
      holds&lt;T&gt;(s), *ptr becomes deref&lt;T&gt;(s), ptr.get()
      becomes get_address_of(s) and we add an additional safe getter
      value.<br class=3D"">
      <br class=3D"">
      &nbsp;&nbsp;&nbsp; * get_address_of&lt;T&gt;(s) must returns nullptr =
if the
      stored type/index is not the requested one. (This is similar to
      your recover&lt;T&gt;(&amp;s), but has a reference as parameter)<br c=
lass=3D""></font></div></div></blockquote><div><br class=3D""></div><div>Ye=
s, splitting out the pointer case would make the overloading more uniform. =
Covariance between pointers and references makes sense for a cast, but <fon=
t face=3D"Courier" class=3D"">recover</font> isn=E2=80=99t a cast (any more=
).</div><div><br class=3D""></div><div>I=E2=80=99ll definitely think about =
this.</div><br class=3D""><blockquote type=3D"cite" class=3D""><div class=
=3D""><div bgcolor=3D"#FFFFFF" text=3D"#000000" class=3D""><font class=3D""=
>&nbsp;&nbsp;&nbsp; * holds&lt;T&gt;(s) is true if get_address_of&lt;T&gt;(=
s) !=3D
      nullptr.<br class=3D""></font></div></div></blockquote><div><br class=
=3D""></div><div>This is just the same as <font face=3D"Courier" class=3D""=
>s.verify_type&lt;T&gt;()</font>, no?</div><br class=3D""><blockquote type=
=3D"cite" class=3D""><div class=3D""><div bgcolor=3D"#FFFFFF" text=3D"#0000=
00" class=3D""><font class=3D"">&nbsp;&nbsp;&nbsp; * deref&lt;T&gt;(s) has =
as precondition that holds&lt;T&gt; is
      true and returns (object *) recover_address( &amp;s,
      std::is_reference&lt; T &gt;{} ).<br class=3D""></font></div></div></=
blockquote><div><br class=3D""></div><div>This is just equivalent to <font =
face=3D"Courier" class=3D"">(T*) s.complete_object_address()</font>. (Or th=
e equivalent with&nbsp;<font face=3D"Courier" class=3D"">s.referent_address=
()</font>.) Why should there be a shortcut? The user should safely obtain a=
 named reference at the start of the scope where <font face=3D"Courier" cla=
ss=3D"">T</font> is statically determined.</div><br class=3D""><blockquote =
type=3D"cite" class=3D""><div class=3D""><div bgcolor=3D"#FFFFFF" text=3D"#=
000000" class=3D""><font class=3D"">&nbsp;&nbsp;&nbsp; * value&lt;T&gt;(s) =
Let ptr =3D get_address_of&lt;T&gt;(s).
      throws a bad access exception if ptr=3D=3Dnullptr otherwise returns
      *ptr;<br class=3D""></font></div></div></blockquote><div><br class=3D=
""></div><div>This is the original case of <font face=3D"Courier" class=3D"=
">recover&lt;T&gt;(s)</font>. I think the name <font face=3D"Courier" class=
=3D"">value</font> is too general.</div><br class=3D""><blockquote type=3D"=
cite" class=3D""><div class=3D""><div bgcolor=3D"#FFFFFF" text=3D"#000000" =
class=3D""><font class=3D"">Note that none of these functions have a refere=
nce as parameter.<br class=3D""></font></div></div></blockquote><div><br cl=
ass=3D""></div><div>Wait, so the user has to always pass a pointer to Erasu=
reClass? That doesn=E2=80=99t seem to make sense=E2=80=A6 also it contradic=
ts your <font face=3D"Courier" class=3D"">get_address_of</font> description=
.. I=E2=80=99ll assume you meant =E2=80=9Call=E2=80=9D not =E2=80=9Cnone.=E2=
=80=9D</div><br class=3D""><blockquote type=3D"cite" class=3D""><div class=
=3D""><div bgcolor=3D"#FFFFFF" text=3D"#000000" class=3D""><font class=3D""=
>We can have also the index variants when the number of possible
      types is know at compile time: holds&lt;I&gt;, deref&lt;I&gt;,
      value&lt;I&gt; and get_address_of&lt;I&gt; . <br class=3D""></font></=
div></div></blockquote><br class=3D""></div><div>This only applies to <font=
 face=3D"Courier" class=3D"">variant</font>; it would clutter the generic i=
nterface.</div><br class=3D""><div class=3D""><br class=3D""></div><div cla=
ss=3D""><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=
=9309=E2=80=9320, at 4:31 PM, Vicente J. Botet Escriba &lt;<a href=3D"mailt=
o:vicente.botet@wanadoo.fr" class=3D"">vicente.botet@wanadoo.fr</a>&gt; wro=
te:</div><br class=3D"Apple-interchange-newline"><div class=3D""><span clas=
s=3D"" style=3D"background-color: rgb(255, 255, 255); float: none; display:=
 inline !important;">Any interest in select_type?</span><br class=3D"" styl=
e=3D"background-color: rgb(255, 255, 255);"></div></blockquote></div><div c=
lass=3D""><div class=3D""><span class=3D"" style=3D"background-color: rgb(2=
55, 255, 255); float: none; display: inline !important;"><br class=3D""></s=
pan></div></div><div class=3D""><span class=3D"" style=3D"background-color:=
 rgb(255, 255, 255); float: none; display: inline !important;">Such a gener=
ic adaptor could be defined in terms of <font face=3D"Courier" class=3D"">r=
ecover</font>. It might be a later proposal.</span></div><div class=3D""><s=
pan class=3D"" style=3D"background-color: rgb(255, 255, 255); float: none; =
display: inline !important;"><br class=3D""></span></div><div class=3D""><s=
pan class=3D"" style=3D"background-color: rgb(255, 255, 255); float: none; =
display: inline !important;">Adaptors will work much better given generaliz=
ed lifetime extension=E2=80=A6 I need to finish revising that proposal.</sp=
an></div><div class=3D""><span class=3D"" style=3D"background-color: rgb(25=
5, 255, 255); float: none; display: inline !important;"><br class=3D""></sp=
an></div></body></html>

<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 />

--Apple-Mail=_A67B7E36-E0D4-4F2F-B38C-78B9226088F7--

.


Author: David Krauss <potswa@gmail.com>
Date: Mon, 21 Sep 2015 00:04:32 +0800
Raw View
--Apple-Mail=_7AFD38E4-6A77-4FD0-BC2A-3BE3CF7E82D7
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9309=E2=80=9320, at 4:31 PM, Vicente J. Botet Escriba <vice=
nte.botet@wanadoo.fr> wrote:
>=20
> This projection should behave as a optional<T> and so we could define the=
 typical operator bool(), operator*() and get() (and even operator->()) on =
this class. And have

Now I see why this class is important. It=E2=80=99s a nullable reference wi=
thout the legacy baggage of pointer types. It can propagate value category.=
 It makes sense to return it from a function which wasn=E2=80=99t given a p=
ointer.

It doesn=E2=80=99t exactly behave like optional<T>, but more like optional<=
T&&> =E2=80=94 except that optional is currently not defined over reference=
 types. (The member value() would be poorly named if it were. Since value()=
 doesn=E2=80=99t return by value, I think it should be called access() anyw=
ay, but I=E2=80=99m sure that suggestion would meet some resistance.)

Really the signature I=E2=80=99m looking for is

 template< typename T >
 optional< T cv ref > try_recover( Erasure cv ref );

So then the user can do

 if ( auto gotten =3D std::try_recover< T >( e ) ) {
     foo ( * std::move( gotten ) );
 }

(By the way, if operator* retrieves an rvalue from an optional, it should d=
o the same for unique_ptr.)

It=E2=80=99s all tricky=E2=80=A6

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--Apple-Mail=_7AFD38E4-6A77-4FD0-BC2A-3BE3CF7E82D7
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9309=
=E2=80=9320, at 4:31 PM, Vicente J. Botet Escriba &lt;<a href=3D"mailto:vic=
ente.botet@wanadoo.fr" class=3D"">vicente.botet@wanadoo.fr</a>&gt; wrote:</=
div><br class=3D"Apple-interchange-newline"><div class=3D""><span style=3D"=
font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: =
normal; font-weight: normal; letter-spacing: normal; line-height: normal; o=
rphans: auto; text-align: start; text-indent: 0px; text-transform: none; wh=
ite-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-wid=
th: 0px; background-color: rgb(255, 255, 255); float: none; display: inline=
 !important;" class=3D"">This projection should behave as a optional&lt;T&g=
t; and so we could define the typical operator bool(), operator*() and get(=
) (and even operator-&gt;()) on this class. And have</span><br style=3D"fon=
t-family: Helvetica; font-size: 12px; font-style: normal; font-variant: nor=
mal; font-weight: normal; letter-spacing: normal; line-height: normal; orph=
ans: auto; text-align: start; text-indent: 0px; text-transform: none; white=
-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width:=
 0px; background-color: rgb(255, 255, 255);" class=3D""></div></blockquote>=
</div><br class=3D""><div class=3D"">Now I see why this class is important.=
 It=E2=80=99s a nullable reference without the legacy baggage of pointer ty=
pes. It can propagate value category. It makes sense to return it from a fu=
nction which wasn=E2=80=99t given a pointer.</div><div class=3D""><br class=
=3D""></div><div class=3D"">It doesn=E2=80=99t exactly behave like <font fa=
ce=3D"Courier" class=3D"">optional&lt;T&gt;</font>, but more like <font fac=
e=3D"Courier" class=3D"">optional&lt;T&amp;&amp;&gt;</font>&nbsp;=E2=80=94 =
except that <font face=3D"Courier" class=3D"">optional</font> is currently =
not defined over reference types. (The member <font face=3D"Courier" class=
=3D"">value()</font> would be poorly named if it were. Since <font face=3D"=
Courier" class=3D"">value()</font> doesn=E2=80=99t return by value, I think=
 it should be called <font face=3D"Courier" class=3D"">access()</font> anyw=
ay, but I=E2=80=99m sure that suggestion would meet some resistance.)</div>=
<div class=3D""><br class=3D""></div><div class=3D"">Really the signature I=
=E2=80=99m looking for is</div><div class=3D""><br class=3D""></div><div cl=
ass=3D""><font face=3D"Courier" class=3D""><span class=3D"Apple-tab-span" s=
tyle=3D"white-space:pre"> </span>template&lt; typename T &gt;</font></div><=
div class=3D""><font face=3D"Courier" class=3D""><span class=3D"Apple-tab-s=
pan" style=3D"white-space:pre"> </span>optional&lt; T <i class=3D"">cv</i>&=
nbsp;<i class=3D"">ref</i> &gt; try_recover( Erasure <i class=3D"">cv ref</=
i>&nbsp;);</font></div><div class=3D""><br class=3D""></div><div class=3D""=
>So then the user can do</div><div class=3D""><br class=3D""></div><div cla=
ss=3D""><font face=3D"Courier" class=3D""><span class=3D"Apple-tab-span" st=
yle=3D"white-space:pre"> </span>if ( auto gotten =3D std::try_recover&lt; T=
 &gt;( e ) ) {</font></div><div class=3D""><font face=3D"Courier" class=3D"=
"><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>&nbsp; &=
nbsp; foo ( * std::move( gotten ) );</font></div><div class=3D""><font face=
=3D"Courier" class=3D""><span class=3D"Apple-tab-span" style=3D"white-space=
:pre"> </span>}</font></div><div class=3D""><br class=3D""></div><div class=
=3D"">(By the way, if <font face=3D"Courier" class=3D"">operator*</font> re=
trieves an rvalue from an <font face=3D"Courier" class=3D"">optional</font>=
, it should do the same for <font face=3D"Courier" class=3D"">unique_ptr</f=
ont>.)</div><div class=3D""><br class=3D""></div><div class=3D"">It=E2=80=
=99s all tricky=E2=80=A6</div><div class=3D""><br class=3D""></div></body><=
/html>

<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 />

--Apple-Mail=_7AFD38E4-6A77-4FD0-BC2A-3BE3CF7E82D7--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 20 Sep 2015 18:40:47 +0200
Raw View
This is a multi-part message in MIME format.
--------------050000080404030600050207
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 20/09/15 11:16, David Krauss a =C3=A9crit :
>> On 2015=E2=80=9309=E2=80=9320, at 4:04 PM, Vicente J. Botet Escriba <vic=
ente.botet@wanadoo.fr> wrote:
>>
>> Hi David, I know that it is very late for changes.
> There=E2=80=99s too late and there=E2=80=99s still on time :)
>
>> The paper is missing the definition of recover when the parameter is a p=
ointer (=C2=A73.3), however you define it in =C2=A75.
> The requires and returns paragraphs in =C2=A73.3 are intended as the norm=
ative definition. Also it=E2=80=99s mentioned in the second paragraph, =E2=
=80=9CGiven a pointer argument, the result is a pointer=E2=80=A6=E2=80=9D
The signatures are not the same

template< typename T, typename P >
auto & recover( P cv * e );                     // cv is a cv-qualifier=20
sequence

template< typename T, typename ErasureClass >
constexpr auto * recover( ErasureClass * e ) noexcept;

> Would you suggest adding something more?
I would add this signature

template< typename T, typename ErasureClass >
constexpr auto * recover( ErasureClass * e ) noexcept;

after

template< typename T, typename ErasureClass >
constexpr auto && recover( ErasureClass && e );

and require that the overload participate in overload resolution only if=20
ErasureClass satisfies the requirements of ErasureClass concept.

I suspect that this signature

template< typename T, typename P >
auto & recover( P cv * e );

is for polymorphic pointers.
>
>> template< typename T, typename ErasureClass >
>> constexpr auto * recover( ErasureClass * e ) noexcept;
>>
>> Does this function has as pre-condition that the passed pointer is not n=
ullptr?
> The intent isn=E2=80=99t that the user would be keeping pointers to Erasu=
reClass types, so really I forgot to think about nullptr. N4542 also forget=
s about it.
I know.
>
> It=E2=80=99s checked by any_cast,
Agreed.
> it=E2=80=99s a common expectation, and the compiler can elide the check w=
hen the argument is an address-of expression, so I think recover should sup=
port it as well.
I don't like this kind of cast as we don't know if the result is nullptr=20
because there nothing stored or because the type is not stored at all.
>
>> If not, you should check it in
>>
>>      e->template verify_type< T >();
>>
>> and I guess that the result will be nullptr. Then the function can retur=
n either nullptr when the passed parameter is nullptr or when the stored ty=
pe is not T.
>>
>> Wondering if instead of the overloaded recover function the interface of=
 this function couldn't be spited into 4 functions: holds/has, deref, value=
 and get_address_of .
> The proposal already has four functions=E2=80=A6 this seems to be getting=
 complicated.
I prefer to overload functions that do almost the same thing. Here the=20
overload change the semantics.
>
>> This interface is more in line with the smart pointer interface, but ext=
ended to types and indexes, bool(ptr) becomes holds<T>(s), *ptr becomes der=
ef<T>(s), ptr.get() becomes get_address_of(s) and we add an additional safe=
 getter value.
>>
>>      * get_address_of<T>(s) must returns nullptr if the stored type/inde=
x is not the requested one. (This is similar to your recover<T>(&s), but ha=
s a reference as parameter)
> Yes, splitting out the pointer case would make the overloading more unifo=
rm. Covariance between pointers and references makes sense for a cast, but =
recover isn=E2=80=99t a cast (any more).
I agree here. As we don't want a cast the overload is less expected.
>
> I=E2=80=99ll definitely think about this.
>
>>      * holds<T>(s) is true if get_address_of<T>(s) !=3D nullptr.
> This is just the same as s.verify_type<T>(), no?
Yes. I know that it is more difficult to adopt non-member functions, but=20
I'm all for them :)
>
>>      * deref<T>(s) has as precondition that holds<T> is true and returns=
 (object *) recover_address( &s, std::is_reference< T >{} ).
> This is just equivalent to (T*) s.complete_object_address(). (Or the equi=
valent with s.referent_address().) Why should there be a shortcut? The user=
 should safely obtain a named reference at the start of the scope where T i=
s statically determined.
I prefer to don't have casts is user code. I'm sure that we will end by=20
defining this shortcut. In addition, I can define deref() for types that=20
don't define

s.complete_object_address()

>
>>      * value<T>(s) Let ptr =3D get_address_of<T>(s). throws a bad access=
 exception if ptr=3D=3Dnullptr otherwise returns *ptr;
> This is the original case of recover<T>(s). I think the name value is too=
 general.
Agree naming is difficult. I don't like recover in order to retrieve the=20
value. recover let me thing to error handling.
>
>> Note that none of these functions have a reference as parameter.
> Wait, so the user has to always pass a pointer to ErasureClass? That does=
n=E2=80=99t seem to make sense=E2=80=A6 also it contradicts your get_addres=
s_of description. I=E2=80=99ll assume you meant =E2=80=9Call=E2=80=9D not =
=E2=80=9Cnone.=E2=80=9D
My bad. I meant "all"
>
>> We can have also the index variants when the number of possible types is=
 know at compile time: holds<I>, deref<I>, value<I> and get_address_of<I> .
> This only applies to variant; it would clutter the generic interface.
Yes and not. It can be also applicable to optional/expected .... That is=20
any sum type.

>
>
>> On 2015=E2=80=9309=E2=80=9320, at 4:31 PM, Vicente J. Botet Escriba <vic=
ente.botet@wanadoo.fr> wrote:
>>
>> Any interest in select_type?
>
> Such a generic adaptor could be defined in terms of recover. It might be =
a later proposal.
Of course. However the adaptor gives me just the functions I need? and=20
they are just holds, deref, access, address . We need just to have the=20
good names.
>
> Adaptors will work much better given generalized lifetime extension=E2=80=
=A6 I need to finish revising that proposal.
Please, could you give me the number?
Vicente

--=20

---=20
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 e=
mail 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-proposa=
ls/.

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

<html>
  <head>
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">Le 20/09/15 11:16, David Krauss a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">
</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">On 2015=E2=80=9309=E2=80=9320, at 4:04 PM, Vicente J=
.. Botet Escriba <a class=3D"moz-txt-link-rfc2396E" href=3D"mailto:vicente.b=
otet@wanadoo.fr">&lt;vicente.botet@wanadoo.fr&gt;</a> wrote:

Hi David, I know that it is very late for changes.
</pre>
      </blockquote>
      <pre wrap=3D"">
There=E2=80=99s too late and there=E2=80=99s still on time :)

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">The paper is missing the definition of recover when =
the parameter is a pointer (=C2=A73.3), however you define it in =C2=A75.
</pre>
      </blockquote>
      <pre wrap=3D"">
The requires and returns paragraphs in =C2=A73.3 are intended as the normat=
ive definition. Also it=E2=80=99s mentioned in the second paragraph, =E2=80=
=9CGiven a pointer argument, the result is a pointer=E2=80=A6=E2=80=9D
</pre>
    </blockquote>
    The signatures are not the same<br>
    <br>
    <meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8=
">
    template&lt; typename T, typename P &gt;<br>
    auto &amp; recover( P cv * e );=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 // cv is a
    cv-qualifier sequence<br>
    <br>
    template&lt; typename T, typename ErasureClass &gt;<br>
    constexpr auto * recover( ErasureClass * e ) noexcept;<br>
    <meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8=
">
    <br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">
Would you suggest adding something more?</pre>
    </blockquote>
    I would add this signature<br>
    <br>
    template&lt; typename T, typename ErasureClass &gt;<br>
    constexpr auto * recover( ErasureClass * e ) noexcept; <br>
    <br>
    after<br>
    <br>
    template&lt; typename T, typename ErasureClass &gt;<br>
    constexpr auto &amp;&amp; recover( ErasureClass &amp;&amp; e );<br>
    <meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8=
">
    <br>
    and require that the overload participate in overload resolution
    only if ErasureClass satisfies the requirements of ErasureClass
    concept.<br>
    <br>
    I suspect that this signature<br>
    <br>
    template&lt; typename T, typename P &gt;<br>
    auto &amp; recover( P cv * e ); <br>
    <br>
    is for polymorphic pointers.<br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">template&lt; typename T, typename ErasureClass &gt;
constexpr auto * recover( ErasureClass * e ) noexcept;

Does this function has as pre-condition that the passed pointer is not null=
ptr?=20
</pre>
      </blockquote>
      <pre wrap=3D"">
The intent isn=E2=80=99t that the user would be keeping pointers to Erasure=
Class types, so really I forgot to think about nullptr. N4542 also forgets =
about it.</pre>
    </blockquote>
    I know.<br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

It=E2=80=99s checked by any_cast, </pre>
    </blockquote>
    Agreed.<br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">it=E2=80=99s a common expectation, and the compiler ca=
n elide the check when the argument is an address-of expression, so I think=
 recover should support it as well.</pre>
    </blockquote>
    I don't like this kind of cast as we don't know if the result is
    nullptr because there nothing stored or because the type is not
    stored at all.<br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">If not, you should check it in=20

    e-&gt;template verify_type&lt; T &gt;();

and I guess that the result will be nullptr. Then the function can return e=
ither nullptr when the passed parameter is nullptr or when the stored type =
is not T.

Wondering if instead of the overloaded recover function the interface of th=
is function couldn't be spited into 4 functions: holds/has, deref, value an=
d get_address_of .
</pre>
      </blockquote>
      <pre wrap=3D"">
The proposal already has four functions=E2=80=A6 this seems to be getting c=
omplicated.</pre>
    </blockquote>
    I prefer to overload functions that do almost the same thing. Here
    the overload change the semantics.<br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">This interface is more in line with the smart pointe=
r interface, but extended to types and indexes, bool(ptr) becomes holds&lt;=
T&gt;(s), *ptr becomes deref&lt;T&gt;(s), ptr.get() becomes get_address_of(=
s) and we add an additional safe getter value.

    * get_address_of&lt;T&gt;(s) must returns nullptr if the stored type/in=
dex is not the requested one. (This is similar to your recover&lt;T&gt;(&am=
p;s), but has a reference as parameter)
</pre>
      </blockquote>
      <pre wrap=3D"">
Yes, splitting out the pointer case would make the overloading more uniform=
.. Covariance between pointers and references makes sense for a cast, but re=
cover isn=E2=80=99t a cast (any more).</pre>
    </blockquote>
    I agree here. As we don't want a cast the overload is less expected.<br=
>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

I=E2=80=99ll definitely think about this.

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">    * holds&lt;T&gt;(s) is true if get_address_of&lt=
;T&gt;(s) !=3D nullptr.
</pre>
      </blockquote>
      <pre wrap=3D"">
This is just the same as s.verify_type&lt;T&gt;(), no?</pre>
    </blockquote>
    Yes. I know that it is more difficult to adopt non-member functions,
    but I'm all for them :)<br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">    * deref&lt;T&gt;(s) has as precondition that hol=
ds&lt;T&gt; is true and returns (object *) recover_address( &amp;s, std::is=
_reference&lt; T &gt;{} ).
</pre>
      </blockquote>
      <pre wrap=3D"">
This is just equivalent to (T*) s.complete_object_address(). (Or the equiva=
lent with s.referent_address().) Why should there be a shortcut? The user s=
hould safely obtain a named reference at the start of the scope where T is =
statically determined.</pre>
    </blockquote>
    I prefer to don't have casts is user code. I'm sure that we will end
    by defining this shortcut. In addition, I can define deref() for
    types that don't define <br>
    <pre wrap=3D"">s.complete_object_address()</pre>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">    * value&lt;T&gt;(s) Let ptr =3D get_address_of&l=
t;T&gt;(s). throws a bad access exception if ptr=3D=3Dnullptr otherwise ret=
urns *ptr;
</pre>
      </blockquote>
      <pre wrap=3D"">
This is the original case of recover&lt;T&gt;(s). I think the name value is=
 too general.</pre>
    </blockquote>
    Agree naming is difficult. I don't like recover in order to retrieve
    the value. recover let me thing to error handling.<br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">Note that none of these functions have a reference a=
s parameter.
</pre>
      </blockquote>
      <pre wrap=3D"">
Wait, so the user has to always pass a pointer to ErasureClass? That doesn=
=E2=80=99t seem to make sense=E2=80=A6 also it contradicts your get_address=
_of description. I=E2=80=99ll assume you meant =E2=80=9Call=E2=80=9D not =
=E2=80=9Cnone.=E2=80=9D</pre>
    </blockquote>
    My bad. I meant "all"<br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">We can have also the index variants when the number =
of possible types is know at compile time: holds&lt;I&gt;, deref&lt;I&gt;, =
value&lt;I&gt; and get_address_of&lt;I&gt; .=20
</pre>
      </blockquote>
      <pre wrap=3D"">
This only applies to variant; it would clutter the generic interface.</pre>
    </blockquote>
    Yes and not. It can be also applicable to optional/expected ....
    That is any sum type. <br>
    =C2=A0<br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">


</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">On 2015=E2=80=9309=E2=80=9320, at 4:31 PM, Vicente J=
.. Botet Escriba <a class=3D"moz-txt-link-rfc2396E" href=3D"mailto:vicente.b=
otet@wanadoo.fr">&lt;vicente.botet@wanadoo.fr&gt;</a> wrote:

Any interest in select_type?
</pre>
      </blockquote>
      <pre wrap=3D"">

Such a generic adaptor could be defined in terms of recover. It might be a =
later proposal.</pre>
    </blockquote>
    Of course. However the adaptor gives me just the functions I need?
    and they are just holds, deref, access, address . We need just to
    have the good names.<br>
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

Adaptors will work much better given generalized lifetime extension=E2=80=
=A6 I need to finish revising that proposal.</pre>
    </blockquote>
    Please, could you give me the number?
    <blockquote
      cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com"
      type=3D"cite">
    </blockquote>
    Vicente<br>
  </body>
</html>

<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 />

--------------050000080404030600050207--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 20 Sep 2015 18:43:56 +0200
Raw View
Le 20/09/15 18:18, Vicente J. Botet Escriba a =C3=A9crit :
> Le 20/09/15 18:04, David Krauss a =C3=A9crit :
>>> On 2015=E2=80=9309=E2=80=9320, at 4:31 PM, Vicente J. Botet Escriba=20
>>> <vicente.botet@wanadoo.fr> wrote:
>>>
>>> This projection should behave as a optional<T> and so we could=20
>>> define the typical operator bool(), operator*() and get() (and even=20
>>> operator->()) on this class. And have
>> Now I see why this class is important. It=E2=80=99s a nullable reference=
=20
>> without the legacy baggage of pointer types. It can propagate value=20
>> category. It makes sense to return it from a function which wasn=E2=80=
=99t=20
>> given a pointer.
>>
>> It doesn=E2=80=99t exactly behave like optional<T>, but more like=20
>> optional<T&&> =E2=80=94
> RIght.
>> except that optional is currently not defined over reference types.=20
>> (The member value() would be poorly named if it were. Since value()=20
>> doesn=E2=80=99t return by value, I think it should be called access() an=
yway,=20
>> but I=E2=80=99m sure that suggestion would meet some resistance.)
> Agreed, T& is not a value.
>>
>> Really the signature I=E2=80=99m looking for is
>>
>>     template< typename T >
>>     optional< T cv ref > try_recover( Erasure cv ref );
>>
>> So then the user can do
>>
>>     if ( auto gotten =3D std::try_recover< T >( e ) ) {
>>         foo ( * std::move( gotten ) );
>>     }
> Why not? But I don't think we need that the result is exactly optional
>> (By the way, if operator* retrieves an rvalue from an optional, it=20
>> should do the same for unique_ptr.)
>>
>> It=E2=80=99s all tricky=E2=80=A6
>>
>>
> Yes, the details are always tricky.
>
> Vicente

--=20

---=20
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 e=
mail 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-proposa=
ls/.

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 20 Sep 2015 18:44:11 +0200
Raw View
Le 20/09/15 18:18, Vicente J. Botet Escriba a =C3=A9crit :
> Le 20/09/15 18:04, David Krauss a =C3=A9crit :
>>> On 2015=E2=80=9309=E2=80=9320, at 4:31 PM, Vicente J. Botet Escriba=20
>>> <vicente.botet@wanadoo.fr> wrote:
>>>
>>> This projection should behave as a optional<T> and so we could=20
>>> define the typical operator bool(), operator*() and get() (and even=20
>>> operator->()) on this class. And have
>> Now I see why this class is important. It=E2=80=99s a nullable reference=
=20
>> without the legacy baggage of pointer types. It can propagate value=20
>> category. It makes sense to return it from a function which wasn=E2=80=
=99t=20
>> given a pointer.
>>
>> It doesn=E2=80=99t exactly behave like optional<T>, but more like=20
>> optional<T&&> =E2=80=94
> RIght.
>> except that optional is currently not defined over reference types.=20
>> (The member value() would be poorly named if it were. Since value()=20
>> doesn=E2=80=99t return by value, I think it should be called access() an=
yway,=20
>> but I=E2=80=99m sure that suggestion would meet some resistance.)
> Agreed, T& is not a value.
>>
>> Really the signature I=E2=80=99m looking for is
>>
>>     template< typename T >
>>     optional< T cv ref > try_recover( Erasure cv ref );
>>
>> So then the user can do
>>
>>     if ( auto gotten =3D std::try_recover< T >( e ) ) {
>>         foo ( * std::move( gotten ) );
>>     }
> Why not? But I don't think we need that the result is exactly optional
>> (By the way, if operator* retrieves an rvalue from an optional, it=20
>> should do the same for unique_ptr.)
>>
>> It=E2=80=99s all tricky=E2=80=A6
>>
>>
> Yes, the details are always tricky.
>
> Vicente

--=20

---=20
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 e=
mail 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-proposa=
ls/.

.


Author: David Krauss <potswa@gmail.com>
Date: Mon, 21 Sep 2015 09:34:46 +0800
Raw View
--Apple-Mail=_0E889631-2AFC-42C3-8E69-8B108625B35A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9309=E2=80=9321, at 12:18 AM, Vicente J. Botet Escriba <vic=
ente.botet@wanadoo.fr> wrote:
>=20
> I don't think we need that the result is exactly optional

No, but both alternatives are tricky: either justify why the class shouldn=
=E2=80=99t be spelled optional<T&>, or convince everyone that optional shou=
ld accommodate references.


> On 2015=E2=80=9309=E2=80=9321, at 12:40 AM, Vicente J. Botet Escriba <vic=
ente.botet@wanadoo.fr> wrote:
>=20
> The signatures are not the same
>=20
> template< typename T, typename P >
> auto & recover( P cv * e );                     // cv is a cv-qualifier s=
equence

You seem to be looking at the wrong document. Is it called =E2=80=9Crecover=
_native.pdf=E2=80=9D with a note at the top, "This is a preliminary draft o=
f an alternative direction. =C2=A73.3 is a failed experiment.=E2=80=9D? Try=
 downloading again: bit.ly/reccast <http://bit.ly/reccast> .

> I would add this signature
>=20
> template< typename T, typename ErasureClass >
> constexpr auto * recover( ErasureClass * e ) noexcept;=20

It should already be so.

> I don't like this kind of cast as we don't know if the result is nullptr =
because there nothing stored or because the type is not stored at all.

I wish pointers had an immediately viable alternative=E2=80=A6

> I prefer to overload functions that do almost the same thing. Here the ov=
erload change the semantics.

Yes, exactly.

>> This is just equivalent to (T*) s.complete_object_address(). (Or the equ=
ivalent with s.referent_address().) Why should there be a shortcut? The use=
r should safely obtain a named reference at the start of the scope where T =
is statically determined.
> I prefer to don't have casts is user code. I'm sure that we will end by d=
efining this shortcut.

I prefer not to encapsulate a cast if it=E2=80=99s potentially unsafe and t=
he user can express it just as easily.

> In addition, I can define deref() for types that don't define=20
> s.complete_object_address()
Remember that these functions don=E2=80=99t work by ADL, so users wouldn=E2=
=80=99t be able to define deref.
> Yes and not. It can be also applicable to optional/expected .... That is =
any sum type.=20

optional and expected don=E2=80=99t define indexes. Do you mean to let T be=
 index 0 and disengaged be index -1UL? For expected, does that imply not re=
cognizing exception polymorphism?

> Of course. However the adaptor gives me just the functions I need? and th=
ey are just holds, deref, access, address . We need just to have the good n=
ames.

The proposal is intended to introduce a common interface to these classes, =
as a non-member function in std::. Replacing that with one more new erasure=
 class might inspire some cynicism.

>> Adaptors will work much better given generalized lifetime extension=E2=
=80=A6 I need to finish revising that proposal.
> Please, could you give me the number?
> Vicente

bit.ly/genlife <http://bit.ly/genlife> - D0066 revises N4221

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--Apple-Mail=_0E889631-2AFC-42C3-8E69-8B108625B35A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9309=
=E2=80=9321, at 12:18 AM, Vicente J. Botet Escriba &lt;<a href=3D"mailto:vi=
cente.botet@wanadoo.fr" class=3D"">vicente.botet@wanadoo.fr</a>&gt; wrote:<=
/div><br class=3D"Apple-interchange-newline"><div class=3D"">I don't think =
we need that the result is exactly optional<br class=3D""></div></blockquot=
e><div><br class=3D""></div><div>No, but both alternatives are tricky: eith=
er justify why the class shouldn=E2=80=99t be spelled <font face=3D"Courier=
" class=3D"">optional&lt;T&amp;&gt;</font>, or convince everyone that optio=
nal should accommodate references.</div></div><br class=3D""><div class=3D"=
"><br class=3D""></div><div class=3D""><blockquote type=3D"cite" class=3D""=
><div class=3D"">On 2015=E2=80=9309=E2=80=9321, at 12:40 AM, Vicente J. Bot=
et Escriba &lt;<a href=3D"mailto:vicente.botet@wanadoo.fr" class=3D"">vicen=
te.botet@wanadoo.fr</a>&gt; wrote:</div><div class=3D""></div></blockquote>=
<blockquote type=3D"cite" class=3D""><br class=3D""></blockquote><blockquot=
e type=3D"cite" class=3D""><div class=3D""><div bgcolor=3D"#FFFFFF" text=3D=
"#000000" class=3D"">The signatures are not the same<br class=3D""><br clas=
s=3D"">template&lt; typename T, typename P &gt;<br class=3D"">auto &amp; re=
cover( P cv * e );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // cv is a =
cv-qualifier sequence<br class=3D""></div></div></blockquote><div class=3D"=
"><br class=3D""></div><div class=3D"">You seem to be looking at the wrong =
document. Is it called =E2=80=9Crecover_native.pdf=E2=80=9D with a note at =
the top, "This is a preliminary draft of an&nbsp;alternative direction. =C2=
=A73.3 is a failed&nbsp;experiment.=E2=80=9D? Try downloading again: <a hre=
f=3D"http://bit.ly/reccast" class=3D"">bit.ly/reccast</a>&nbsp;.</div><br c=
lass=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><div bgcolor=
=3D"#FFFFFF" text=3D"#000000" class=3D"">I would add this signature<br clas=
s=3D""><br class=3D"">template&lt; typename T, typename ErasureClass &gt;<b=
r class=3D"">constexpr auto * recover( ErasureClass * e ) noexcept;&nbsp;<b=
r class=3D""></div></div></blockquote><div class=3D""><br class=3D""></div>=
<div class=3D"">It should already be so.</div><br class=3D""><blockquote ty=
pe=3D"cite" class=3D""><div class=3D""><div bgcolor=3D"#FFFFFF" text=3D"#00=
0000" class=3D"">I don't like this kind of cast as we don't know if the res=
ult is nullptr because there nothing stored or because the type is not stor=
ed at all.<br class=3D""></div></div></blockquote><div class=3D""><br class=
=3D""></div><div class=3D"">I wish pointers had an immediately viable alter=
native=E2=80=A6</div><br class=3D""><blockquote type=3D"cite" class=3D""><d=
iv class=3D""><div bgcolor=3D"#FFFFFF" text=3D"#000000" class=3D""><blockqu=
ote cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com" type=3D"cit=
e" class=3D""><pre wrap=3D"" class=3D""></pre></blockquote>I prefer to over=
load functions that do almost the same thing. Here the overload change the =
semantics.<br class=3D""></div></div></blockquote><div class=3D""><br class=
=3D""></div>Yes, exactly.</div><div class=3D""><br class=3D""><blockquote t=
ype=3D"cite" class=3D""><div bgcolor=3D"#FFFFFF" text=3D"#000000" class=3D"=
"><blockquote cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com" t=
ype=3D"cite" class=3D""><pre wrap=3D"" class=3D""></pre></blockquote><block=
quote cite=3D"mid:23BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com" type=3D"c=
ite" class=3D""><pre wrap=3D"" class=3D"">This is just equivalent to (T*) s=
..complete_object_address(). (Or the equivalent with s.referent_address().) =
Why should there be a shortcut? The user should safely obtain a named refer=
ence at the start of the scope where T is statically determined.</pre></blo=
ckquote>I prefer to don't have casts is user code. I'm sure that we will en=
d by defining this shortcut. </div></blockquote><div class=3D""><br class=
=3D""></div><div class=3D"">I prefer not to encapsulate a cast if it=E2=80=
=99s potentially unsafe and the user can express it just as easily.</div><b=
r class=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><div bgco=
lor=3D"#FFFFFF" text=3D"#000000" class=3D"">In addition, I can define deref=
() for types that don't define&nbsp;<br class=3D""><pre wrap=3D"" class=3D"=
">s.complete_object_address()</pre></div></div></blockquote><div class=3D""=
>Remember that these functions don=E2=80=99t work by ADL, so users wouldn=
=E2=80=99t be able to define <font face=3D"Courier" class=3D"">deref</font>=
..</div><blockquote type=3D"cite" class=3D""><div class=3D""><div bgcolor=3D=
"#FFFFFF" text=3D"#000000" class=3D""><blockquote cite=3D"mid:23BE02B7-49AC=
-4229-BE7E-191DDD032C7A@gmail.com" type=3D"cite" class=3D""><pre wrap=3D"" =
class=3D""></pre></blockquote>Yes and not. It can be also applicable to opt=
ional/expected .... That is any sum type.&nbsp;<br class=3D""></div></div><=
/blockquote><div class=3D""><br class=3D""></div><div class=3D""><font face=
=3D"Courier" class=3D"">optional</font> and <font face=3D"Courier" class=3D=
"">expected</font> don=E2=80=99t define indexes. Do you mean to let <font f=
ace=3D"Courier" class=3D"">T</font> be index <font face=3D"Courier" class=
=3D"">0</font> and disengaged be index <font face=3D"Courier" class=3D"">-1=
UL</font>? For <font face=3D"Courier" class=3D"">expected</font>, does that=
 imply not recognizing exception polymorphism?</div><div class=3D""><br cla=
ss=3D""></div><blockquote type=3D"cite" class=3D""><div class=3D""><div bgc=
olor=3D"#FFFFFF" text=3D"#000000" class=3D"">Of course. However the adaptor=
 gives me just the functions I need? and they are just holds, deref, access=
, address . We need just to have the good names.<br class=3D""></div></div>=
</blockquote><div class=3D""><br class=3D""></div>The proposal is intended =
to introduce a common interface to these classes, as a non-member function =
in&nbsp;<font face=3D"Courier" class=3D"">std::</font>. Replacing that with=
 one more new erasure class might inspire some cynicism.</div><div class=3D=
""><br class=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><div=
 bgcolor=3D"#FFFFFF" text=3D"#000000" class=3D""><blockquote cite=3D"mid:23=
BE02B7-49AC-4229-BE7E-191DDD032C7A@gmail.com" type=3D"cite" class=3D""><pre=
 wrap=3D"" class=3D"">Adaptors will work much better given generalized life=
time extension=E2=80=A6 I need to finish revising that proposal.</pre></blo=
ckquote>Please, could you give me the number?<blockquote cite=3D"mid:23BE02=
B7-49AC-4229-BE7E-191DDD032C7A@gmail.com" type=3D"cite" class=3D""></blockq=
uote>Vicente<br class=3D""></div><div class=3D""></div></div></blockquote><=
div class=3D""><br class=3D""></div><div class=3D""><a href=3D"http://bit.l=
y/genlife" class=3D"">bit.ly/genlife</a>&nbsp;- D0066 revises N4221</div></=
div><div class=3D""><div class=3D""><br class=3D""></div></div></body></htm=
l>

<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 />

--Apple-Mail=_0E889631-2AFC-42C3-8E69-8B108625B35A--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Mon, 21 Sep 2015 20:03:56 +0200
Raw View
This is a multi-part message in MIME format.
--------------010105070509010407050802
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 21/09/15 03:34, David Krauss a =C3=A9crit :
>> On 2015=E2=80=9309=E2=80=9321, at 12:18 AM, Vicente J. Botet Escriba <vi=
cente.botet@wanadoo.fr> wrote:
>>
>> I don't think we need that the result is exactly optional
> No, but both alternatives are tricky: either justify why the class should=
n=E2=80=99t be spelled optional<T&>, or convince everyone that optional sho=
uld accommodate references.
I see. Maybe we have a good use case justifying optional<T&>.
>
>
>> On 2015=E2=80=9309=E2=80=9321, at 12:40 AM, Vicente J. Botet Escriba <vi=
cente.botet@wanadoo.fr> wrote:
>>
>> The signatures are not the same
>>
>> template< typename T, typename P >
>> auto & recover( P cv * e );                     // cv is a cv-qualifier =
sequence
> You seem to be looking at the wrong document. Is it called =E2=80=9Crecov=
er_native.pdf=E2=80=9D with a note at the top, "This is a preliminary draft=
 of an alternative direction. =C2=A73.3 is a failed experiment.=E2=80=9D? T=
ry downloading again: bit.ly/reccast <http://bit.ly/reccast> .
Right. I can see the new one now, thanks.
>
>> I would add this signature
>>
>> template< typename T, typename ErasureClass >
>> constexpr auto * recover( ErasureClass * e ) noexcept;
> It should already be so.
>
>> I don't like this kind of cast as we don't know if the result is nullptr=
 because there nothing stored or because the type is not stored at all.
> I wish pointers had an immediately viable alternative=E2=80=A6
>
>> I prefer to overload functions that do almost the same thing. Here the o=
verload change the semantics.
> Yes, exactly.
>
>>> This is just equivalent to (T*) s.complete_object_address(). (Or the eq=
uivalent with s.referent_address().) Why should there be a shortcut? The us=
er should safely obtain a named reference at the start of the scope where T=
 is statically determined.
>> I prefer to don't have casts is user code. I'm sure that we will end by =
defining this shortcut.
> I prefer not to encapsulate a cast if it=E2=80=99s potentially unsafe and=
 the user can express it just as easily.
IIUC, value<T>(s) (or another name) is correct because value checks at=20
run-time the cast is safe, but deref<T> is unsafe.

*try_recover<T>(a) would be possible and unsafe if it returns optional<T&>.
>
>> In addition, I can define deref() for types that don't define
>> s.complete_object_address()
> Remember that these functions don=E2=80=99t work by ADL, so users wouldn=
=E2=80=99t be able to define deref.
I know that you are not proposing customizable functions. This is what I=20
would like to be able to do. I would like customization points that can=20
have a default implementation for models of ErasureClass.
>> Yes and not. It can be also applicable to optional/expected .... That is=
 any sum type.
> optional and expected don=E2=80=99t define indexes. Do you mean to let T =
be index 0 and disengaged be index -1UL?
I see optional<T> as nullopt_t + T, so the index 0 is for disengaged and=20
1 for T.
> For expected, does that imply not recognizing exception polymorphism?
the last proposal of expected<T> associated a default exception_ptr so=20
index access will retrieve an exception_ptr.
I'm working on a variadic expected that accepts several errors=20
expected<T, E1, E2, E3>. This class will allow check for any of the=20
errors. Of course, one of the E can be exception_ptr.
>
>> Of course. However the adaptor gives me just the functions I need? and t=
hey are just holds, deref, access, address . We need just to have the good =
names.
> The proposal is intended to introduce a common interface to these classes=
, as a non-member function in std::. Replacing that with one more new erasu=
re class might inspire some cynicism.
I'm not proposing to replace your ErasureClass, even if I would prefer=20
that the concept is defined in terms of customizable non-member=20
functions. E.g. the following functions:

template< typename T, typename ErasureClass >
bool holds( ErasureClass && e );

// pre-condition true (equivalent to complete_object_address and=20
referent_address)
template< typename T, typename ErasureClass >
auto raw_address_of( ErasureClass && e );

>>> Adaptors will work much better given generalized lifetime extension=E2=
=80=A6 I need to finish revising that proposal.
>> Please, could you give me the number?
>> Vicente
> bit.ly/genlife <http://bit.ly/genlife> - D0066 revises N4221
>
>
Thanks,
Vicente

--=20

---=20
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 e=
mail 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-proposa=
ls/.

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

<html>
  <head>
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">Le 21/09/15 03:34, David Krauss a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote
      cite=3D"mid:F660B27C-C748-4815-AACD-77A7CB4C4B86@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">
</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">On 2015=E2=80=9309=E2=80=9321, at 12:18 AM, Vicente =
J. Botet Escriba <a class=3D"moz-txt-link-rfc2396E" href=3D"mailto:vicente.=
botet@wanadoo.fr">&lt;vicente.botet@wanadoo.fr&gt;</a> wrote:

I don't think we need that the result is exactly optional
</pre>
      </blockquote>
      <pre wrap=3D"">
No, but both alternatives are tricky: either justify why the class shouldn=
=E2=80=99t be spelled optional&lt;T&amp;&gt;, or convince everyone that opt=
ional should accommodate references.</pre>
    </blockquote>
    I see. Maybe we have a good use case justifying
    optional&lt;T&amp;&gt;.<br>
    <blockquote
      cite=3D"mid:F660B27C-C748-4815-AACD-77A7CB4C4B86@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">


</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">On 2015=E2=80=9309=E2=80=9321, at 12:40 AM, Vicente =
J. Botet Escriba <a class=3D"moz-txt-link-rfc2396E" href=3D"mailto:vicente.=
botet@wanadoo.fr">&lt;vicente.botet@wanadoo.fr&gt;</a> wrote:

The signatures are not the same

template&lt; typename T, typename P &gt;
auto &amp; recover( P cv * e );                     // cv is a cv-qualifier=
 sequence
</pre>
      </blockquote>
      <pre wrap=3D"">
You seem to be looking at the wrong document. Is it called =E2=80=9Crecover=
_native.pdf=E2=80=9D with a note at the top, "This is a preliminary draft o=
f an alternative direction. =C2=A73.3 is a failed experiment.=E2=80=9D? Try=
 downloading again: bit.ly/reccast <a class=3D"moz-txt-link-rfc2396E" href=
=3D"http://bit.ly/reccast">&lt;http://bit.ly/reccast&gt;</a> .</pre>
    </blockquote>
    Right. I can see the new one now, thanks.<br>
    <blockquote
      cite=3D"mid:F660B27C-C748-4815-AACD-77A7CB4C4B86@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">I would add this signature

template&lt; typename T, typename ErasureClass &gt;
constexpr auto * recover( ErasureClass * e ) noexcept;=20
</pre>
      </blockquote>
      <pre wrap=3D"">
It should already be so.

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">I don't like this kind of cast as we don't know if t=
he result is nullptr because there nothing stored or because the type is no=
t stored at all.
</pre>
      </blockquote>
      <pre wrap=3D"">
I wish pointers had an immediately viable alternative=E2=80=A6

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">I prefer to overload functions that do almost the sa=
me thing. Here the overload change the semantics.
</pre>
      </blockquote>
      <pre wrap=3D"">
Yes, exactly.

</pre>
      <blockquote type=3D"cite">
        <blockquote type=3D"cite">
          <pre wrap=3D"">This is just equivalent to (T*) s.complete_object_=
address(). (Or the equivalent with s.referent_address().) Why should there =
be a shortcut? The user should safely obtain a named reference at the start=
 of the scope where T is statically determined.
</pre>
        </blockquote>
        <pre wrap=3D"">I prefer to don't have casts is user code. I'm sure =
that we will end by defining this shortcut.
</pre>
      </blockquote>
      <pre wrap=3D"">
I prefer not to encapsulate a cast if it=E2=80=99s potentially unsafe and t=
he user can express it just as easily.</pre>
    </blockquote>
    IIUC, value&lt;T&gt;(s) (or another name) is correct because value
    checks at run-time the cast is safe, but deref&lt;T&gt; is unsafe. <br>
    <br>
    *try_recover&lt;T&gt;(a) would be possible and unsafe if it returns
    optional&lt;T&amp;&gt;.<br>
    <blockquote
      cite=3D"mid:F660B27C-C748-4815-AACD-77A7CB4C4B86@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">In addition, I can define deref() for types that don=
't define=20
s.complete_object_address()
</pre>
      </blockquote>
      <pre wrap=3D"">Remember that these functions don=E2=80=99t work by AD=
L, so users wouldn=E2=80=99t be able to define deref.</pre>
    </blockquote>
    I know that you are not proposing customizable functions. This is
    what I would like to be able to do. I would like customization
    points that can have a default implementation for models of
    ErasureClass.<br>
    <blockquote
      cite=3D"mid:F660B27C-C748-4815-AACD-77A7CB4C4B86@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">
</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">Yes and not. It can be also applicable to optional/e=
xpected .... That is any sum type.=20
</pre>
      </blockquote>
      <pre wrap=3D"">
optional and expected don=E2=80=99t define indexes. Do you mean to let T be=
 index 0 and disengaged be index -1UL? </pre>
    </blockquote>
    I see optional&lt;T&gt; as nullopt_t + T, so the index 0 is for
    disengaged and 1 for T.<br>
    <blockquote
      cite=3D"mid:F660B27C-C748-4815-AACD-77A7CB4C4B86@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">For expected, does that imply not recognizing exceptio=
n polymorphism?</pre>
    </blockquote>
    the last proposal of expected&lt;T&gt; associated a default
    exception_ptr so index access will retrieve an exception_ptr.<br>
    I'm working on a variadic expected that accepts several errors
    expected&lt;T, E1, E2, E3&gt;. This class will allow check for any
    of the errors. Of course, one of the E can be exception_ptr. <br>
    <blockquote
      cite=3D"mid:F660B27C-C748-4815-AACD-77A7CB4C4B86@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">

</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">Of course. However the adaptor gives me just the fun=
ctions I need? and they are just holds, deref, access, address . We need ju=
st to have the good names.
</pre>
      </blockquote>
      <pre wrap=3D"">
The proposal is intended to introduce a common interface to these classes, =
as a non-member function in std::. Replacing that with one more new erasure=
 class might inspire some cynicism.
</pre>
    </blockquote>
    I'm not proposing to replace your ErasureClass, even if I would
    prefer that the concept is defined in terms of customizable
    non-member functions. E.g. the following functions: <br>
    <br>
    template&lt; typename T, typename ErasureClass &gt;<br>
    bool holds( ErasureClass &amp;&amp; e );<br>
    <br>
    // pre-condition true (equivalent to complete_object_address and
    referent_address)<br>
    template&lt; typename T, typename ErasureClass &gt;<br>
    auto raw_address_of( ErasureClass &amp;&amp; e ); <br>
    <br>
    <meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8=
">
    <blockquote
      cite=3D"mid:F660B27C-C748-4815-AACD-77A7CB4C4B86@gmail.com"
      type=3D"cite">
      <pre wrap=3D"">
</pre>
      <blockquote type=3D"cite">
        <blockquote type=3D"cite">
          <pre wrap=3D"">Adaptors will work much better given generalized l=
ifetime extension=E2=80=A6 I need to finish revising that proposal.
</pre>
        </blockquote>
        <pre wrap=3D"">Please, could you give me the number?
Vicente
</pre>
      </blockquote>
      <pre wrap=3D"">
bit.ly/genlife <a class=3D"moz-txt-link-rfc2396E" href=3D"http://bit.ly/gen=
life">&lt;http://bit.ly/genlife&gt;</a> - D0066 revises N4221


</pre>
    </blockquote>
    Thanks,<br>
    Vicente<br>
  </body>
</html>

<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 />

--------------010105070509010407050802--

.