Author Topic: C++11 Brace Initializer Formatting  (Read 2073 times)

tchrismadden

  • Junior Community Member
  • Posts: 3
  • Hero Points: 1
C++11 Brace Initializer Formatting
« 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

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: C++11 Brace Initializer Formatting
« Reply #1 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.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: C++11 Brace Initializer Formatting
« Reply #2 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.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: C++11 Brace Initializer Formatting
« Reply #3 on: September 28, 2018, 01:44:12 PM »
The editing and beautifier issues will be fixed in the next beta.

tchrismadden

  • Junior Community Member
  • Posts: 3
  • Hero Points: 1
Re: C++11 Brace Initializer Formatting
« Reply #4 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.