Updated readme with some fallback use-case help and adapted the tests to reflect parts of it.

This commit is contained in:
Steffen Schuemann 2018-09-22 13:37:04 +02:00
parent cf48497662
commit 90bab0edee
2 changed files with 28 additions and 17 deletions

View File

@ -45,7 +45,7 @@ if you can't use it.
Tests are currently run with: 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) * 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 * 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 into your project folder oder point your include path to this directory and
simply include the `filesystem.h` header. 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 ```cpp
#if defined(__cplusplus) && __cplusplus >= 201703L #if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) && __has_include(<filesystem>)
#include <filesystem> #include <filesystem>
namespace fs = std::filesystem; namespace fs = std::filesystem;
#else #else
@ -95,16 +96,26 @@ namespace fs = ghc::filesystem;
#endif #endif
``` ```
If you are paranoid you can add the feature tests of C++17 to ensure your compiler If you want to also use the `fstream` wrapper with `path` support as fallback,
already has std::filesystem when using `-std=c++17`: you might use:
```cpp ```cpp
#if defined(__has_include) && __has_include(<filesystem>) #if defined(__has_include) && __has_include(<filesystem>)
#include <filesystem> #include <filesystem>
namespace fs = std::filesystem; namespace fs {
using namespace std::filesystem;
using ifstream = std::ifstream;
using ofstream = std::ofstream;
using fstream = std::fstream;
}
#else #else
#include "filesystem.h" #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 #endif
``` ```

View File

@ -45,12 +45,12 @@
#ifdef USE_STD_FS #ifdef USE_STD_FS
#include <filesystem> #include <filesystem>
namespace fs = std::filesystem; namespace fs {
namespace ghc { using namespace std::filesystem;
using ifstream = std::ifstream; using ifstream = std::ifstream;
using ofstream = std::ofstream; using ofstream = std::ofstream;
using fstream = std::fstream; using fstream = std::fstream;
} // namespace ghc }
#ifdef __GNUC__ #ifdef __GNUC__
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif #endif
@ -63,12 +63,12 @@ using fstream = std::fstream;
#else #else
#define NOMINMAX #define NOMINMAX
#include "../filesystem.h" #include "../filesystem.h"
namespace fs = ghc::filesystem; namespace fs {
namespace ghc { using namespace ghc::filesystem;
using ifstream = filesystem::ifstream; using ifstream = ghc::filesystem::ifstream;
using ofstream = filesystem::ofstream; using ofstream = ghc::filesystem::ofstream;
using fstream = filesystem::fstream; using fstream = ghc::filesystem::fstream;
} // namespace ghc }
#endif #endif
#define CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN
@ -128,7 +128,7 @@ private:
static void generateFile(const fs::path& pathname, int withSize = -1) static void generateFile(const fs::path& pathname, int withSize = -1)
{ {
ghc::ofstream outfile(pathname.string()); fs::ofstream outfile(pathname.string());
if (withSize < 0) { if (withSize < 0) {
outfile << "Hello world!" << std::endl; outfile << "Hello world!" << std::endl;
} }