C++17 is feature complete

Patrick Schluter via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 27 07:47:51 PDT 2016


On Monday, 27 June 2016 at 06:52:58 UTC, Ola Fosheim Grøstad 
wrote:
> On Monday, 27 June 2016 at 03:09:46 UTC, Meta wrote:
>> On Sunday, 26 June 2016 at 22:32:55 UTC, Walter Bright wrote:
>>> On 6/26/2016 10:18 AM, Enamex wrote:
>>>>   - template arguments that accept constant values of any 
>>>> type whatsoever
>>>> 'template<auto Arg>';
>>>
>>> Still adding D features, I see!
>>
>> Imitation is the sincerest form of flattery, so when is 
>> destructuring coming to D?
>>
>> Also, the `if (init; condition) and switch (init; condition)` 
>> seems like a very nice idea.
>
> It's from Go,  I don't see much value in it. You can just wrap 
> the if in a block:
>
> {
>   init;
>   if(condition)…
> }
>
> That is usually more readable IMO.

No, it's the logical conclusion from the for(init; condition; 
increment) loop and the declare a variable anywhere feature, 
introduced in C++ long time ago.

It's funny that C++ now will introduce it, as I had the same idea 
a couple of weeks ago for C. I'm currently in the process of 
transforming old legacy C code that had all their variables 
declared at the top, to a more modern style, using C99 feature 
taken from C++, i.e. vars only declared and initialized when they 
are used and using for(initdeclaration;...) style.
It appeared quite rapidly that in a lot of cases the if(init; and 
switch(init; would have been nice as it would have brought a lot 
of regularity in the code and it allows to limit the scope of a 
temporary variable really to the section it is used in without 
overloading the code with { and }.

btw: I was first quite skeptical of the gain to be had of that 
scope reduction transformation, but after discovering several 
serious bugs in our code because of scope errors, I am now 
transforming more systematically to that style our 200K lines of 
C code.


More information about the Digitalmars-d mailing list