C++17 is feature complete

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 27 08:16:19 PDT 2016


On Monday, 27 June 2016 at 14:57:10 UTC, Patrick Schluter wrote:
> I forgot. No it's not more readable, to the contrary. The issue 
> is that normally { } introduces an indentation, which is always 
> associated with some kind of branching. Adding an indentation 
> just for the declaration of a variable is an inconsistency 
> annoying to read. I had the case several times in the code I 
> was transforming and it had me each time puzzled at where the 
> loop or condition was.

I see your point, but I like to keep conditional clean. Usually 
the expression is long when  I have to check an error code in 
C++. I don't think the following is easy on my eyes and it is not 
at all clear where the destructor is called:

if ( auto file = 
::tool::filesystem::open("/path/to/somewhere/xx"); file != 
nullptr) {
    ...
}  else if(…) {
     ...
} else {
     ...
}

I think this is easier to read, and the location for the 
destruction is obvious:

{
     auto file = ::tool::filesystem::open("/path/to/somewhere/xx");

     if ( file != nullptr ) {
        ...
     }  else if(…) {
        ...
     } else {
        ...
     }
}

In modern C++ one has to think about introducing scopes to gain 
control over where RAII is created and destructed.



More information about the Digitalmars-d mailing list