www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - D idioms list

reply "ponce" <contact gam3sfrommars.fr> writes:
I've started a list of curated D tips and tricks here: 
http://p0nce.github.io/d-idioms/

Anything that you wished you learned earlier at one point in the 
D world is welcome to be added or suggested.

I think the focus should be on "stuff that could make you more 
productive, or is just funky" but that is up to debate.

Of course the D Cookbook still stays irreplaceable for a 
consistent, in-depth discussion of being D-enabled.

Thoughts?
Jan 08 2015
next sibling parent reply "uri" <uri.grill gmail.com> writes:
On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
 I've started a list of curated D tips and tricks here: 
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in 
 the D world is welcome to be added or suggested.

 I think the focus should be on "stuff that could make you more 
 productive, or is just funky" but that is up to debate.

 Of course the D Cookbook still stays irreplaceable for a 
 consistent, in-depth discussion of being D-enabled.

 Thoughts?
This is great, thanks. Something I personally would find useful is a comparison between the C++ way and idiomatic D with Phobos. I finding coming from C/C++ to D very easy but I'm always wondering if I'm doing things the "D" way. Cheers, uri
Jan 08 2015
parent reply "ponce" <contact gam3sfrommars.fr> writes:
On Thursday, 8 January 2015 at 10:30:38 UTC, uri wrote:
 This is great, thanks.

 Something I personally would find useful is a comparison 
 between the C++ way and idiomatic D with Phobos. I finding 
 coming from C/C++ to D very easy but I'm always wondering if 
 I'm doing things the "D" way.

 Cheers,
 uri
I'm not familiar with the terse, range-heavy, UFCS style that has emerged from Phobos so I'm not sure if I can write that. What could help is a list of tasks for which you asked yourself what the "D" way was. Is there one?
Jan 08 2015
next sibling parent "uri" <uri.grill gmail.com> writes:
On Thursday, 8 January 2015 at 10:35:07 UTC, ponce wrote:
 On Thursday, 8 January 2015 at 10:30:38 UTC, uri wrote:
 This is great, thanks.

 Something I personally would find useful is a comparison 
 between the C++ way and idiomatic D with Phobos. I finding 
 coming from C/C++ to D very easy but I'm always wondering if 
 I'm doing things the "D" way.

 Cheers,
 uri
I'm not familiar with the terse, range-heavy, UFCS style that has emerged from Phobos so I'm not sure if I can write that. What could help is a list of tasks for which you asked yourself what the "D" way was. Is there one?
No I admit I don't have any real list. It's always an "in the moment" sort of thing and I then just choose a D-ish/C++ style and promptly forget the exact details. I'll start to compile a list each time this comes up. And if I find any good D idioms in the process I'll include them in the list as well. Thanks, uri
Jan 08 2015
prev sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
ponce:

 I'm not familiar with the terse, range-heavy, UFCS style that 
 has emerged from Phobos
In Rosettacode I have inserted tons of examples of that coding style. An example, given a tuple of arbitrary length, with items all of the same type, how do you compute the total of its items? The last way I've invented is: myTuple[].only.sum It's also nogc. But it causes a little of template bloat. Bye, bearophile
Jan 08 2015
parent "ponce" <contact gam3sfrommars.fr> writes:
On Thursday, 8 January 2015 at 10:56:00 UTC, bearophile wrote:
 ponce:

 I'm not familiar with the terse, range-heavy, UFCS style that 
 has emerged from Phobos
In Rosettacode I have inserted tons of examples of that coding style. An example, given a tuple of arbitrary length, with items all of the same type, how do you compute the total of its items? The last way I've invented is: myTuple[].only.sum It's also nogc. But it causes a little of template bloat. Bye, bearophile
Cool. I will link to the Rosettacode D pages since I've used them in the past when time-constrained, especially all things regarding text files.
Jan 08 2015
prev sibling next sibling parent reply "Szymon Gatner" <noemail gmail.com> writes:
On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
 I've started a list of curated D tips and tricks here: 
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in 
 the D world is welcome to be added or suggested.

 I think the focus should be on "stuff that could make you more 
 productive, or is just funky" but that is up to debate.

 Of course the D Cookbook still stays irreplaceable for a 
 consistent, in-depth discussion of being D-enabled.

 Thoughts?
