Skip to content

Commit 3a8cd29

Browse files
committed
Add several methods that are not in this repo but in STL.
1 parent f45da75 commit 3a8cd29

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

filesystem/path.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ class path {
225225
return oss.str();
226226
}
227227

228+
std::string string() const {
229+
return str();
230+
}
231+
228232
void set(const std::string &str, path_type type = native_path) {
229233
m_type = type;
230234
if (type == windows_path) {
@@ -431,4 +435,12 @@ inline bool create_directories(const path& p) {
431435
#endif
432436
}
433437

438+
inline bool exists(const path& p) {
439+
return p.exists();
440+
}
441+
442+
inline bool is_directory(const path& p) {
443+
return p.is_directory();
444+
}
445+
434446
NAMESPACE_END(filesystem)

path_demo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ int main(int argc, char **argv) {
2525
cout << "some/path.ext:operator==() (unequal) = " << (path("some/path.ext") == path("another/path.ext")) << endl;
2626

2727
cout << "nonexistant:exists = " << path("nonexistant").exists() << endl;
28+
cout << "nonexistant:exists = " << exists(path("nonexistant")) << endl;
2829
cout << "nonexistant:is_file = " << path("nonexistant").is_file() << endl;
2930
cout << "nonexistant:is_directory = " << path("nonexistant").is_directory() << endl;
3031
cout << "nonexistant:filename = " << path("nonexistant").filename() << endl;
3132
cout << "nonexistant:extension = " << path("nonexistant").extension() << endl;
3233
cout << "filesystem/path.h:exists = " << path("filesystem/path.h").exists() << endl;
34+
cout << "filesystem/path.h:exists = " << exists(path("filesystem/path.h")) << endl;
3335
cout << "filesystem/path.h:is_file = " << path("filesystem/path.h").is_file() << endl;
3436
cout << "filesystem/path.h:is_directory = " << path("filesystem/path.h").is_directory() << endl;
3537
cout << "filesystem/path.h:filename = " << path("filesystem/path.h").filename() << endl;
3638
cout << "filesystem/path.h:extension = " << path("filesystem/path.h").extension() << endl;
3739
cout << "filesystem/path.h:make_absolute = " << path("filesystem/path.h").make_absolute() << endl;
3840
cout << "../filesystem:exists = " << path("../filesystem").exists() << endl;
41+
cout << "../filesystem:exists = " << exists(path("../filesystem")) << endl;
3942
cout << "../filesystem:is_file = " << path("../filesystem").is_file() << endl;
4043
cout << "../filesystem:is_directory = " << path("../filesystem").is_directory() << endl;
4144
cout << "../filesystem:extension = " << path("../filesystem").extension() << endl;

0 commit comments

Comments
 (0)