updating readme and dynamic selection examples

This commit is contained in:
Steffen Schuemann 2020-11-15 21:12:41 +01:00
parent 809d680df9
commit 427108c8e2
5 changed files with 48 additions and 19 deletions

View File

@ -122,8 +122,8 @@ Everything is in the namespace `ghc::filesystem`, so one way to use it only as
a fallback could be: a fallback could be:
```cpp ```cpp
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
#if __has_include(<filesystem>) #if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
#define GHC_USE_STD_FS #define GHC_USE_STD_FS
#include <filesystem> #include <filesystem>
namespace fs = std::filesystem; namespace fs = std::filesystem;
@ -136,18 +136,22 @@ namespace fs = ghc::filesystem;
``` ```
**Note that this code uses a two-stage preprocessor condition because Visual Studio 2015 **Note that this code uses a two-stage preprocessor condition because Visual Studio 2015
doesn't like the `(<...>)` syntax, even if it could cut evaluation early before.** doesn't like the `(<...>)` syntax, even if it could cut evaluation early before. This code also
used the minimum deployment target to detect if std::filesystem really is available on macOS
compilation.**
**Note also, that on MSVC this detection only works starting from version 15.7 on and when setting **Note also, this detection now works on MSVC versions prior to 15.7 on, or without setting
the `/Zc:__cplusplus` compile switch, as the compiler allways reports `199711L` the `/Zc:__cplusplus` compile switch that would fix `__cplusplus` on MSVC. (Without the switch
without that switch ([see](https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/)).** the compiler allways reports `199711L`
([see](https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/)),
but `_MSVC_LANG` works without it.**
If you want to also use the `fstream` wrapper with `path` support as fallback, If you want to also use the `fstream` wrapper with `path` support as fallback,
you might use: you might use:
```cpp ```cpp
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
#if __has_include(<filesystem>) #if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
#define GHC_USE_STD_FS #define GHC_USE_STD_FS
#include <filesystem> #include <filesystem>
namespace fs { namespace fs {
@ -201,8 +205,8 @@ If you use the forwarding/implementation approach, you can still use the dynamic
switching like this: switching like this:
```cpp ```cpp
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
#if __has_include(<filesystem>) #if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
#define GHC_USE_STD_FS #define GHC_USE_STD_FS
#include <filesystem> #include <filesystem>
namespace fs { namespace fs {
@ -228,11 +232,15 @@ and in the implementation hiding cpp, you might use (before any include that inc
to take precedence: to take precedence:
```cpp ```cpp
#if !(defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
#if __has_include(<filesystem>)) #if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
#include <ghc/fs_impl.hpp> #define GHC_USE_STD_FS
#endif #endif
#endif #endif
#ifndef GHC_USE_STD_FS
#define GHC_FILESYSTEM_IMPLEMENTATION
#include <ghc/filesystem.hpp>
#endif
``` ```
:information_source: **Hint:** There are additional helper headers, named `ghc/fs_std_fwd.hpp` and :information_source: **Hint:** There are additional helper headers, named `ghc/fs_std_fwd.hpp` and
@ -498,6 +506,22 @@ to the expected behavior.
## Release Notes ## Release Notes
### [v1.3.8](https://github.com/gulrak/filesystem/releases/tag/v1.3.8)
* Refactoring for [#78](https://github.com/gulrak/filesystem/issues/78), the dynamic
switching helper includes are now using `__MAC_OS_X_VERSION_MIN_REQUIRED` to
ensure that `std::filesystem` is only selected on macOS if the deployment target is
at least Catalina.
* Bugfix for [#77](https://github.com/gulrak/filesystem/issues/77), the `directory_iterator`
and the `recursive_directory_iterator` had an issue with the `skip_permission_denied`
option, that leads to the inability to skip SIP protected folders on macOS.
* Enhancement for [#76](https://github.com/gulrak/filesystem/issues/76), `_MSVC_LANG` is
now used when available, additionally to `__cplusplus`, in the helping headers to
allow them to work even when `/Zc:__cplusplus` is not used.
* Bugfix for [#75](https://github.com/gulrak/filesystem/issues/75), NTFS reparse points
to mapped volumes where handled incorrect, leading to `false` on `fs::exists` or
not-found-errors on `fs::status`. Namespaced paths are not filtered anymore.
### [v1.3.6](https://github.com/gulrak/filesystem/releases/tag/v1.3.6) ### [v1.3.6](https://github.com/gulrak/filesystem/releases/tag/v1.3.6)
* Pull request [#74](https://github.com/gulrak/filesystem/pull/74), on Windows symlink * Pull request [#74](https://github.com/gulrak/filesystem/pull/74), on Windows symlink

View File

@ -26,12 +26,17 @@
// //
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// //
// To dynamically select std::filesystem where available, you could use: // To dynamically select std::filesystem where available on most platforms,
// you could use:
// //
// #if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) && __has_include(<filesystem>) // #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
// #if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
// #define GHC_USE_STD_FS
// #include <filesystem> // #include <filesystem>
// namespace fs = std::filesystem; // namespace fs = std::filesystem;
// #else // #endif
// #endif
// #ifndef GHC_USE_STD_FS
// #include <ghc/filesystem.hpp> // #include <ghc/filesystem.hpp>
// namespace fs = ghc::filesystem; // namespace fs = ghc::filesystem;
// #endif // #endif

View File

@ -30,7 +30,7 @@
// namespace fs. // namespace fs.
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
#ifndef GHC_FILESYSTEM_STD_H #ifndef GHC_FILESYSTEM_STD_H
#if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L) && defined(__has_include) #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
#if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) #if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
#define GHC_USE_STD_FS #define GHC_USE_STD_FS
#include <filesystem> #include <filesystem>

View File

@ -33,7 +33,7 @@
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
#ifndef GHC_FILESYSTEM_STD_FWD_H #ifndef GHC_FILESYSTEM_STD_FWD_H
#define GHC_FILESYSTEM_STD_FWD_H #define GHC_FILESYSTEM_STD_FWD_H
#if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L) && defined(__has_include) #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
#if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) #if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
#define GHC_USE_STD_FS #define GHC_USE_STD_FS
#include <filesystem> #include <filesystem>

View File

@ -31,7 +31,7 @@
// The cpp has to include this before including fs_std_fwd.hpp directly or via a different // The cpp has to include this before including fs_std_fwd.hpp directly or via a different
// header to work. // header to work.
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
#if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L) && defined(__has_include) #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
#if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) #if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
#define GHC_USE_STD_FS #define GHC_USE_STD_FS
#endif #endif