Skip to content

Commit

Permalink
Add macro for filesystem.
Browse files Browse the repository at this point in the history
Filesystem wasn't introduced until C++17, so including the library is
dodgy for different C++ versions, compiler and OSs. This should help,
but may be incomplete.
  • Loading branch information
jeannielynnmoulton committed Jul 18, 2024
1 parent f12f2b7 commit 446f6fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/Scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
#include <sstream>
#include <string>
#include <sys/stat.h>
#ifdef __APPLE__
namespace fs = std::__fs::filesystem;
#else
namespace fs = std::experimental::filesystem;
#endif
#include "filesystem.hpp"

bool IsPathExist(const std::string &s) {
struct stat buffer;
Expand Down
11 changes: 11 additions & 0 deletions src/filesystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This is a workaround for the filesystem library to work for different OSs/compiler and C++ versions
#ifdef __cpp_lib_filesystem // C++17
#include <filesystem>
namespace fs = std::filesystem;
#elif __cpp_lib_experimental_filesystem // C++11
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else // MacOS C++11
#include <filesystem>
namespace fs = std::__fs::filesystem;
#endif

0 comments on commit 446f6fb

Please sign in to comment.