仅在漂亮打印时坚持使用 2 种布局

Stick with 2 layouts only when pretty printing

我正在打印一个 C++ 方法声明,我希望参数列表以紧凑的形式呈现,如果它符合以下行:

void method(MyLongClassName& instance, const MyClass& c);

或者如果不是,则在列中进行格式化:

void method(      MyLongClassName& instance,
            const MyClass&         c,
                  int              counter);

我想从考虑中排除的所有其他布局。 如果不破解源代码,wl-pprint nor with pretty 似乎也不简单。

有什么想法吗?

如何选择适合单行的布局的更一般问题的解决方案,或者,如果 none,可以在此处找到替代方案: