SlickEdit Community

Archived Beta Discussions => SlickEdit 201x Beta Discussions => SlickEdit 2018 v23 Beta Discussion => Topic started by: tchrismadden on September 27, 2018, 03:40:51 PM

Title: C++11 Brace Initializer Formatting
Post by: tchrismadden on September 27, 2018, 03:40:51 PM
When I attempt to use brace initializers the formatter usually treats it as a code block and expands it over two lines. This most often occurs when I create an unnamed object inline such as:

Code: [Select]
auto x = initializer{ bubba }.string();
Another common example is if I want to return a zero-initialized or default-constructed value from a function:

Code: [Select]
string fun( int v )
{
    if ( v > 0 )
        return std::to_string( v );
    else
        return {};
}

This occurs when I'm typing in code or in the beautifier (not surprisingly).


TCM
Title: Re: C++11 Brace Initializer Formatting
Post by: patrick on September 27, 2018, 04:05:48 PM
Reproduced, I'll look into what's happened.

In the meantime, a possible temporary workaround is to set the Languages->C/C++->Auto Close -> Brace setting to "On same line".  Typing "{" will put the closing brace on the same line like "{|}".  Hitting return will move the braces to where they would have been expanded with the "On next line" setting.  I like it for languages that use braced anonymous functions heavily, but definitely not to everyone's taste.
Title: Re: C++11 Brace Initializer Formatting
Post by: patrick on September 27, 2018, 05:07:04 PM
Which brace style does your beautifier profile tend to use for code?  '{' on the same line as the statement, on the next line after the statement, or on the next line after the statement with extra indent? 

From what I'm seeing here, I'm betting 'next line after statement', but want to double check to make sure I'm not on the wrong track.
Title: Re: C++11 Brace Initializer Formatting
Post by: patrick on September 28, 2018, 01:44:12 PM
The editing and beautifier issues will be fixed in the next beta.
Title: Re: C++11 Brace Initializer Formatting
Post by: tchrismadden on October 01, 2018, 06:30:36 PM
You're correct, I use next line (flush with statement). Sometimes the next line is honored, sometimes the opening brace is on the same line. I'm not sure what distinguishes the cases but I haven't had a chance to really explore that.