They are really cool, thanks :) Question: Where did this syntax came from? It is not documented for 'import' keyword.(first time I see that D has built-in resource compiler): ubyte[] sdlBytes = cast(ubyte[]) import("SDL2.dll");
Jan 08 2015
parent reply ketmar via Digitalmars-d-announce <digitalmars-d-announce puremagic.com> writes:
On Thu, 08 Jan 2015 11:24:34 +0000
Szymon Gatner via Digitalmars-d-announce
<digitalmars-d-announce puremagic.com> wrote:

 On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
 I've started a list of curated D tips and tricks here:=20
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in=20
 the D world is welcome to be added or suggested.

 I think the focus should be on "stuff that could make you more=20
 productive, or is just funky" but that is up to debate.

 Of course the D Cookbook still stays irreplaceable for a=20
 consistent, in-depth discussion of being D-enabled.

 Thoughts?
=20 They are really cool, thanks :) =20 Question: =20 Where did this syntax came from? It is not documented for=20 'import' keyword.(first time I see that D has built-in resource=20 compiler): =20 ubyte[] sdlBytes =3D cast(ubyte[]) import("SDL2.dll");
it is documented: http://dlang.org/expression.html#ImportExpression it's a nice D habit of overloading keywords.
Jan 08 2015
parent reply "Szymon Gatner" <noemail gmail.com> writes:
On Thursday, 8 January 2015 at 11:31:14 UTC, ketmar via 
Digitalmars-d-announce wrote:
 On Thu, 08 Jan 2015 11:24:34 +0000
 Szymon Gatner via Digitalmars-d-announce
 <digitalmars-d-announce puremagic.com> wrote:

 On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
 I've started a list of curated D tips and tricks here: 
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in 
 the D world is welcome to be added or suggested.

 I think the focus should be on "stuff that could make you 
 more productive, or is just funky" but that is up to debate.

 Of course the D Cookbook still stays irreplaceable for a 
 consistent, in-depth discussion of being D-enabled.

 Thoughts?
They are really cool, thanks :) Question: Where did this syntax came from? It is not documented for 'import' keyword.(first time I see that D has built-in resource compiler): ubyte[] sdlBytes = cast(ubyte[]) import("SDL2.dll");
it is documented: http://dlang.org/expression.html#ImportExpression it's a nice D habit of overloading keywords.
Ah, thanks. Follow up then: can such imported string be used for mixin?
Jan 08 2015
next sibling parent reply "ponce" <contact gam3sfrommars.fr> writes:
On Thursday, 8 January 2015 at 11:41:43 UTC, Szymon Gatner wrote:
 
 Question:
 
 Where did this syntax came from? It is not documented for 
 'import' keyword.(first time I see that D has built-in 
 resource compiler):
 
 ubyte[] sdlBytes = cast(ubyte[]) import("SDL2.dll");
it is documented: http://dlang.org/expression.html#ImportExpression it's a nice D habit of overloading keywords.
Ah, thanks. Follow up then: can such imported string be used for mixin?
Yes.
Jan 08 2015
parent "Szymon Gatner" <noemail gmail.com> writes:
On Thursday, 8 January 2015 at 11:43:30 UTC, ponce wrote:
 On Thursday, 8 January 2015 at 11:41:43 UTC, Szymon Gatner 
 wrote:
 
 Question:
 
 Where did this syntax came from? It is not documented for 
 'import' keyword.(first time I see that D has built-in 
 resource compiler):
 
 ubyte[] sdlBytes = cast(ubyte[]) import("SDL2.dll");
