boost::hana 前向声明 headers 的用例是什么?
What is the use case of boost::hana forward declaration headers?
大部分 hana headers 还包括子文件夹 fwd
中包含的前向声明 headers,例如#include<boost/hana/fwd/pair.hpp
。
AFAIK 前向声明 headers 声明事物而不是定义它们,因此用户可以限制访问 指针 (和引用)函数和 objects.
boost::hana
是 header-only 模板库,这有什么意义?我唯一想到的是,如果您不打算实例化声明的模板,那么前向声明就足够了,但是 - 首先使用它们有什么意义?
通过查看库源代码,我觉得它非常聪明,但我仍然不理解。
假设我只需要 boost::hana
模板的非常具体的实例。如果我在一个翻译单元中定义 并实例化 它们,并使用前向声明从所有其他单元向它们 link 定义它们,它会起作用吗?
手册中有一些关于此的信息here:
This subdirectory contains the forward declaration of everything in
the
library. It is essentially a mirror of the boost/hana/
directory, except
all the headers contain only forward declarations and documentation. For
example, to include the hana::tuple
container, one can use the
boost/hana/tuple.hpp
header. However, if one only wants the
forward declaration of that container, the boost/hana/fwd/tuple.hpp
header can be used instead. Note that forward declarations for headers
in boost/hana/ext/
and boost/hana/functional/
are not provided.
也来自与作者的讨论here:
The rationale is so that we can #include lightweight declarations
instead of full blown definitions when only a declaration is requried.
This can help with compile times. Also, it’s necessary for some
circularly-dependent stuff.
和:
And finally, I think it makes for a nice separation between interface
and implementation, and also it gives a place to systematically put
documentation. Since the implementation is sometimes hairy, I think
it’s nice not to entangle the documentation with it.
这是马口径来。我发现非常有必要将整个 chicken/egg 问题的实现与循环依赖分开。这是我在自己的项目中采用的一种干净的方式。
大部分 hana headers 还包括子文件夹 fwd
中包含的前向声明 headers,例如#include<boost/hana/fwd/pair.hpp
。
AFAIK 前向声明 headers 声明事物而不是定义它们,因此用户可以限制访问 指针 (和引用)函数和 objects.
boost::hana
是 header-only 模板库,这有什么意义?我唯一想到的是,如果您不打算实例化声明的模板,那么前向声明就足够了,但是 - 首先使用它们有什么意义?
通过查看库源代码,我觉得它非常聪明,但我仍然不理解。
假设我只需要 boost::hana
模板的非常具体的实例。如果我在一个翻译单元中定义 并实例化 它们,并使用前向声明从所有其他单元向它们 link 定义它们,它会起作用吗?
手册中有一些关于此的信息here:
This subdirectory contains the forward declaration of everything in the library. It is essentially a mirror of the
boost/hana/
directory, except all the headers contain only forward declarations and documentation. For example, to include thehana::tuple
container, one can use theboost/hana/tuple.hpp
header. However, if one only wants the forward declaration of that container, theboost/hana/fwd/tuple.hpp
header can be used instead. Note that forward declarations for headers inboost/hana/ext/
andboost/hana/functional/
are not provided.
也来自与作者的讨论here:
The rationale is so that we can #include lightweight declarations instead of full blown definitions when only a declaration is requried. This can help with compile times. Also, it’s necessary for some circularly-dependent stuff.
和:
And finally, I think it makes for a nice separation between interface and implementation, and also it gives a place to systematically put documentation. Since the implementation is sometimes hairy, I think it’s nice not to entangle the documentation with it.
这是马口径来。我发现非常有必要将整个 chicken/egg 问题的实现与循环依赖分开。这是我在自己的项目中采用的一种干净的方式。