- filesystem[meta header]
- std::filesystem[meta namespace]
- path[meta class]
- function[meta id-type]
- cpp17[meta cpp]
bool is_relative() const;パスが相対パスかを判定する。
return !is_absolute();- is_absolute()[link is_absolute.md]
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path ps[] = {
"/", // ルートパスのみ
"/foo/bar.txt", // ルートパスを含む
"/foo/../bar.txt", // ルートパスに加えて、親ディレクトリの参照を含む
"foo/bar.txt" // ルートパスを含まない
};
std::cout << std::boolalpha;
for (const fs::path& p : ps) {
std::cout << p << " : " << p.is_relative() << std::endl;
}
}- is_relative()[color ff0000]
"/" : false
"/foo/bar.txt" : false
"/foo/../bar.txt" : false
"foo/bar.txt" : true
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path ps[] = {
"C:", // ルート名のみ
"C:/", // ルートパスのみ
"C:/foo/bar.txt", // ルートパスを含む
"C:/foo/../bar.txt", // ルートパスに加えて、親ディレクトリの参照を含む
"foo/bar.txt", // ルートパスを含まない
"C:foo", // ルート名はあるがルートディレクトリはない
"/foo" // ルートディレクトリはあるがルート名はない
};
std::cout << std::boolalpha;
for (const fs::path& p : ps) {
std::cout << p << " : " << p.is_relative() << std::endl;
}
}- is_relative()[color ff0000]
"C:" : true
"C:/" : false
"C:/foo/bar.txt" : false
"C:/foo/../bar.txt" : false
"foo/bar.txt" : true
"C:foo" : true
"/foo" : true
- C++17
- Clang:
- GCC: 8.1
- Visual C++: 2017 Update 7