it is documented: http://dlang.org/expression.html#ImportExpression it's a nice D habit of overloading keywords.
Ah, thanks. Follow up then: can such imported string be used for mixin?
Yes.
That is pretty damn cool then.
Jan 08 2015
prev sibling parent ketmar via Digitalmars-d-announce <digitalmars-d-announce puremagic.com> writes:
On Thu, 08 Jan 2015 11:41:42 +0000
Szymon Gatner via Digitalmars-d-announce
<digitalmars-d-announce puremagic.com> wrote:

 On Thursday, 8 January 2015 at 11:31:14 UTC, ketmar via=20
 Digitalmars-d-announce wrote:
 On Thu, 08 Jan 2015 11:24:34 +0000
 Szymon Gatner via Digitalmars-d-announce
 <digitalmars-d-announce puremagic.com> wrote:

 On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
 I've started a list of curated D tips and tricks here:=20
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in=20
 the D world is welcome to be added or suggested.

 I think the focus should be on "stuff that could make you=20
 more productive, or is just funky" but that is up to debate.

 Of course the D Cookbook still stays irreplaceable for a=20
 consistent, in-depth discussion of being D-enabled.

 Thoughts?
=20 They are really cool, thanks :) =20 Question: =20 Where did this syntax came from? It is not documented for=20 'import' keyword.(first time I see that D has built-in=20 resource compiler): =20 ubyte[] sdlBytes =3D cast(ubyte[]) import("SDL2.dll");
it is documented:=20 http://dlang.org/expression.html#ImportExpression it's a nice D habit of overloading keywords.
=20 Ah, thanks. Follow up then: can such imported string be used for=20 mixin?
sure. either directly, or you can use CTFE to parse imported data and generate code. for now it's somewhat limited, 'cause CTFE parsing eats alot of memory, but when we'll have 128GB of RAM at bare minimum... i don't think that i'll be using external preprocessors to generate D code from various text and binary files.
Jan 08 2015
prev sibling next sibling parent "Robert burner Schadek" <rburners gmail.com> writes:
that a really nice idea, thanks.

substring position, std.string.(last)indexOf(|Any|Neither) may be 
better


btw. this should move to the dlang wiki. Any takers?
Jan 08 2015
prev sibling next sibling parent reply "Foo" <Foo test.de> writes:
On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
 I've started a list of curated D tips and tricks here: 
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in 
 the D world is welcome to be added or suggested.

 I think the focus should be on "stuff that could make you more 
 productive, or is just funky" but that is up to debate.

 Of course the D Cookbook still stays irreplaceable for a 
 consistent, in-depth discussion of being D-enabled.

 Thoughts?
"Struct inheritance with alias this" You are using a class ;)
Jan 08 2015
parent reply "Foo" <Foo test.de> writes:
On Thursday, 8 January 2015 at 20:00:11 UTC, Foo wrote:
 On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
 I've started a list of curated D tips and tricks here: 
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in 
 the D world is welcome to be added or suggested.

 I think the focus should be on "stuff that could make you more 
 productive, or is just funky" but that is up to debate.

 Of course the D Cookbook still stays irreplaceable for a 
 consistent, in-depth discussion of being D-enabled.

 Thoughts?
"Struct inheritance with alias this" You are using a class ;)
And the public label is redundant.
Jan 08 2015
parent reply "ponce" <contact gamesfrommars.fr> writes:
On Thursday, 8 January 2015 at 21:28:56 UTC, Foo wrote:
 On Thursday, 8 January 2015 at 20:00:11 UTC, Foo wrote:
 On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
 I've started a list of curated D tips and tricks here: 
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in 
 the D world is welcome to be added or suggested.

 I think the focus should be on "stuff that could make you 
 more productive, or is just funky" but that is up to debate.

 Of course the D Cookbook still stays irreplaceable for a 
 consistent, in-depth discussion of being D-enabled.

 Thoughts?
"Struct inheritance with alias this" You are using a class ;)
And the public label is redundant.
Corrected. Never realized public: was implied.
Jan 08 2015
parent "Foo" <Foo test.de> writes:
I saw recently (at last in this thread: 
http://forum.dlang.org/thread/tdfydchrairigdlgtyum forum.dlang.org#post-qakiogaqvmiwlneimhg
:40forum.dlang.org) 
that many users use
----
key in aa ? aa[key] : ValueType.init;
----
instead of
----
auto ptr = key in aa;
ptr ? *ptr : ValueType.init;
----
which is more economic.
Maybe you can add it to your list:

