From 90bab0edee716045ab47c492837c1ecf0ab3e31c Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Sat, 22 Sep 2018 13:37:04 +0200 Subject: [PATCH] Updated readme with some fallback use-case help and adapted the tests to reflect parts of it. --- README.md | 25 ++++++++++++++++++------- test/filesystem_test.cpp | 20 ++++++++++---------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e892f8d..4b75fa3 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ if you can't use it. Tests are currently run with: * macOS 10.12: XCode 9.2 (clang-900.0.39.2), GCC 8.1.0, Clang 8.0.0 (HEAD, homebrew) -* Windows 10: Visual Studio 2017 15.7.4, MingW GCC 5.3 +* Windows 10: Visual Studio 2017 15.8.5, MingW GCC 5.3 * Linux: Ubuntu 18.04LTS GCC 7.3 & GCC 8.0.1 @@ -83,10 +83,11 @@ As it is a header-only library, it should be enough to copy the header into your project folder oder point your include path to this directory and simply include the `filesystem.h` header. -Everything is in the namespace `ghc::filesystem`, so one way to use it could be: +Everything is in the namespace `ghc::filesystem`, so one way to use it only as +a fallback could be: ```cpp -#if defined(__cplusplus) && __cplusplus >= 201703L +#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) && __has_include() #include namespace fs = std::filesystem; #else @@ -95,16 +96,26 @@ namespace fs = ghc::filesystem; #endif ``` -If you are paranoid you can add the feature tests of C++17 to ensure your compiler -already has std::filesystem when using `-std=c++17`: +If you want to also use the `fstream` wrapper with `path` support as fallback, +you might use: ```cpp #if defined(__has_include) && __has_include() #include -namespace fs = std::filesystem; +namespace fs { +using namespace std::filesystem; +using ifstream = std::ifstream; +using ofstream = std::ofstream; +using fstream = std::fstream; +} #else #include "filesystem.h" -namespace fs = ghc::filesystem; +namespace fs { +using namespace ghc::filesystem; +using ifstream = ghc::filesystem::ifstream; +using ofstream = ghc::filesystem::ofstream; +using fstream = ghc::filesystem::fstream; +} #endif ``` diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index dd3ca05..47765e0 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -45,12 +45,12 @@ #ifdef USE_STD_FS #include -namespace fs = std::filesystem; -namespace ghc { +namespace fs { +using namespace std::filesystem; using ifstream = std::ifstream; using ofstream = std::ofstream; using fstream = std::fstream; -} // namespace ghc +} #ifdef __GNUC__ #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #endif @@ -63,12 +63,12 @@ using fstream = std::fstream; #else #define NOMINMAX #include "../filesystem.h" -namespace fs = ghc::filesystem; -namespace ghc { -using ifstream = filesystem::ifstream; -using ofstream = filesystem::ofstream; -using fstream = filesystem::fstream; -} // namespace ghc +namespace fs { +using namespace ghc::filesystem; +using ifstream = ghc::filesystem::ifstream; +using ofstream = ghc::filesystem::ofstream; +using fstream = ghc::filesystem::fstream; +} #endif #define CATCH_CONFIG_MAIN @@ -128,7 +128,7 @@ private: static void generateFile(const fs::path& pathname, int withSize = -1) { - ghc::ofstream outfile(pathname.string()); + fs::ofstream outfile(pathname.string()); if (withSize < 0) { outfile << "Hello world!" << std::endl; }