有没有办法为 std::filesystem 包含前向 headers?

Is there a way to include forward headers for std::filesystem?

与 iostreams 具有仅带有声明的 forward-include header #include<iosfwd> a header 相同的方式,我假设文件系统也会有一个。但是我找不到。

我有一个 class 声明了一个以 filesystem::path const& 作为参数的成员函数,并且为了获得 path 而引入整个 #include<experimental/filesystem> 似乎有点矫枉过正.

#include<experimental/filsystem_fwd> // or #include<experimental/filesystem/path/*only*/>
...
struct A{
  ...
  void save(std::experimental::filesystem::path const& p);
}

有这样的header吗?号

你能做出这样的header吗?还有,不。 [namespace.std]/1 tells us:

The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std unless otherwise specified.

由于 std 命名空间事物的任何前向声明都必须是 std 命名空间的一部分,因此您不能那样做。您可以编写模板特化,并且在某些情况下您可以戳 std 本身。但是声明 std::filesystem::* 不是你能做的。