----
import std.stdio;

void main() {
	immutable string key = "foo";
	immutable string[string] arr = [key : "bar"];
	
	if (auto ptr = key in arr)
		writeln(*ptr);
}
----
Jan 08 2015
prev sibling next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
A note:

a resource compiler is still useful for things like giving a 
Windows program an icon or other such things where the operating 
system needs to find the data, since the OS doesn't know how D 
stores info.

(a fun project that I'm kinda tempted to do some day btw: make 
program that CAN fetch imported data from a D program. Maybe 
reading the executable, or maybe establishing a command line 
protocol to fetch it with the program's help. )

You can compile resources on Windows in D exactly the same way as 
in C.



Another thing too, I'm starting work on a "This week in D" thing 
and tips like these are one of the things I'd like to put in it. 
I guess I don't have anything else to say about it right now, I 
still have some more prep work to do, but if any of you have 
idioms or tricks, we should compile a list for reference and 
perhaps slightly longer articles about their use we can stick in 
the newsletter. (I'm thinking the length should only be 2-5 
paragraphs.)
Jan 08 2015
parent "ponce" <contact gam3sfrommars.fr> writes:
On Thursday, 8 January 2015 at 20:16:24 UTC, Adam D. Ruppe wrote:
 Another thing too, I'm starting work on a "This week in D" 
 thing and tips like these are one of the things I'd like to put 
 in it. I guess I don't have anything else to say about it right 
 now, I still have some more prep work to do, but if any of you 
 have idioms or tricks, we should compile a list for reference 
 and perhaps slightly longer articles about their use we can 
 stick in the newsletter. (I'm thinking the length should only 
 be 2-5 paragraphs.)
Feel free to take and extend :)
Jan 08 2015
prev sibling next sibling parent reply ketmar via Digitalmars-d-announce <digitalmars-d-announce puremagic.com> writes:
On Thu, 08 Jan 2015 10:21:25 +0000
ponce via Digitalmars-d-announce <digitalmars-d-announce puremagic.com>
wrote:

 I've started a list of curated D tips and tricks here:=20
 http://p0nce.github.io/d-idioms/
=20
 Anything that you wished you learned earlier at one point in the=20
 D world is welcome to be added or suggested.
=20
 I think the focus should be on "stuff that could make you more=20
 productive, or is just funky" but that is up to debate.
=20
 Of course the D Cookbook still stays irreplaceable for a=20
 consistent, in-depth discussion of being D-enabled.
=20
 Thoughts?
i'm not sure, but maybe it worth renaming "struct inheritance" to "extending a struct"? or even something completely different. what it does is actually extending/augmenting the struct, but not OO-inheritance, as one cannot pass "augmented" struct to the function which expects original struct. at least without hackery.
Jan 08 2015
parent reply "ponce" <contact gam3sfrommars.fr> writes:
On Thursday, 8 January 2015 at 20:23:11 UTC, ketmar via 
Digitalmars-d-announce wrote:
 i'm not sure, but maybe it worth renaming "struct inheritance" 
 to
 "extending a struct"? or even something completely different. 
 what it
 does is actually extending/augmenting the struct, but not
 OO-inheritance, as one cannot pass "augmented" struct to the 
 function
 which expects original struct. at least without hackery.
Renamed, thanks!
Jan 08 2015
next sibling parent ketmar via Digitalmars-d-announce <digitalmars-d-announce puremagic.com> writes:
On Thu, 08 Jan 2015 21:22:30 +0000
ponce via Digitalmars-d-announce <digitalmars-d-announce puremagic.com>
wrote:

 On Thursday, 8 January 2015 at 20:23:11 UTC, ketmar via=20
 Digitalmars-d-announce wrote:
 i'm not sure, but maybe it worth renaming "struct inheritance"=20
 to
 "extending a struct"? or even something completely different.=20
 what it
 does is actually extending/augmenting the struct, but not
 OO-inheritance, as one cannot pass "augmented" struct to the=20
 function
 which expects original struct. at least without hackery.
