包括带有 clang 格式的转发标头的顺序
Include order of forward headers with clang-format
clang-formatIncludeIsMainRegex
来确定多个文件是否共享相同的主标头,以便将此#include
指令放在首位。足够整洁。
我几乎总是使用这种风格的前向声明标头:"entity_fwd.hpp"、"entity.hpp"和"entity.cpp"。此外,还有一个"entity_test.cpp",它应该使用"entity.hpp"标头。但是,"entity.hpp"应使用"entity_fwd.hpp"作为其主标题。
因此,我实际需要的是一种将其他标头指定为主文件的方法,而不是使用相同的主标头的其他源文件。
有没有人找到一种方法来使 clang 格式做到这一点?
编辑:好的,所以更多的背景。假设我有这个标题,称为entity_fwd.hpp
:
class Entity;
class Player;
class MOB;
bool collisionTest(Entity const & e1, Entity const & e2);
然后我有一个普通的定义标题,entity.hpp
:
#include "entity_fwd.hpp"
#include "world.hpp"
#include <vector>
class Entity {
public:
Entity(Entity const &) = delete;
virtual bool isAlive() const;
...
};
...
最后是一个实现文件,entity.cpp
:
#include "entity.hpp"
bool collisionTest(Entity const & e1, Entity const & e2) {
...
}
bool Entity::isAlive() const {
...
}
...
因为entity.cpp
clang-format知道entity.hpp
是该文件的主标头,基于标头文件名的词干;术语main header是clang-format的术语。主标题将放在包含列表中的第一个。
对于entity.hpp
,主标头应entity_fwd.hpp
。我可以将IncludeCategories
与正则表达式'_fwd.h(pp)?"$'
一起使用来首先对entity_fwd.hpp
进行排序,但这会将所有_fwd
个标头放在首位,只有entity_fwd.hpp
应该得到特殊处理。
最新的clang-format
文档显示了一个新的样式选项IncludeIsMainSourceRegex
,这似乎是您所需要的。这不是版本 10.0.0,因此您需要查找比该版本更新的clang-format
版本。
- CMake-按正确顺序将项目与C运行时对象文件链接
- 函数调用中参数的顺序重要吗
- 为什么不;名字在地图上是按顺序排列的吗
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 数到第n个楼梯的路(顺序无关紧要)
- 优先顺序:智能指针和类析构函数
- 在循环中按顺序遍历成员变量
- 独立读取-修改-写入顺序
- QML按钮点击功能执行顺序
- 正在折叠转发引用
- C++中数据类型修饰符的顺序
- 当比特(而不是字节)的顺序至关重要时的持久性
- C++从其他 constexpr 创建 lambda 不能按顺序执行 Constexpr
- 通过选项卡的文本设置QTabWidget顺序
- c++11评估顺序(未定义的行为)
- 如何在C++中递归地按相反顺序打印集合
- 给定顺序中的事件处理
- 具有包含其他对象的类的对象创建顺序
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- 包括带有 clang 格式的转发标头的顺序