Topic: typed nullptr
Author: Rogge L <latrogge@gmail.com>
Date: Wed, 29 Jul 2015 05:30:42 -0700 (PDT)
Raw View
------=_Part_5325_2041687229.1438173042356
Content-Type: multipart/alternative;
boundary="----=_Part_5326_1980778691.1438173042357"
------=_Part_5326_1980778691.1438173042357
Content-Type: text/plain; charset=UTF-8
Hello,
I see some discussion about typed null pointers in std::optional-related
topics, but I don't think that std::optional really addresses the following
problem.
A nullptr can implicitly be converted to a pointer of any type.
But what if I have several overloads of a function, expecting pointers of
different types, all matching (tts "convertible from") a nullptr?
Usually, I have to explictly cast to the desired pointer type:
void func(char *p);
void func(int *p);
func(nullptr); => func((int*)nullptr);
actually it would be cleaner to use
func(static_cast<int*>(nullptr));
But it's quite long.
Likewise for all cases where we can have a ambiguous conversion from a
nullptr to several specific pointer types.
I just wonder if it would be useful to have a dedicated "short" syntax for
typed nullptr's?
For instance, something like nullptr<int> or nullptr<int*>?
Not a big-bang feature, but it could help having safer null pointers (which
is the goal of nullptr).
Or I am overlooking one of many new features of C++1x addressing that kind
of issue?
Luc
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_5326_1980778691.1438173042357
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hello,<div><br></div><div>I see some discussion about type=
d null pointers in std::optional-related topics, but I don't think that=
std::optional really addresses the following problem.</div><div><br></div>=
<div>A nullptr can implicitly be converted to a pointer of any type.</div><=
div>But what if I have several overloads of a function, expecting pointers =
of different types, all matching (tts "convertible from") a nullp=
tr?</div><div><br></div><div>Usually, I have to explictly cast to the desir=
ed pointer type:</div><div><br></div><div>void func(char *p);</div><div><di=
v>void func(int *p);</div></div><div>func(nullptr); =3D> func((int*)null=
ptr);<br></div><div><br></div><div>actually it would be cleaner to use</div=
><div>func(static_cast<int*>(nullptr));<br></div><div>But it's qu=
ite long.<br></div><div><br></div><div><div>Likewise for all cases where we=
can have a ambiguous conversion from a nullptr to several specific pointer=
types.<br></div></div><div><br></div><div>I just wonder if it would be use=
ful to have a dedicated "short" syntax for typed nullptr's?</=
div><div><br></div><div>For instance, something like nullptr<int> or =
nullptr<int*>?</div><div><br></div><div>Not a big-bang feature, but i=
t could help having safer null pointers (which is the goal of nullptr).</di=
v><div><br></div><div>Or I am overlooking one of many new features of C++1x=
addressing that kind of issue?</div><div><br></div><div>Luc<br></div></div=
>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_5326_1980778691.1438173042357--
------=_Part_5325_2041687229.1438173042356--
.
Author: =?UTF-8?Q?David_Rodr=C3=ADguez_Ibeas?= <dibeas@ieee.org>
Date: Wed, 29 Jul 2015 13:46:30 +0100
Raw View
--001a1135e3d6db582a051c02f941
Content-Type: text/plain; charset=UTF-8
I don't think that there's anything in C++14 addressing that, but it can
trivially be done through a variable template:
template <typename T>
constexpr T* const null_ptr = nullptr;
f(null_ptr<int>);
That is, if I got the syntax right.
David
On Wed, Jul 29, 2015 at 1:30 PM, Rogge L <latrogge@gmail.com> wrote:
> Hello,
>
> I see some discussion about typed null pointers in std::optional-related
> topics, but I don't think that std::optional really addresses the following
> problem.
>
> A nullptr can implicitly be converted to a pointer of any type.
> But what if I have several overloads of a function, expecting pointers of
> different types, all matching (tts "convertible from") a nullptr?
>
> Usually, I have to explictly cast to the desired pointer type:
>
> void func(char *p);
> void func(int *p);
> func(nullptr); => func((int*)nullptr);
>
> actually it would be cleaner to use
> func(static_cast<int*>(nullptr));
> But it's quite long.
>
> Likewise for all cases where we can have a ambiguous conversion from a
> nullptr to several specific pointer types.
>
> I just wonder if it would be useful to have a dedicated "short" syntax for
> typed nullptr's?
>
> For instance, something like nullptr<int> or nullptr<int*>?
>
> Not a big-bang feature, but it could help having safer null pointers
> (which is the goal of nullptr).
>
> Or I am overlooking one of many new features of C++1x addressing that kind
> of issue?
>
> Luc
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a1135e3d6db582a051c02f941
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I don't think that there's anything in C++14 addre=
ssing that, but it can trivially be done through a variable template:<br><b=
r>template <typename T> <br>constexpr T* const null_ptr =3D nullptr;<=
br><br>f(null_ptr<int>);<br><br>That is, if I got the syntax right.<b=
r><br>=C2=A0 =C2=A0David</div><div class=3D"gmail_extra"><br><div class=3D"=
gmail_quote">On Wed, Jul 29, 2015 at 1:30 PM, Rogge L <span dir=3D"ltr"><=
;<a href=3D"mailto:latrogge@gmail.com" target=3D"_blank">latrogge@gmail.com=
</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin=
:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">H=
ello,<div><br></div><div>I see some discussion about typed null pointers in=
std::optional-related topics, but I don't think that std::optional rea=
lly addresses the following problem.</div><div><br></div><div>A nullptr can=
implicitly be converted to a pointer of any type.</div><div>But what if I =
have several overloads of a function, expecting pointers of different types=
, all matching (tts "convertible from") a nullptr?</div><div><br>=
</div><div>Usually, I have to explictly cast to the desired pointer type:</=
div><div><br></div><div>void func(char *p);</div><div><div>void func(int *p=
);</div></div><div>func(nullptr); =3D> func((int*)nullptr);<br></div><di=
v><br></div><div>actually it would be cleaner to use</div><div>func(static_=
cast<int*>(nullptr));<br></div><div>But it's quite long.<br></div=
><div><br></div><div><div>Likewise for all cases where we can have a ambigu=
ous conversion from a nullptr to several specific pointer types.<br></div><=
/div><div><br></div><div>I just wonder if it would be useful to have a dedi=
cated "short" syntax for typed nullptr's?</div><div><br></div=
><div>For instance, something like nullptr<int> or nullptr<int*>=
;?</div><div><br></div><div>Not a big-bang feature, but it could help havin=
g safer null pointers (which is the goal of nullptr).</div><div><br></div><=
div>Or I am overlooking one of many new features of C++1x addressing that k=
ind of issue?</div><div><br></div><div>Luc<span class=3D"HOEnZb"><font colo=
r=3D"#888888"><br></font></span></div></div><span class=3D"HOEnZb"><font co=
lor=3D"#888888">
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
--001a1135e3d6db582a051c02f941--
.
Author: Nevin Liber <nevin@eviloverlord.com>
Date: Wed, 29 Jul 2015 09:52:24 -0500
Raw View
--089e0122f83a7495ef051c04be34
Content-Type: text/plain; charset=UTF-8
On 29 July 2015 at 07:30, Rogge L <latrogge@gmail.com> wrote:
> void func(char *p);
> void func(int *p);
> func(nullptr); => func((int*)nullptr);
>
Why not just add to your code:
void func(nullptr_t) { func(static_cast<int*>(nullptr)); }
> --
>
Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--089e0122f83a7495ef051c04be34
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On 29 July 2015 at 07:30, Rogge L <span dir=3D"ltr"><<a=
href=3D"mailto:latrogge@gmail.com" target=3D"_blank">latrogge@gmail.com</a=
>></span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gmail_quote=
"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>void func(char *p);<=
br></div><div><div>void func(int *p);</div></div><div>func(nullptr); =3D>=
; func((int*)nullptr);<br></div></div></blockquote><div><br></div><div>Why =
not just add to your code:</div><div><br></div><div>void func(nullptr_t) { =
func(static_cast<int*>(nullptr)); }</div><div>=C2=A0</div><blockquote=
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex"><div dir=3D"ltr"><div></div><div>--=C2=A0<br></div></di=
v></blockquote></div><div class=3D"gmail_signature">=C2=A0Nevin ":-)&q=
uot; Liber=C2=A0 <mailto:<a href=3D"mailto:nevin@eviloverlord.com" targe=
t=3D"_blank">nevin@eviloverlord.com</a>>=C2=A0 (847) 691-1404</div>
</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
--089e0122f83a7495ef051c04be34--
.