Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format opening braces in C++ methods with astyle?

Tags:

c++

astyle

Is a common practice to move function's opening brace to next line. How to apply this in class method with astyle (code beautifier)?

example:

// this is an initial C++ code
class Class
{
public:
    static int foo(bool x) {
        if (x) {
            return 42;
        } else {
            return 0;
        }
    }
};

modified version should be:

class Class
{
public:
    static int foo(bool x)
    { // this brace in next line
        if (x) {
            return 42;
        } else {
            return 0;
        }
    }
};

All my attempts working only for global functions.

like image 729
Kokos Avatar asked Nov 26 '22 11:11

Kokos


1 Answers

Both --style=kr / -A3 and --style=linux / -A8 option should apply to class methods as well.

From the docs:

Brackets are broken from namespace, class, and function definitions. Brackets are attached to statements within a function.

like image 114
gioele Avatar answered Dec 09 '22 15:12

gioele