3

I have the following code snippet, which is exactly like I want it:

#include <iostream>

int main(int argc, char* argv[])
{
    for (auto i: { 1, 2, 3 })
    {
        std::cout << i << std::endl;
    }
}

Unfortunately astyle turns this into:

#include <iostream>

int main(int argc, char* argv[])
{
    for (auto i :
            {
                1, 2, 3
            })
    {
        std::cout << i << std::endl;
    }
}

Is there any way I can make astyle treat initializer lists braces differently(i.e. ignore them)?

These are my current options:

--mode=c --style=allman --indent=spaces=4 -max-code-length=100 --attach-namespaces --pad-oper --pad-header
bgp2000
  • 1,070
  • 13
  • 32
  • is not my intent to preach one software or another, but have you considered using clang format instead? – bolov Sep 15 '16 at 11:47

1 Answers1

2

Just add option --keep-one-line-blocks so, all option are

--mode=c --style=allman --indent=spaces=4 --max-code-length=100 --attach-namespaces --pad-oper --pad-header --keep-one-line-blocks


#include <iostream>

int main( int argc, char* argv[] )
{
    for ( auto i : { 1, 2, 3 } )
    {
        std::cout << i << std::endl;
    }

    bool br = false;
    if ( true )
    {   br = true; cout << "Just test" << endl; }
}

However, you should be careful. After adding --keep-one-line-blocks option, astyle just keeps all one line blocks such as last line.

hyun
  • 2,135
  • 2
  • 18
  • 20