为什么 std::experimental::filesystem::path 不接受像“*”这样的通配符?

Why does std::experimental::filesystem::path not accept wildcards like "*"?

#include <string>
#include <iostream>
#include <experimental/filesystem>

namespace fs = std::experimental::filesystem;

int main()
{
    fs::path p("/usr/include/c++/../sys/*");
    p = fs::canonical(p);
}

gcc 6.2.0 编译正常,但运行时错误显示:

terminate called after throwing an instance of 'std::experimental::filesystem::v1::__cxx11::filesystem_error'
what(): filesystem error: cannot canonicalize: No such file or directory [/usr/include/c++/../sys/*] [/data/svn/yaoxinliu] Aborted

为什么 std::experimental::filesystem::path 不接受像 *这样的通配符?

根据documentation

std::experimental::filesystem::canonical converts path p to a canonical absolute path, i.e. an absolute path that has no dot, dot-dot elements or symbolic links.

由于 std::experimental::filesystem::canonical 还必须取消引用路径中包含的符号链接,因此它只能接受现有文件或目录的路径。