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

alf*_*lfC 5 c++ filesystems header-files c++14

与 iostreams 具有前向包含标头#include<iosfwd>的方式相同,我认为 Filesystems 也有一个带有声明的标头。然而我找不到一个。

我有一个类声明了一个带有filesystem::path const&as 参数的成员函数,将整个函数带入#include<experimental/filesystem>get似乎有点矫枉过正path

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

Nic*_*las 3

有这样的标题吗?不。

你能制作这样的标题吗?另外,不。[namespace.std]/1 告诉我们:

如果 C++ 程序向命名空间std或命名空间内的命名空间添加声明或定义,则其行为是未定义的std,除非另有说明。

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