From aaaf381d9d02be832df7182e35ac7260d735d004 Mon Sep 17 00:00:00 2001 From: Chris Sauer Date: Wed, 26 Jul 2023 21:26:33 -0700 Subject: [PATCH 1/5] Improvements to preprocessor conditions for falling back to std::filesystem - Supports more Apple platforms, including future ones, which will always support std::filesystem, like with visionOS - Simplifies cases. Undefined preprocessor values are guaranteed to default evaluate to 0 - Moves include inside conditional, avoiding the include where not needed. - Removes reference to wchar for std headers on windows, which seemed to be out of date, since the define it might have been referring to was commented - (And some other small things.) --- README.md | 213 ++++++++++++++++++++++-------------- include/ghc/fs_std.hpp | 69 +++++++----- include/ghc/fs_std_fwd.hpp | 70 +++++++----- include/ghc/fs_std_impl.hpp | 34 ++++-- 4 files changed, 243 insertions(+), 143 deletions(-) diff --git a/README.md b/README.md index 62b9d5a..59cb32d 100644 --- a/README.md +++ b/README.md @@ -176,60 +176,83 @@ Everything is in the namespace `ghc::filesystem`, so one way to use it only as a fallback could be: ```cpp -#ifdef __APPLE__ -#include // for deployment target to support pre-catalina targets without std::fs +#if _MSVC_LANG >= 201703L || __cplusplus >= 201703L && defined(__has_include) + // ^ Supports MSVC prior to 15.7 without setting /Zc:__cplusplus to fix __cplusplus + // _MSVC_LANG works regardless. But without the switch, the compiler always reported 199711L: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/ + #if __has_include() // Two stage __has_include needed for MSVC 2015 and per https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html + #define GHC_USE_STD_FS + + // Old Apple OSs don't support std::filesystem, though the header is available at compile + // time. In particular, std::filesystem is unavailable before macOS 10.15, iOS/tvOS 13.0, + // and watchOS 6.0. + #ifdef __APPLE__ + #include + // Note: This intentionally uses std::filesystem on any new Apple OS, like visionOS + // released after std::filesystem, where std::filesystem is always available. + // (All other ___VERSION_MIN_REQUIREDs will be undefined and thus 0.) + #if __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 \ + || __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 \ + || __TV_OS_VERSION_MIN_REQUIRED && __TV_OS_VERSION_MIN_REQUIRED < 130000 \ + || __WATCH_OS_VERSION_MAX_ALLOWED && __WATCH_OS_VERSION_MAX_ALLOWED < 60000 + #undef GHC_USE_STD_FS + #endif + #endif + #endif #endif -#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) -#if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) -#define GHC_USE_STD_FS -#include -namespace fs = std::filesystem; -#endif -#endif -#ifndef GHC_USE_STD_FS -#include -namespace fs = ghc::filesystem; + +#ifdef GHC_USE_STD_FS + #include + namespace fs = std::filesystem; +#else + #include + namespace fs = ghc::filesystem; #endif ``` -**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. This code also -used the minimum deployment target to detect if `std::filesystem` really is available on macOS -compilation.** - -**Note also, this detection now works on MSVC versions prior to 15.7 on, or without setting -the `/Zc:__cplusplus` compile switch that would fix `__cplusplus` on MSVC. (Without the switch -the compiler always 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, you might use: ```cpp -#ifdef __APPLE__ -#include // for deployment target to support pre-catalina targets without std::fs +#if _MSVC_LANG >= 201703L || __cplusplus >= 201703L && defined(__has_include) + // ^ Supports MSVC prior to 15.7 without setting /Zc:__cplusplus to fix __cplusplus + // _MSVC_LANG works regardless. But without the switch, the compiler always reported 199711L: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/ + #if __has_include() // Two stage __has_include needed for MSVC 2015 and per https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html + #define GHC_USE_STD_FS + + // Old Apple OSs don't support std::filesystem, though the header is available at compile + // time. In particular, std::filesystem is unavailable before macOS 10.15, iOS/tvOS 13.0, + // and watchOS 6.0. + #ifdef __APPLE__ + #include + // Note: This intentionally uses std::filesystem on any new Apple OS, like visionOS + // released after std::filesystem, where std::filesystem is always available. + // (All other ___VERSION_MIN_REQUIREDs will be undefined and thus 0.) + #if __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 \ + || __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 \ + || __TV_OS_VERSION_MIN_REQUIRED && __TV_OS_VERSION_MIN_REQUIRED < 130000 \ + || __WATCH_OS_VERSION_MAX_ALLOWED && __WATCH_OS_VERSION_MAX_ALLOWED < 60000 + #undef GHC_USE_STD_FS + #endif + #endif + #endif #endif -#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) -#if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) -#define GHC_USE_STD_FS -#include -namespace fs { -using namespace std::filesystem; -using ifstream = std::ifstream; -using ofstream = std::ofstream; -using fstream = std::fstream; -} -#endif -#endif -#ifndef GHC_USE_STD_FS -#include -namespace fs { -using namespace ghc::filesystem; -using ifstream = ghc::filesystem::ifstream; -using ofstream = ghc::filesystem::ofstream; -using fstream = ghc::filesystem::fstream; -} + +#ifdef GHC_USE_STD_FS + #include + namespace fs { + using namespace std::filesystem; + using ifstream = std::ifstream; + using ofstream = std::ofstream; + using fstream = std::fstream; + } +#else + #include + namespace fs { + using namespace ghc::filesystem; + using ifstream = ghc::filesystem::ifstream; + using ofstream = ghc::filesystem::ofstream; + using fstream = ghc::filesystem::fstream; + } #endif ``` @@ -269,29 +292,46 @@ If you use the forwarding/implementation approach, you can still use the dynamic switching like this: ```cpp -#ifdef __APPLE__ -#include // for deployment target to support pre-catalina targets without std::fs +#if _MSVC_LANG >= 201703L || __cplusplus >= 201703L && defined(__has_include) + // ^ Supports MSVC prior to 15.7 without setting /Zc:__cplusplus to fix __cplusplus + // _MSVC_LANG works regardless. But without the switch, the compiler always reported 199711L: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/ + #if __has_include() // Two stage __has_include needed for MSVC 2015 and per https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html + #define GHC_USE_STD_FS + + // Old Apple OSs don't support std::filesystem, though the header is available at compile + // time. In particular, std::filesystem is unavailable before macOS 10.15, iOS/tvOS 13.0, + // and watchOS 6.0. + #ifdef __APPLE__ + #include + // Note: This intentionally uses std::filesystem on any new Apple OS, like visionOS + // released after std::filesystem, where std::filesystem is always available. + // (All other ___VERSION_MIN_REQUIREDs will be undefined and thus 0.) + #if __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 \ + || __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 \ + || __TV_OS_VERSION_MIN_REQUIRED && __TV_OS_VERSION_MIN_REQUIRED < 130000 \ + || __WATCH_OS_VERSION_MAX_ALLOWED && __WATCH_OS_VERSION_MAX_ALLOWED < 60000 + #undef GHC_USE_STD_FS + #endif + #endif + #endif #endif -#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) -#if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) -#define GHC_USE_STD_FS -#include -namespace fs { -using namespace std::filesystem; -using ifstream = std::ifstream; -using ofstream = std::ofstream; -using fstream = std::fstream; -} -#endif -#endif -#ifndef GHC_USE_STD_FS -#include -namespace fs { -using namespace ghc::filesystem; -using ifstream = ghc::filesystem::ifstream; -using ofstream = ghc::filesystem::ofstream; -using fstream = ghc::filesystem::fstream; -} + +#ifdef GHC_USE_STD_FS + #include + namespace fs { + using namespace std::filesystem; + using ifstream = std::ifstream; + using ofstream = std::ofstream; + using fstream = std::fstream; + } +#else + #include + namespace fs { + using namespace ghc::filesystem; + using ifstream = ghc::filesystem::ifstream; + using ofstream = ghc::filesystem::ofstream; + using fstream = ghc::filesystem::fstream; + } #endif ``` @@ -299,25 +339,38 @@ and in the implementation hiding cpp, you might use (before any include that inc to take precedence: ```cpp -#ifdef __APPLE__ // for deployment target to support pre-catalina targets without std::fs -#include -#endif -#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) -#if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) -#define GHC_USE_STD_FS -#endif +#if _MSVC_LANG >= 201703L || __cplusplus >= 201703L && defined(__has_include) + // ^ Supports MSVC prior to 15.7 without setting /Zc:__cplusplus to fix __cplusplus + // _MSVC_LANG works regardless. But without the switch, the compiler always reported 199711L: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/ + #if __has_include() // Two stage __has_include needed for MSVC 2015 and per https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html + #define GHC_USE_STD_FS + + // Old Apple OSs don't support std::filesystem, though the header is available at compile + // time. In particular, std::filesystem is unavailable before macOS 10.15, iOS/tvOS 13.0, + // and watchOS 6.0. + #ifdef __APPLE__ + #include + // Note: This intentionally uses std::filesystem on any new Apple OS, like visionOS + // released after std::filesystem, where std::filesystem is always available. + // (All other ___VERSION_MIN_REQUIREDs will be undefined and thus 0.) + #if __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 \ + || __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 \ + || __TV_OS_VERSION_MIN_REQUIRED && __TV_OS_VERSION_MIN_REQUIRED < 130000 \ + || __WATCH_OS_VERSION_MAX_ALLOWED && __WATCH_OS_VERSION_MAX_ALLOWED < 60000 + #undef GHC_USE_STD_FS + #endif + #endif + #endif #endif + #ifndef GHC_USE_STD_FS -#define GHC_FILESYSTEM_IMPLEMENTATION -#include + #include #endif ``` :information_source: **Hint:** There are additional helper headers, named `ghc/fs_std_fwd.hpp` and `ghc/fs_std_impl.hpp` that use this technique, so you can simply include them -if you want to dynamically select the filesystem implementation. they also -enable the `wchar_t` support on `ghc::filesystem` on Windows, so the resulting -implementation in the `fs` namespace will be compatible. +if you want to dynamically select the filesystem implementation. @@ -409,7 +462,7 @@ int main(int argc, char* argv[]) exit(EXIT_FAILURE); } - // now use argc/argv as usual, they have utf-8 enconding on windows + // now use argc/argv as usual, they have utf-8 encoding on windows // ... return 0; diff --git a/include/ghc/fs_std.hpp b/include/ghc/fs_std.hpp index c9492fd..f188e57 100644 --- a/include/ghc/fs_std.hpp +++ b/include/ghc/fs_std.hpp @@ -31,30 +31,47 @@ //--------------------------------------------------------------------------------------- #ifndef GHC_FILESYSTEM_STD_H #define GHC_FILESYSTEM_STD_H -#if defined(__APPLE__) -#include -#endif -#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) -#if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) -#define GHC_USE_STD_FS -#include -namespace fs { -using namespace std::filesystem; -using ifstream = std::ifstream; -using ofstream = std::ofstream; -using fstream = std::fstream; -} -#endif -#endif -#ifndef GHC_USE_STD_FS -//#define GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE -#include -namespace fs { -using namespace ghc::filesystem; -using ifstream = ghc::filesystem::ifstream; -using ofstream = ghc::filesystem::ofstream; -using fstream = ghc::filesystem::fstream; -} -#endif -#endif // GHC_FILESYSTEM_STD_H +#if _MSVC_LANG >= 201703L || __cplusplus >= 201703L && defined(__has_include) + // ^ Supports MSVC prior to 15.7 without setting /Zc:__cplusplus to fix __cplusplus + // _MSVC_LANG works regardless. But without the switch, the compiler always reported 199711L: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/ + #if __has_include() // Two stage __has_include needed for MSVC 2015 and per https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html + #define GHC_USE_STD_FS + + // Old Apple OSs don't support std::filesystem, though the header is available at compile + // time. In particular, std::filesystem is unavailable before macOS 10.15, iOS/tvOS 13.0, + // and watchOS 6.0. + #ifdef __APPLE__ + #include + // Note: This intentionally uses std::filesystem on any new Apple OS, like visionOS + // released after std::filesystem, where std::filesystem is always available. + // (All other ___VERSION_MIN_REQUIREDs will be undefined and thus 0.) + #if __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 \ + || __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 \ + || __TV_OS_VERSION_MIN_REQUIRED && __TV_OS_VERSION_MIN_REQUIRED < 130000 \ + || __WATCH_OS_VERSION_MAX_ALLOWED && __WATCH_OS_VERSION_MAX_ALLOWED < 60000 + #undef GHC_USE_STD_FS + #endif + #endif + #endif +#endif + +#ifdef GHC_USE_STD_FS + #include + namespace fs { + using namespace std::filesystem; + using ifstream = std::ifstream; + using ofstream = std::ofstream; + using fstream = std::fstream; + } +#else + #include + namespace fs { + using namespace ghc::filesystem; + using ifstream = ghc::filesystem::ifstream; + using ofstream = ghc::filesystem::ofstream; + using fstream = ghc::filesystem::fstream; + } +#endif + +#endif // GHC_FILESYSTEM_STD_H diff --git a/include/ghc/fs_std_fwd.hpp b/include/ghc/fs_std_fwd.hpp index 163c956..e6cd583 100644 --- a/include/ghc/fs_std_fwd.hpp +++ b/include/ghc/fs_std_fwd.hpp @@ -33,31 +33,47 @@ //--------------------------------------------------------------------------------------- #ifndef GHC_FILESYSTEM_STD_FWD_H #define GHC_FILESYSTEM_STD_FWD_H -#if defined(__APPLE__) -#include -#endif -#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) -#if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) -#define GHC_USE_STD_FS -#include -namespace fs { -using namespace std::filesystem; -using ifstream = std::ifstream; -using ofstream = std::ofstream; -using fstream = std::fstream; -} -#endif -#endif -#ifndef GHC_USE_STD_FS -//#define GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE -#define GHC_FILESYSTEM_FWD -#include -namespace fs { -using namespace ghc::filesystem; -using ifstream = ghc::filesystem::ifstream; -using ofstream = ghc::filesystem::ofstream; -using fstream = ghc::filesystem::fstream; -} -#endif -#endif // GHC_FILESYSTEM_STD_FWD_H +#if _MSVC_LANG >= 201703L || __cplusplus >= 201703L && defined(__has_include) + // ^ Supports MSVC prior to 15.7 without setting /Zc:__cplusplus to fix __cplusplus + // _MSVC_LANG works regardless. But without the switch, the compiler always reported 199711L: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/ + #if __has_include() // Two stage __has_include needed for MSVC 2015 and per https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html + #define GHC_USE_STD_FS + + // Old Apple OSs don't support std::filesystem, though the header is available at compile + // time. In particular, std::filesystem is unavailable before macOS 10.15, iOS/tvOS 13.0, + // and watchOS 6.0. + #ifdef __APPLE__ + #include + // Note: This intentionally uses std::filesystem on any new Apple OS, like visionOS + // released after std::filesystem, where std::filesystem is always available. + // (All other ___VERSION_MIN_REQUIREDs will be undefined and thus 0.) + #if __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 \ + || __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 \ + || __TV_OS_VERSION_MIN_REQUIRED && __TV_OS_VERSION_MIN_REQUIRED < 130000 \ + || __WATCH_OS_VERSION_MAX_ALLOWED && __WATCH_OS_VERSION_MAX_ALLOWED < 60000 + #undef GHC_USE_STD_FS + #endif + #endif + #endif +#endif + +#ifdef GHC_USE_STD_FS + #include + namespace fs { + using namespace std::filesystem; + using ifstream = std::ifstream; + using ofstream = std::ofstream; + using fstream = std::fstream; + } +#else + #include + namespace fs { + using namespace ghc::filesystem; + using ifstream = ghc::filesystem::ifstream; + using ofstream = ghc::filesystem::ofstream; + using fstream = ghc::filesystem::fstream; + } +#endif + +#endif // GHC_FILESYSTEM_STD_FWD_H diff --git a/include/ghc/fs_std_impl.hpp b/include/ghc/fs_std_impl.hpp index 7042edc..50b22b9 100644 --- a/include/ghc/fs_std_impl.hpp +++ b/include/ghc/fs_std_impl.hpp @@ -31,16 +31,30 @@ // The cpp has to include this before including fs_std_fwd.hpp directly or via a different // header to work. //--------------------------------------------------------------------------------------- -#if defined(__APPLE__) -#include -#endif -#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) -#if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) -#define GHC_USE_STD_FS -#endif +#if _MSVC_LANG >= 201703L || __cplusplus >= 201703L && defined(__has_include) + // ^ Supports MSVC prior to 15.7 without setting /Zc:__cplusplus to fix __cplusplus + // _MSVC_LANG works regardless. But without the switch, the compiler always reported 199711L: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/ + #if __has_include() // Two stage __has_include needed for MSVC 2015 and per https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html + #define GHC_USE_STD_FS + + // Old Apple OSs don't support std::filesystem, though the header is available at compile + // time. In particular, std::filesystem is unavailable before macOS 10.15, iOS/tvOS 13.0, + // and watchOS 6.0. + #ifdef __APPLE__ + #include + // Note: This intentionally uses std::filesystem on any new Apple OS, like visionOS + // released after std::filesystem, where std::filesystem is always available. + // (All other ___VERSION_MIN_REQUIREDs will be undefined and thus 0.) + #if __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 \ + || __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 \ + || __TV_OS_VERSION_MIN_REQUIRED && __TV_OS_VERSION_MIN_REQUIRED < 130000 \ + || __WATCH_OS_VERSION_MAX_ALLOWED && __WATCH_OS_VERSION_MAX_ALLOWED < 60000 + #undef GHC_USE_STD_FS + #endif + #endif + #endif #endif + #ifndef GHC_USE_STD_FS -//#define GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE -#define GHC_FILESYSTEM_IMPLEMENTATION -#include + #include #endif From a55c96a2ba9b14cf41f0e9bfd1203510380e001a Mon Sep 17 00:00:00 2001 From: Chris Sauer Date: Wed, 26 Jul 2023 21:28:52 -0700 Subject: [PATCH 2/5] Minor: seperated typo --- include/ghc/fs_fwd.hpp | 2 +- include/ghc/fs_impl.hpp | 2 +- include/ghc/fs_std_fwd.hpp | 2 +- include/ghc/fs_std_impl.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ghc/fs_fwd.hpp b/include/ghc/fs_fwd.hpp index 31188d1..1f84e35 100644 --- a/include/ghc/fs_fwd.hpp +++ b/include/ghc/fs_fwd.hpp @@ -25,7 +25,7 @@ // SOFTWARE. // //--------------------------------------------------------------------------------------- -// fs_fwd.hpp - The forwarding header for the header/implementation seperated usage of +// fs_fwd.hpp - The forwarding header for the header/implementation separated usage of // ghc::filesystem. // This file can be include at any place, where ghc::filesystem api is needed while // not bleeding implementation details (e.g. system includes) into the global namespace, diff --git a/include/ghc/fs_impl.hpp b/include/ghc/fs_impl.hpp index 92e3eae..7e3c989 100644 --- a/include/ghc/fs_impl.hpp +++ b/include/ghc/fs_impl.hpp @@ -25,7 +25,7 @@ // SOFTWARE. // //--------------------------------------------------------------------------------------- -// fs_impl.hpp - The implementation header for the header/implementation seperated usage of +// fs_impl.hpp - The implementation header for the header/implementation separated usage of // ghc::filesystem. // This file can be used to hide the implementation of ghc::filesystem into a single cpp. // The cpp has to include this before including fs_fwd.hpp directly or via a different diff --git a/include/ghc/fs_std_fwd.hpp b/include/ghc/fs_std_fwd.hpp index e6cd583..b1ace23 100644 --- a/include/ghc/fs_std_fwd.hpp +++ b/include/ghc/fs_std_fwd.hpp @@ -25,7 +25,7 @@ // SOFTWARE. // //--------------------------------------------------------------------------------------- -// fs_std_fwd.hpp - The forwarding header for the header/implementation seperated usage of +// fs_std_fwd.hpp - The forwarding header for the header/implementation separated usage of // ghc::filesystem that uses std::filesystem if it detects it. // This file can be include at any place, where fs::filesystem api is needed while // not bleeding implementation details (e.g. system includes) into the global namespace, diff --git a/include/ghc/fs_std_impl.hpp b/include/ghc/fs_std_impl.hpp index 50b22b9..b8d5697 100644 --- a/include/ghc/fs_std_impl.hpp +++ b/include/ghc/fs_std_impl.hpp @@ -25,7 +25,7 @@ // SOFTWARE. // //--------------------------------------------------------------------------------------- -// fs_std_impl.hpp - The implementation header for the header/implementation seperated usage of +// fs_std_impl.hpp - The implementation header for the header/implementation separated usage of // ghc::filesystem that does nothing if std::filesystem is detected. // This file can be used to hide the implementation of ghc::filesystem into a single cpp. // The cpp has to include this before including fs_std_fwd.hpp directly or via a different From 64f9c5a61a8e3613797627c56d7685d553abf6ca Mon Sep 17 00:00:00 2001 From: Chris Sauer Date: Wed, 26 Jul 2023 21:40:38 -0700 Subject: [PATCH 3/5] Switch internal includes to quoted relative This makes project integration more flexible, allowing the drag-contents-of-directory project integration contemplated in the readme and allowing use via -iquote --- README.md | 8 ++++---- include/ghc/fs_fwd.hpp | 2 +- include/ghc/fs_impl.hpp | 2 +- include/ghc/fs_std.hpp | 2 +- include/ghc/fs_std_fwd.hpp | 2 +- include/ghc/fs_std_impl.hpp | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 59cb32d..5321132 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ a fallback could be: #include namespace fs = std::filesystem; #else - #include + #include "filesystem.hpp" namespace fs = ghc::filesystem; #endif ``` @@ -246,7 +246,7 @@ you might use: using fstream = std::fstream; } #else - #include + #include "filesystem.hpp" namespace fs { using namespace ghc::filesystem; using ifstream = ghc::filesystem::ifstream; @@ -325,7 +325,7 @@ switching like this: using fstream = std::fstream; } #else - #include + #include "fs_fwd.hpp" namespace fs { using namespace ghc::filesystem; using ifstream = ghc::filesystem::ifstream; @@ -364,7 +364,7 @@ to take precedence: #endif #ifndef GHC_USE_STD_FS - #include + #include "fs_impl.hpp" #endif ``` diff --git a/include/ghc/fs_fwd.hpp b/include/ghc/fs_fwd.hpp index 1f84e35..fe87966 100644 --- a/include/ghc/fs_fwd.hpp +++ b/include/ghc/fs_fwd.hpp @@ -34,5 +34,5 @@ #ifndef GHC_FILESYSTEM_FWD_H #define GHC_FILESYSTEM_FWD_H #define GHC_FILESYSTEM_FWD -#include +#include "filesystem.hpp" #endif // GHC_FILESYSTEM_FWD_H diff --git a/include/ghc/fs_impl.hpp b/include/ghc/fs_impl.hpp index 7e3c989..929a6be 100644 --- a/include/ghc/fs_impl.hpp +++ b/include/ghc/fs_impl.hpp @@ -32,4 +32,4 @@ // header to work. //--------------------------------------------------------------------------------------- #define GHC_FILESYSTEM_IMPLEMENTATION -#include +#include "filesystem.hpp" diff --git a/include/ghc/fs_std.hpp b/include/ghc/fs_std.hpp index f188e57..d5c1643 100644 --- a/include/ghc/fs_std.hpp +++ b/include/ghc/fs_std.hpp @@ -65,7 +65,7 @@ using fstream = std::fstream; } #else - #include + #include "filesystem.hpp" namespace fs { using namespace ghc::filesystem; using ifstream = ghc::filesystem::ifstream; diff --git a/include/ghc/fs_std_fwd.hpp b/include/ghc/fs_std_fwd.hpp index b1ace23..d979113 100644 --- a/include/ghc/fs_std_fwd.hpp +++ b/include/ghc/fs_std_fwd.hpp @@ -67,7 +67,7 @@ using fstream = std::fstream; } #else - #include + #include "fs_fwd.hpp" namespace fs { using namespace ghc::filesystem; using ifstream = ghc::filesystem::ifstream; diff --git a/include/ghc/fs_std_impl.hpp b/include/ghc/fs_std_impl.hpp index b8d5697..8ba5733 100644 --- a/include/ghc/fs_std_impl.hpp +++ b/include/ghc/fs_std_impl.hpp @@ -56,5 +56,5 @@ #endif #ifndef GHC_USE_STD_FS - #include + #include "fs_impl.hpp" #endif From 23710d3b560c2696b3b1ddc2c5c060e367f20c95 Mon Sep 17 00:00:00 2001 From: Chris Sauer Date: Wed, 26 Jul 2023 21:56:08 -0700 Subject: [PATCH 4/5] Remove conditional inclusion snippet in filesystem.hpp Reduces duplication and tendency to get out of sync. As evidence of the problem, the snippet had previously (before this PR) started to diverge. It seemed more prudent to delete than to fix, given the usage instructions seem to be centralized in the readme and the dynamic selection headers should probably be recommended anyway. --- include/ghc/filesystem.hpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index bbb1023..cfb17e6 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -25,23 +25,6 @@ // SOFTWARE. // //--------------------------------------------------------------------------------------- -// -// To dynamically select std::filesystem where available on most platforms, -// you could use: -// -// #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include) -// #if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) -// #define GHC_USE_STD_FS -// #include -// namespace fs = std::filesystem; -// #endif -// #endif -// #ifndef GHC_USE_STD_FS -// #include -// namespace fs = ghc::filesystem; -// #endif -// -//--------------------------------------------------------------------------------------- #ifndef GHC_FILESYSTEM_H #define GHC_FILESYSTEM_H From 48d46cccef0d9b980a4ee409e86b6327d3b14b1b Mon Sep 17 00:00:00 2001 From: Chris Sauer Date: Wed, 26 Jul 2023 23:07:09 -0700 Subject: [PATCH 5/5] Improve apple conditionals in filesystem.hpp Two changes: - (minor) Rename GHC_OS_MACOS -> GHC_OS_APPLE, since it is defined all apple platforms (iOS, watchOS, etc.), not just macOS. - Changed the preprocessor conditional in last_write_time to align with its presumed intent. Previously, it would always have been true, which can't be intentional, because the *_OS_VERSION_MIN_REQUIRED is undefined and thus zero for platforms besides the current one, and therefore less than the constants--except for on very old SDKs where, e.g., MAC_OS_X_VERSION_10_13 and others would be undefined and therefore 0 and therefore making the clause false when it needed to be true. Therefore, I changed the conditions to be parallel to those in the dynamic selection headers, checking for the undefined, zero case and hardcoding the version values to support old SDKs. --- include/ghc/filesystem.hpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index cfb17e6..c7e9f54 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -36,7 +36,7 @@ #ifndef GHC_OS_DETECTED #if defined(__APPLE__) && defined(__MACH__) -#define GHC_OS_MACOS +#define GHC_OS_APPLE #elif defined(__linux__) #define GHC_OS_LINUX #if defined(__ANDROID__) @@ -164,7 +164,7 @@ #include #endif #endif -#ifdef GHC_OS_MACOS +#ifdef GHC_OS_APPLE #include #endif @@ -4633,9 +4633,11 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err if (!::SetFileTime(file.get(), 0, 0, &ft)) { ec = detail::make_system_error(); } -#elif defined(GHC_OS_MACOS) && \ - (__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_13) || (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_11_0) || \ - (__TV_OS_VERSION_MIN_REQUIRED < __TVOS_11_0) || (__WATCH_OS_VERSION_MIN_REQUIRED < __WATCHOS_4_0) +#elif defined(GHC_OS_APPLE) && \ + (__MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300 \ + || __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000 \ + || __TV_OS_VERSION_MIN_REQUIRED && __TVOS_VERSION_MIN_REQUIRED < 110000 \ + || __WATCH_OS_VERSION_MIN_REQUIRED && __WATCHOS_VERSION_MIN_REQUIRED < 40000) struct ::stat fs; if (::stat(p.c_str(), &fs) == 0) { struct ::timeval tv[2];