I like to define my array values with a designator, when possible:
enum Mode {
NONE,
SPLIT_FILES,
SINGLE_FILE,
INVALID
};
const std::string ModeName[] = {
[NONE] = "NONE",
[SPLIT_FILES] = "SPLIT_FILES",
[SINGLE_FILE] = "SINGLE_FILE",
[INVALID] = "INVALID"
};
Running this through clang-format
(3.5) mangles the new lines and makes it less readable:
enum RecorderMode { REC_NONE, REC_SPLIT_FILES, REC_SINGLE_FILE, REC_INVALID };
const std::string RecorderModeName[]
= {[REC_NONE] = "NONE", [REC_SPLIT_FILES] = "SPLIT_FILES", [REC_SINGLE_FILE] = "SINGLE_FILE",
[REC_INVALID] = "INVALID" };
The array definition has several problems: = {
is moved to the next line. If I add a comma after the last array entry, the rows are indented twice.
Is there a way to keep the new lines and indentation, short of using the clang-format turn off comment?
This shows a work-around for the enum
(add a comma after the last constant, or add a trailing comment after a comma), but it doesn't seem to apply to the array.