=20 Renamed, thanks!
we actually can pass "extended" struct as original one, as Artur shown, but i believe that "extending" is still better. p.s. you forgot to fix TOC, which still reads "struct inheritance".
Jan 08 2015
prev sibling parent reply ketmar via Digitalmars-d-announce <digitalmars-d-announce puremagic.com> writes:
On Thu, 08 Jan 2015 21:22:30 +0000
ponce via Digitalmars-d-announce <digitalmars-d-announce puremagic.com>
wrote:

 On Thursday, 8 January 2015 at 20:23:11 UTC, ketmar via=20
 Digitalmars-d-announce wrote:
 i'm not sure, but maybe it worth renaming "struct inheritance"=20
 to
 "extending a struct"? or even something completely different.=20
 what it
 does is actually extending/augmenting the struct, but not
 OO-inheritance, as one cannot pass "augmented" struct to the=20
 function
 which expects original struct. at least without hackery.
=20 Renamed, thanks!
p.p.s. maybe it's worth adding Artur's code sample[1] too, to show that "extended" structure can be passed to functions which requires original one? it's not obvious, at least for me. ;-) [1] http://forum.dlang.org/post/mailman.4332.1420752329.9932.digitalmars-d-= announce puremagic.com
Jan 08 2015
parent "ponce" <contact gam3sfrommars.fr> writes:
On Friday, 9 January 2015 at 05:58:09 UTC, ketmar via 
Digitalmars-d-announce wrote:
 p.p.s. maybe it's worth adding Artur's code sample[1] too, to 
 show that
 "extended" structure can be passed to functions which requires 
 original
 one? it's not obvious, at least for me. ;-)

 [1] 
 http://forum.dlang.org/post/mailman.4332.1420752329.9932.digitalmars-d-announce puremagic.com
I didn't knew alias this does object slicing. Will add it.
Jan 09 2015
prev sibling next sibling parent Artur Skawina via Digitalmars-d-announce writes:
On 01/08/15 21:23, ketmar via Digitalmars-d-announce wrote:
 i'm not sure, but maybe it worth renaming "struct inheritance" to
 "extending a struct"? or even something completely different. what it
 does is actually extending/augmenting the struct, but not
 OO-inheritance, as one cannot pass "augmented" struct to the function
 which expects original struct. at least without hackery.
'alias this' is just the D syntax for implicit conversions. The feature /is/ crippled, but there's no need for "hackery"; at least not for simple things like that. struct A { int a; } struct B { A a; alias a this; string b; } int f(A a) { return a.a+1; } int g(ref A a) { return a.a+1; } ref A h(ref A a) { return a; } int main() { B b; return f(b)+g(b)+h(b).a; } artur
Jan 08 2015
prev sibling next sibling parent "weaselcat" <weaselcat gmail.com> writes:
On Thursday, 8 January 2015 at 10:21:26 UTC, ponce wrote:
 I've started a list of curated D tips and tricks here: 
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in 
 the D world is welcome to be added or suggested.

 I think the focus should be on "stuff that could make you more 
 productive, or is just funky" but that is up to debate.

 Of course the D Cookbook still stays irreplaceable for a 
 consistent, in-depth discussion of being D-enabled.

 Thoughts?
Not much to add but I enjoy reading 'idiomatic' D content - coming from C++, I feel like I'm often not writing my D code like I should be. Thanks for the extra resource.
Jan 08 2015
prev sibling next sibling parent ketmar via Digitalmars-d-announce <digitalmars-d-announce puremagic.com> writes:
On Thu, 08 Jan 2015 22:25:11 +0100
Artur Skawina via Digitalmars-d-announce
<digitalmars-d-announce puremagic.com> wrote:

 On 01/08/15 21:23, ketmar via Digitalmars-d-announce wrote:
 i'm not sure, but maybe it worth renaming "struct inheritance" to
 "extending a struct"? or even something completely different. what it
 does is actually extending/augmenting the struct, but not
 OO-inheritance, as one cannot pass "augmented" struct to the function
 which expects original struct. at least without hackery.
