digitalmars.D - Re: Spec#, nullables and more
- bearophile <bearophileHUGS lycos.com> Nov 06 2010
- Christopher Bergqvist <chris digitalpoetry.se> Nov 06 2010
- "Denis Koroskin" <2korden gmail.com> Nov 06 2010
- Christopher Bergqvist <chris digitalpoetry.se> Nov 06 2010
Don:bearophile wrote:... http://d.puremagic.com/issues/show_bug.cgi?id=5081
As was pointed out in a recent post, the return value of a pure function is guaranteed to be unique, so could be allowed to implictly cast to immutable. I'm planning a patch for that soon, to see how well it works in practice.
Right, that's the bug 5081 :-) It works with strong pure. It's a simple but very nice idea that avoids some casts.But I don't think that would work for non-nulls. I don't think the two situations have a great deal in common.
I see, they may have different solutions too. Bye and thank you, bearophile
Nov 06 2010
--00163631046f7ec8d9049460618c Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Does D have anything comparable to C++ references =E0 la "void nullCheckLessFunction(const std::string& notNullStr) {...}" or does it only have the equivalent of "void nullCheckingRequired(const std::string* mightByNullStr) {...}"? --00163631046f7ec8d9049460618c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8">Do= es D have anything comparable to C++ references =E0 la "void nullCheck= LessFunction(const std::string& notNullStr) {...}" or does it only= have the equivalent of "void nullCheckingRequired(const std::string* = mightByNullStr) {...}"? --00163631046f7ec8d9049460618c--
Nov 06 2010
On Sat, 06 Nov 2010 14:06:20 +0300, Christopher Bergqvist = <chris digitalpoetry.se> wrote:Does D have anything comparable to C++ references =C3=A0 la "void nullCheckLessFunction(const std::string& notNullStr) {...}" or does it=
only have the equivalent of "void nullCheckingRequired(const std::string* mightByNullStr) {...}"?
void nullCheckLessFunction(ref const(string) notNullStr) { .. }
Nov 06 2010
--0016364d30a5e5327d049461a7a1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sat, Nov 6, 2010 at 12:23 PM, Denis Koroskin <2korden gmail.com> wrote:On Sat, 06 Nov 2010 14:06:20 +0300, Christopher Bergqvist < chris digitalpoetry.se> wrote: Does D have anything comparable to C++ references =E0 la "voidnullCheckLessFunction(const std::string& notNullStr) {...}" or does it only have the equivalent of "void nullCheckingRequired(const std::string* mightByNullStr) {...}"?
void nullCheckLessFunction(ref const(string) notNullStr) { .. }
I made two comparison snippets between D & C++. http://ideone.com/VPzz6 (D) http://ideone.com/HzFRB (C++) I feel like C++ is one small step ahead of D in this respect. It's not possible to trust that C++ references are non-null, but at least they serve as concise documentation of the expected contents and tend to make surrounding code perform the null-check up front before dereferencing from pointer to C++ reference. --0016364d30a5e5327d049461a7a1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On Sat, Nov 6, 2010 at 12:23 PM, Denis Koroskin = <span dir=3D"ltr"><<a href=3D"mailto:2korden gmail.com">2korden gmail.co= m</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margi= n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> <div><div></div><div class=3D"h5">On Sat, 06 Nov 2010 14:06:20 +0300, Chris= topher Bergqvist <<a href=3D"mailto:chris digitalpoetry.se" target=3D"_b= lank">chris digitalpoetry.se</a>> wrote:<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> Does D have anything comparable to C++ references =E0 la "void<br> nullCheckLessFunction(const std::string& notNullStr) {...}" or doe= s it only<br> have the equivalent of "void nullCheckingRequired(const std::string*<b= r> mightByNullStr) {...}"?<br> </blockquote> <br></div></div> void nullCheckLessFunction(ref const(string) notNullStr) { .. }<br> </blockquote></div><br><div>I made two comparison snippets between D & = C++.</div><div><br></div><div><a href=3D"http://ideone.com/VPzz6">http://id= eone.com/VPzz6</a>=A0(D)</div><div><a href=3D"http://ideone.com/HzFRB">http= ://ideone.com/HzFRB</a>=A0(C++)</div> <div><br></div><div>I feel like C++ is one small step ahead of D in this re= spect. It's not possible to trust that C++ references are non-null, but= at least they serve as concise documentation of the expected contents and = tend to make surrounding code perform the null-check up front before derefe= rencing from pointer to C++ reference.</div> --0016364d30a5e5327d049461a7a1--
Nov 06 2010