diff --git a/README.md b/README.md index 62b9d5a..5321132 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 "filesystem.hpp" + 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 "filesystem.hpp" + 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 -#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; -} +#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 -#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 "fs_fwd.hpp" + 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 "fs_impl.hpp" #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/filesystem.hpp b/include/ghc/filesystem.hpp index bbb1023..c7e9f54 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 @@ -53,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__) @@ -181,7 +164,7 @@ #include #endif #endif -#ifdef GHC_OS_MACOS +#ifdef GHC_OS_APPLE #include #endif @@ -4650,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]; diff --git a/include/ghc/fs_fwd.hpp b/include/ghc/fs_fwd.hpp index 31188d1..fe87966 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, @@ -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 92e3eae..929a6be 100644 --- a/include/ghc/fs_impl.hpp +++ b/include/ghc/fs_impl.hpp @@ -25,11 +25,11 @@ // 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 // 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 c9492fd..d5c1643 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 + +#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 -#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 "filesystem.hpp" + 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 +#endif // GHC_FILESYSTEM_STD_H diff --git a/include/ghc/fs_std_fwd.hpp b/include/ghc/fs_std_fwd.hpp index 163c956..d979113 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, @@ -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 + +#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_FWD -#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 "fs_fwd.hpp" + 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 +#endif // GHC_FILESYSTEM_STD_FWD_H diff --git a/include/ghc/fs_std_impl.hpp b/include/ghc/fs_std_impl.hpp index 7042edc..8ba5733 100644 --- a/include/ghc/fs_std_impl.hpp +++ b/include/ghc/fs_std_impl.hpp @@ -25,22 +25,36 @@ // 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 // 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 "fs_impl.hpp" #endif