=20 'alias this' is just the D syntax for implicit conversions. The feature /is/ crippled, but there's no need for "hackery"; at least not for simple things like that. =20 struct A { int a; } struct B { A a; alias a this; string b; } =20 int f(A a) { return a.a+1; } int g(ref A a) { return a.a+1; } ref A h(ref A a) { return a; } =20 int main() { B b; return f(b)+g(b)+h(b).a; } =20 artur
mea culpa. i completely forgot about that feature of `alias this`, and was pretty sure that the code above is invalid. i never bothered to really check it. sorry.
Jan 08 2015
prev sibling next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 1/8/2015 2:21 AM, ponce wrote:
 I've started a list of curated D tips and tricks here:
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in the D world is
 welcome to be added or suggested.
My contribution: http://digitalmars.com/articles/b68.html (Member function pointers in D)
Jan 10 2015
parent reply "weaselcat" <weaselcat gmail.com> writes:
On Saturday, 10 January 2015 at 20:37:04 UTC, Walter Bright wrote:
 On 1/8/2015 2:21 AM, ponce wrote:
 I've started a list of curated D tips and tricks here:
 http://p0nce.github.io/d-idioms/

 Anything that you wished you learned earlier at one point in 
 the D world is
 welcome to be added or suggested.
My contribution: http://digitalmars.com/articles/b68.html (Member function pointers in D)
Sorry for the off-topic noise, but where will you be publishing your articles since Dr.Dobbs has closed? Sorry if you have answered this elsewhere.
Jan 10 2015
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 1/10/2015 1:28 PM, weaselcat wrote:
 Sorry for the off-topic noise, but where will you be publishing your articles
 since Dr.Dobbs has closed?

 Sorry if you have answered this elsewhere.
It's a good question. Dr. Dobb's has graciously given me permission to republish them, and I'll post them on http://digitalmars.com/articles. As you can see, I've already done a few of them. Lots more to go.
Jan 10 2015
parent reply Russel Winder via Digitalmars-d-announce writes:
On Sat, 2015-01-10 at 14:13 -0800, Walter Bright via Digitalmars-d-announce
wrote:
 On 1/10/2015 1:28 PM, weaselcat wrote:
 Sorry for the off-topic noise, but where will you be publishing 
 your articles
 since Dr.Dobbs has closed?
 
 Sorry if you have answered this elsewhere.
It's a good question. Dr. Dobb's has graciously given me permission to republish them, and I'll post them on http://digitalmars.com/articles. As you can see, I've already done a few of them. Lots more to go.
Feel free to send stuff to ACCU's CVu or Overload. http://accu.org/index.php/journal -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jan 11 2015
parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/11/2015 4:24 AM, Russel Winder via Digitalmars-d-announce wrote:
 Feel free to send stuff to ACCU's CVu or Overload.

 http://accu.org/index.php/journal
Good idea!
Jan 11 2015
prev sibling next sibling parent reply "Vlad Levenfeld" <vlevenfeld gmail.com> writes:
For optimal AA lookup, this idiom is also nice if you only need 
the result for one line:

   if (auto found = key in AA)
     do_stuff (found);
Jan 14 2015
parent "ponce" <contact gam3sfrommars.fr> writes:
On Thursday, 15 January 2015 at 06:02:13 UTC, Vlad Levenfeld 
wrote:
 For optimal AA lookup, this idiom is also nice if you only need 
 the result for one line:

   if (auto found = key in AA)
     do_stuff (found);
Having a declaration in an "if" could be another entry together with: if (auto inst = cast(SubClass)myObject) do_stuff(inst); How to do "instanceof" is quite a common question on IRC.
Jan 15 2015
prev sibling parent Muhavare <muhavareslang gmail.com> writes:
For optimal AA lookup, this idiom is also nice if you only need 
the result for one line:

   if (auto found = key in AA)
     do_stuff (found);

http://idioms.in/
Mar 08 2016