
ghc::filesystem::ifstream , ghc::filesystem::ofstream , ghc::filesystem::fstreamghc::filesystem::u8arguments 이것은 C ++ 17 및 C ++ 20 사양을 기반으로 한 헤더 전용 단일 파일 std::filesystem 호환 헬퍼 라이브러리이지만 C ++ 11, C ++ 14, C ++ 17 또는 C ++ 20에 대해 구현되었습니다 (문서화 된 예외가 거의없는 C ++ 17 표준에 따라 단단히). 현재 MACOS 10.12/10.14/10.15/11.6, Windows 10, Ubuntu 18.04, Ubuntu 20.04, Centos 7, Centos 8, FreeBSD 12, Alpine ARM/ARM64 LINUX 및 SOLARIS 10에서 테스트되었지만 적어도 C ++ 11 호환 작곡가가있는 한 다른 시스템에서도 작동해야합니다. emscripten, emscripten과 함께 작동해야하며 iOS (샌드 박스 제약 조건 내)에 사용된다는보고가 있었고 v1.5.6에서는 QNX에 대한 실험적 지원이 있습니다. Android NDK, Emscripten, QNX, 1.5.14 GNU/HURD 및 Haiku의 지원은 자동화 된 테스트에 의해 백업되지 않지만 PRS 및 버그 보고서도 환영하며 작동하는 것으로보고되었습니다. 물론 자체 네임 스페이스 ghc::filesystem 정기적 인 std::filesystem 을 방해하지 않아도됩니다.
테스트 범위는 90%이상이며 V1.3.6에서 시작하여 v1.5.0에서는 라이브러리의 벤치마킹 및 최적화에 더 많은 시간이 투자되었습니다. 추가 C ++ 17/C ++ 20 호환성 문제를 도입하지 않는 한 일부 부품을 최적화하고 다른 부분을 계속 최적화하고 다른 부분을 리팩터링하려고 노력할 것입니다. 피드백은 항상 환영합니다. 예상대로 누락되거나 잘못되었거나 행동하지 않는 경우 문제를 열면 언급하겠습니다.
나는 종종 파일 시스템 기능, 주로 fs::path 필요하지만 디렉토리 액세스도 필요하며 C ++ 11을 사용하기 시작할 때 해당 언어 업데이트를 사용하여 타사 종속성을 줄이기 위해 노력했습니다. 나는 내가 사용한 것을 대부분 떨어 뜨릴 수 있었지만 여전히 재미를 위해 구현하기 시작한 것들을 놓쳤다. 원래 나는이 도우미들을 내 자신의 코딩 및 명명 규칙을 기반으로합니다. C ++ 17이 마무리되었을 때, 나는 그 인터페이스를 사용하고 싶었지만, 수업을 전환하기 위해 스스로를 밀기 위해 시간이 걸렸습니다.
구현은 C ++ 17 표준의 30.10 장을 기반으로하며 해당 버전과 가까운 초안은 N4687 초안 작업 중입니다. C ++ 17의 표준화 이후부터 시작되었지만 작업 초안 N4659와 비교하여 최신 파일 시스템 인터페이스 변경이 포함됩니다. C ++ 20을 사용하여 컴파일 된 v1.4.0을 쳐다 보면 경로 분류 순서 및 작업 초안 N4860에서 std::u8string 처리에 따라 변경 사항에 적응합니다.
C ++ 향상을 위해 일하는 사람들에게 감사의 말씀을 전하고 싶습니다. 나는 언어가 C ++ 11으로 진화하는 방법과 다음 표준을 좋아했습니다. 좋은 일을 계속하십시오!
당신이 ghc 무엇을 의미하는지 스스로에게 물어 보면 단순히 gulraks helper classes 입니다. 그래도 상상력이 없지만 짧은 네임 스페이스를 원했고 일부 개인 수업에서 사용합니다 (따라서 Haskell과 관련이 없습니다 .
ghc::filesystem 은 MacOS에서 개발되었지만 CI는 MacOS, Windows, 다양한 Linux 배포, FreeBSD에서 테스트되었으며 Solaris에서 v1.5.12로 시작합니다. C ++ 11 가능 컴파일러와 함께이 중 하나에서 작동해야합니다. 또한 Android에서 더 나은 작업에 대한 수표가 있지만 현재 Android NDK에서 테스트하지 않기 때문에 아직 지원되는 플랫폼이라고 부르지 않으므로 EMScripten과 함께 사용하는 데 유효합니다. 이제 감지 된 플랫폼의 일부이며 명백한 문제를 해결하고 일부 테스트를 실행하므로 괜찮을 것입니다. 대체로 전체 C ++ 17 또는 C ++ 20을 사용할 수있는 std::filesystem 대체하는 것을 보지 못합니다. "더 나은" std::filesystem 되려고하지 않으며, 사용할 수없는 경우 거의 드롭 인 (UTF-8 선호도를 제외하고).
중요 : 이 구현은 모든 std::string 인스턴스가 std::u8string 현명하고 UTF-8에있는 것으로 인코딩하는 것과 동일하게 해석 될 것이라는 "UTF-8 Everywhere"철학을 따릅니다. std::u16string UTF-16으로 간주됩니다. 자세한 내용은 API의 차이점을 참조하십시오.
단위 테스트는 현재 다음과 같이 실행됩니다.
헤더는 단위 테스트 세트와 함께 제공되며 CMake를 빌드 도구로 사용하고 테스트 프레임 워크로 Catch2를 사용합니다. 모든 테스트는 CMAKE에 등록되므로 CTEST Commando를 사용하여 테스트를 실행할 수 있습니다.
이 구현에 대한 모든 테스트는 귀하의 환경에 따라 성공해야합니다. 예를 들어 Windows에서 Symlinks를 만들 권한이 없거나 적어도 테스트가 그렇게 생각할 권리가 없다면 유익한 정보입니다.
MacOS 또는 Linux의 프로젝트 디렉토리 내부에서 테스트를 구축하려면 다음과 같습니다.
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
ctest이를 통해 테스트를 실행하는 테스트 바이너리가 생성되고 마지막 명령이 실행됩니다.
기본 컴파일러가 GCC 8 또는 최신 또는 Clang 7 또는 최신 인 경우 추가로 구성된 테스트 테스트로서 std_filesystem_test 라는 GCCS/Clangs std::filesystem 구현에 대한 테스트 바이너리 버전을 구축하려고합니다. 이상적으로 모든 테스트는 모든 파일 시스템 구현에서 컴파일하고 성공해야하지만 실제로는 행동에 약간의 차이가 있으며 때로는 표준의 해석 공간으로 인해 이러한 구현에 문제가있을 수 있습니다.
최신 릴리스 버전은 v1.5.14이며 소스 아카이브는 여기에서 찾을 수 있습니다.
최신 사전 자방 반응 버전은 v1.4.0이며 소스 아카이브는 여기에서 찾을 수 있습니다.
최신 C-C ++ 20-Support 릴리스 버전은 v1.3.10이며 소스 아카이브는 여기에서 찾을 수 있습니다.
현재 최신 마이너 릴리스 버전 만 버그 픽스를 수신하므로 가능하면 최신 릴리스를 사용해야합니다.
ghc::filesystem 은 처음에는 헤더 전용 라이브러리이므로 헤더 또는 include/ghc 디렉토리를 프로젝트 폴더에 복사 하거나이 장소로의 포함 경로를 가리키고 filesystem.hpp .hpp 헤더 (또는 ghc/filesystem.hpp 사용하는 경우)를 포함시키기에 충분해야합니다.
모든 것이 네임 스페이스 ghc::filesystem 에 있으므로 폴백으로 만 사용하는 한 가지 방법은 다음과 같습니다.
# 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(<filesystem>) // 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 < Availability.h >
// 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 __<platform>_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 < filesystem >
namespace fs = std::filesystem;
# else
# include " filesystem.hpp "
namespace fs = ghc::filesystem;
# endif path 지원이있는 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(<filesystem>) // 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 < Availability.h >
// 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 __<platform>_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 < filesystem >
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 이제 당신은 예를 들어 fs::ofstream out(somePath); 그리고 그것은 래퍼 또는 C ++ 17 std::ofstream 입니다.
헤더 전용 라이브러리로서 시스템이 포함되어 있다는 사실을 숨기지 않으므로 글로벌 네임 스페이스를 "오염"합니다. 이를 피하려면 전달/구현 헤드 기반 접근법 (아래 참조)을 사용하십시오. Windows의 경우 Windows.h 필요하며 filesystem.hpp 또는 fs_std.hpp 헤더를 포함시키기 전에 WIN32_LEAN_AND_MEAN 또는 NOMINMAX 정의하여 글로벌 네임 스페이스의 오염 및 컴파일 시간을 줄이는 것이 좋습니다. ghc::filesystem 전체 Windows.h 필요한 컨텍스트 (예 : UI 요소)와 조합 할 수 있도록 정의되지 않습니다.
힌트 : ghc/fs_std.hpp 라는 추가 헤더가 있으며 파일 시스템 구현의 이러한 동적 선택을 구현합니다. ghc/filesystem.hpp 대신 std::filesystem 사용할 수 있고 ghc::filesystem 원할 때 포함 할 수 있습니다.
또는 v1.1.0 ghc::filesystem 에서 시작하여 2 개의 추가 래퍼 헤더 중 하나를 포함하여 사용할 수도 있습니다. 여기에는 대부분의 장소에 전달 된 버전 ( ghc/fs_fwd.hpp )이 포함되어 있고 필요한 코드를 구현하기 위해 ghc/fs_impl.hpp 포함 된 단일 CPP 파일에 구현 세부 정보를 숨길 수 있습니다. ghc::filesystem 사용하면 시스템이 포함되어있어 CPP 파일 내부에서만 볼 수있게되면 다른 모든 장소는 깨끗합니다.
인터페이스에 C ++ 표준 템플릿이있는 DLL 인터페이스가 다른 짐승이므로 현재 구현을 Windows-DLL에 숨기는 것이 지원되지 않습니다. 누군가가 그것을 시험해 볼 의향이 있다면, 나는 PR을 통합 할 수 있지만 현재 직접 작업하는 것은 우선 순위가 아닙니다.
전달/구현 접근법을 사용하는 경우에도 다음과 같은 동적 스위칭을 사용할 수 있습니다.
# 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(<filesystem>) // 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 < Availability.h >
// 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 __<platform>_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 < filesystem >
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 그리고 CPP를 숨기는 구현에서 당신은 ( ghc/fs_fwd.hpp 포함하여 포함하기 전에 다음을 사용할 수 있습니다.
# 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(<filesystem>) // 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 < Availability.h >
// 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 __<platform>_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
# include " fs_impl.hpp "
# endif 힌트 : 이 기술을 사용하는 ghc/fs_std_fwd.hpp 및 ghc/fs_std_impl.hpp 라는 추가 도우미 헤더가 있으므로 파일 시스템 구현을 동적으로 선택하려면 간단히 포함시킬 수 있습니다.
v1.1.0부터 ghc::filesystem GIT 하위 모드로 추가하고 add_subdirectory() 사용하여 CMakeLists.txt 에 디렉토리를 추가 한 다음 target_link_libraries(your-target ghc_filesystem) 사용하여 #include <ghc/filesystem.hpp> .
CMakeLists.txt 는 동작을 사용자 정의 할 수있는 몇 가지 옵션을 제공합니다.
GHC_FILESYSTEM_BUILD_TESTING ON 모드로 사용하면 기본값이 OFF 있습니다.GHC_FILESYSTEM_BUILD_EXAMPLES ON 모드로 사용하면 기본값이 OFF 있습니다.GHC_FILESYSTEM_WITH_INSTALL 빌드에 설치 대상을 추가하고, 서브 ON 로 사용하면 기본값이 OFF 있습니다.GHC_FILESYSTEM_BUILD_STD_TESTING STD :: std::filesystem 에 대해 실행중인 테스트 스위트의 변형 인 std_filesystem_test 컴파일하여 GHC_FILESYSTEM_BUILD_TESTING 으로 기본값을 제공합니다. 컴파일러가 할 수있는 것으로 감지 된 경우에만 수행됩니다.GHC_FILESYSTEM_TEST_COMPILE_FEATURES cxx_std_20 테스트를 위해 CMAKE_CXX_COMPILE_FEATURES filesystem_test_cpp20 하기 위해 기능 목록으로 설정할 수 있습니다.Hedronvision/Bazel-CC-Filesystem-Backport를 사용하여 모든 것을 자동으로 설정할 수 있습니다.
향후 변경으로 인해 버전에서 반응해야 할 경우에 정의 된 Macro GHC_FILESYSTEM_VERSION 버전이 있습니다. 소수점 번호 (major * 10000 + minor * 100 + patch) 입니다.
참고 : 패치 버전 만 릴리스에 사용되며 홀수 패치 버전은 다음 버전에서 작업하는 동안 Commits 사이에만 사용됩니다.
다음 섹션에서 설명 된 몇 가지 차이점 외에도 std::filesystem 문서화가 작동하기 때문에이 릴리스에는 문서가 거의 없습니다. 따라서이 라이브러리의 구성 요소에 대한 설명을 위해 https://en.cppreference.com/w/cpp/filesystem으로 이동할 수 있습니다.
C ++ 11, C ++ 14 또는 C ++ 17로 컴파일 할 std::string_view API는 C ++ 17 표준을 따릅니다. C ++ 20으로 컴파일 할 때 ghc::filesysytem char8_t 및 std::u8string 인터페이스 및 더 이상 사용되지 않은 fs::u8path FACTORY 메소드를 사용하여 C ++ 20 API로 기본적으로 C ++ 20 API로 기본적으로 구성됩니다.
참고 : C ++ 17 API를 C ++ 20 모드에서도 시행 해야하는 경우 GHC_FILESYSTEM_ENFORCE_CPP17_API 를 정의하십시오. 그럼에도 불구하고 std::u8string 에서 fws::path 만들 수 있지만 fs::path::u8string() 및 fs::path::generic_u8string() 정상 UTF-8 인코딩 된 std::string 인스턴스를 반환하므로 C ++ 17 용으로 작성된 코드는 여전히 C++20으로 컴파일 될 때 ghc::filesystem 과 함께 작동 할 수 있습니다.
표준에 대한 유일한 추가 사항은 다음과 같습니다.
ghc::filesystem::ifstream , ghc::filesystem::ofstream , ghc::filesystem::fstream 이것들은 std::ifstream , std::ofstream 및 std::fstream 주변의 간단한 포장지입니다. C ++ 17의 fstream 변형이이를 가지고 있기 때문에 open() 메소드와 ghc::filesystem::path 인수가있는 생성자를 추가합니다.
ghc::filesystem::u8arguments이것은 현재 Windows 플랫폼이 아닌 플랫폼에서 UTF-8 인코딩을 확인하는 도우미 클래스이지만 Windows에서는 OS의 유니 코드 문자열로 명령 줄 인수를 가져옵니다.
::CommandLineToArgvW (::GetCommandLineW(), &argc) 그런 다음 UTF-8로 변환하고 argc 및 argv 대체합니다. 범위를 벗어날 때 변경 사항을 되돌리는 경비원과 같은 클래스입니다.
기본 사용은 다음과 같습니다.
namespace fs = ghc::filesystem;
int main ( int argc, char * argv[])
{
fs::u8arguments u8guard (argc, argv);
if (!u8guard. valid ()) {
std::cerr << " Bad encoding, needs UTF-8. " << std::endl;
exit (EXIT_FAILURE);
}
// now use argc/argv as usual, they have utf-8 encoding on windows
// ...
return 0 ;
} 이렇게하면 argv 가 main 의 범위가 유효 한 한 UTF-8 인코딩됩니다.
참고 : MacOS에서 Xcode에서 디버깅하는 동안 코드는 Xcode가 US-ASCII 로 응용 프로그램을 인코딩으로 시작하고 제품 구성표에서 LC_ALL 설정하더라도 아무 것도 변경하지 않더라도 현재 CODE가 US-ASCII로 응용 프로그램을 시작함에 따라 false 를 반환합니다. 나는 여전히 이것을 조사해야합니다.
이 구현은 개인 도우미 클래스의 기존 코드를 기반으로하므로 일부 제약 조건을 도출했습니다. V1.5.0에서 시작하여 제거 된 표준 C ++ 17/C ++ 20 API의 차이는 대부분.
이 구현은 LWG 결함 #2682, #2935, #2936 및 #2937에 대한 전환 가능한 동작을 가지고 있습니다. 현재 선택된 동작 (v1.4.0부터 시작)은 #2682, #2936, #2937을 따르지만 #2935를 따르지 않습니다. #2935를 따르지 않습니다. create_directory() 또는 create_directories() 에 오류가 발생하지 않는 버그는 동일한 이름의 일반 파일이 디렉토리의 생성을 금지하고 해당 기능의 사용자가 실제로 해당 기능을 통해 이중 check에 대한 fs::is_directory 일했다. 해당 이름을 가진 파일을 오류로 처리하는 디렉토리 생성에 대한보다 직관적 인 접근 방식은 새로운 논문 WG21 P1164R0에 의해 옹호되며, 개정 P1161R1은 KONA 2019 회의에서 합의에 동의했습니다 (GCC #86910).
// methods in ghc::filesystem::path:
path& operator +=(basic_string_view<value_type> x);
int compare (basic_string_view<value_type> s) const ; std::basic_string_view 가 없으므로 C ++ 11 및 C ++ 14에 따라 구현되지 않으며이 구현을 자체 포함하고 C ++ 11/14에 대한 전체 C ++ 17 업그레이드를 작성하지 않으려고했습니다. v1.1.0부터 시작하여 C ++ 20의 C ++ 17에서 ghc::filesystem 컴파일 할 때 지원됩니다.
v1.5.2 ghc::filesystem 에서 시작하여 std::experimental::basic_string_view 사용하여 가용성이 있습니다. 또한 basic_string_view 호환 C ++ 11 구현이있는 경우 GHC_HAS_CUSTOM_STRING_VIEW 정의하고 ghc::filesystem 네임 스페이스로 구현을 가져 와서 std::basic_string_view 대신 사용할 수 있습니다.
namespace ghc {
namespace filesystem {
using my::basic_string_view;
}
}파일 시스템 헤더를 포함하기 전에.
외부 제 3 자 라이브러리에 의존하지 않고 여전히 휴대용 및 컴팩트 한 상태를 유지하기 위해이 구현은 모든 std::string 인스턴스가 현명한 인코딩 및 UTF-8에있는 것처럼 std::u8string 과 동일하게 해석 될 것입니다. std::u16string UTF-16으로 간주되며 std::u32string 유니 코드 코드 포인트로 간주됩니다. std::wstring 문자의 크기에 따라 std::wstring UTF-16 (예 : Windows) 또는 char32_t 유니 코드 코드 포인트 (현재 다른 모든 플랫폼)로 처리합니다.
v1.5.0 ghc::filesystem 부터 시작하여 wchar_t 및 std::wstring 경로 표현에 내부적으로 사용하는 유형으로 사용하는 C ++ 17 표준을 따릅니다. GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE 를 정의하고 filesystem::path::string_type std::string 및 filesystem::path::value_type as wchar_t 로 얻음으로써 이전 동작을 얻을 수 있습니다.
v1.5.0 이상으로 일부 Windows API를 호출 해야하는 경우 Windows-API 호출의 W- 변수를 사용하기 만하면됩니다 (예 : GetFileAttributesW(p.c_str()) ).
참고 : GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE 정의하여 이전 동작을 사용하는 경우 path::wstring() 멤버 (예 : GetFileAttributesW(p.wstring().c_str()) )를 사용하십시오. 이것은 UNICODE 매크로와 독립적 인 유니 코드 변형을 제공하고 Windows, Linux 및 MacOS간에 코드를 더 쉽게 공유하고 std::filesystem 및 ghc::filesystem 과 함께 작동합니다.
std::string path::u8string () const ;
std::string path::generic_u8string () const ;
vs.
std::u8string path::u8string () const ;
std::u8string path::generic_u8string () const ; 이 두 방법의 반환 유형은 중고 C ++ 표준에 따라 다르며 GHC_FILESYSTEM_ENFORCE_CPP17_API 가 정의 된 경우입니다. C ++ 11, C ++ 14 및 C ++ 17에서 또는 GHC_FILESYSTEM_ENFORCE_CPP17_API 가 정의 될 때, 리턴 유형은 std::string 이고 C ++ 20에서는 std::u8string 입니다.
나는 여기에 언급 될 수있는 다른 std::filesystem 구현 사이의 많은 행동 차이에 대한 위키 항목을 만들었지 만,이 판독 값은 ghc::filesystem 사이의 설계 선택 차이를 해결하려고 시도합니다. 위키 페이지를 수시로 업데이트하려고합니다.
추가 관찰을 환영합니다!
v1.5.0 이후이 구현의 완전한 내부 역학은 내부 표현으로 기본 형식으로 변경된 fs::path . Windows 아래에서 혼합 슬래시 fs::path 개체를 생성합니다 (예 : "C:foo/bar" )는 generic_string() API를 통해 native() 및 "C:/foo/bar" "C:foobar" 로 깨끗한 경로를 이끌어냅니다. 모든 플랫폼에서 중복 된 추가 분리기는 표준 및 기타 구현에 의해 시행되지 않더라도 대부분이 작업을 수행하지 않더라도 제거됩니다.
또한이 구현은 "//host/path" "//host" 의 posix 경로를 처리하기위한 표준 제안을 따릅니다. GCC 구현은 GCC 8.1.0 또는 Clang 7.0.0을 사용하여 Ubuntu 18.04 및 MacOS를 테스트하는 동안이를 선택하지 않았습니다. 이 차이는 std::filesystem 의 경고로 보여줍니다. 이것은 p.is_absolute() 가있는 모든 operator/=(path& p) p 에 대한 표준에 설명 된 알고리즘의 변화로 이어지고,이 구현에는 할당이 저하되는 반면,이 구현에는 *this == *this.root_name() 및 p == preferred_separator 정상적인 부속이 수행되는 경우 :
fs::path p1 = " //host/foo/bar/file.txt " ;
fs::path p2;
for ( auto p : p1) p2 /= p;
ASSERT (p1 == p2);모든 비 호스트 경로에 대해 행동은 표준에 의해 설명 된 경로와 일치합니다.
Windows의 상징적 링크가 Windows Vista (일부 엄격한 보안 제약 조건 포함) 이후 다소 지원되는 동안 "개발자 모드"가 활성화 될 때 (2018)은 거의 사용되지 않아도이 구현에서 지원됩니다.
Windows ACL 권한 기능은 C ++ 17 파일 시스템 인터페이스에 사용되는 POSIX 권한 비트 마스크로 잘못 변환됩니다. 따라서 file_status 에서 반환 된 권한은 현재 user 수준에 대해 합성되어 group 및 other 레벨에 복사됩니다. Windows 권한 시스템과 더 많은 상호 작용을 할 가능성이 여전히 있지만 현재이 구현에 대한 권한을 설정하거나 읽는 것은 확실히 예상되는 동작으로 이어지지 않을 것입니다.
extension() 디렉토리 이름 ".." 에 대해 비 빈 결과를 반환했습니다.ghcFilesystem::ghc_filesystem 이 무조건 설정되었습니다.fs::path 의 POSIX stem() , filename() 및 extension() 에서 #156에 대한 수정 : 콜론이 파일 이름에 있으면 잘못된 결과를 반환합니다.fs::last_write_time(path, time, ec) 세터fs::directory_entry::refresh() 에 대한 수정은 이제 status() 와 일관되게 symlinks를 기존 대상으로 던지지 않지만 입력에 file_type::not_found 유형으로 표시됩니다.EINTR 처리fs::copy_file() 당기십시오. 이제 권한도 복사합니다fs::copy_file() skip_existing 옵션을 무시합니다.dirent::d_type 및 고정 빌드 구성 및 테스트를 새로운 플랫폼으로 지원하기 위해 Solaris를 지원하지 않는 시스템에서 GHC_NO_DIRENT_D_TYPE 에 대한 제거가 제거되었습니다.PATH_MAX 가 없으면 하나는 정의됩니다.fs::remove_all 당기십시오.fs::space 고정하십시오.fs::create_directories 더 이상 긴 파일 이름에서 깨지지 않는 #125를 수정하십시오.ghc::filesystem 처리 된 장착 폴더/볼륨을 심볼릭 링크로 잘못 처리하여 fs::canonical 이 포함 된 경로에서 실패하도록 이끌어냅니다.recursive_directory_iterator 증가 시키면 Dead Symlinks를 입력하지 않습니다.std::fs fs::remove 실패한 경로가 읽기 전용 항목을 가리키면 실패했습니다.GHC_NO_DIRENT_D_TYPE 대한 수정을 사용하면 dirent.d_type 멤버없이 OS 감지 시스템을 지원할 수 있습니다. DT_UNKNOWN (EG ReiserFS)을 반환하는 파일 시스템의 고정 된 문제는 초기 사용 사례로서의 실험적인 첫 번째 QNX 컴파일 지원을 지원합니다.string_view 지원을 추가하십시오.<ghc/fs_std.hpp> 또는 <ghc/fs_std_fwd.hpp> / <ghc/fs_std_impl.hpp> 전에 <Availability.h> 포함 된 경우에만 작동했습니다.std::filesystem 기능이 지원되기 때문에 표준 챕터 번호의 사용이 오도되었습니다.recursive_directory_iterator 에 대한 성능은 이제 Libc ++와 LibStdc ++ 사이에있는 큰 나무에 대한 큰 나무에 대한 향상.ghc::filesystem 이제 Cygwin에 대한 예비 지원을 받았습니다. 테스트가 성공적으로 컴파일하고 실행할 수 있도록하는 곳 (GCC 10.2.0으로 테스트), 피드백 및 추가 PR은 현재 CI 구성의 일부가 아니기 때문에 환영합니다.GHC_FILESYSTEM_BUILD_STD_TESTING std::filesystem 비교의 추가 빌드 버전을 비교하고 GHC_FILESYSTEM_TEST_COMPILE_FEATURES 사용할 가능성을 CMAKE_CXX_COMPILE_FEATURES 프리 플렌징 할 가능성.directory_entry 생성은 더 큰 디렉토리 트리를 통해 recursive_directory_iterator 테스트에서 약 20% -25%로 이어집니다.wchar_t 비 창문에 대한 지원 숯 유형 목록에 없습니다.string_view 지원은 사용 가능한 경우 <string_view> 또는 <experimental/string_view> 를 사용하고, GHC_HAS_CUSTOM_STRING_VIEW 정의 할 때 Custom basic_string_view 구현을 사용할 수 있으며 FileSystem 헤이닝을 포함하기 전에 ghc::filesystem Nomespace로 문자열보기를 가져올 때 Custom Basic_String_view 구현을 사용할 수 있습니다.std::filesystem 테스트는 이제 -lrt 와 연결되어 문제를 피하십시오.fs::hard_link_count 의 테스트 사례는 파일 시스템 동작으로 인해 실패했으며 테스트 사례는이를 고려하도록 조정되었습니다.GHC_FS_API 정의하고 GHC_FS_API_CLASS 는 이제 외부에서 설정할 때 동작을 재정의 할 수 있도록 영광입니다.make install 파일의 일부가 구성되었습니다.GHC_FILESYSTEM_BUILD_TESTING , GHC_FILESYSTEM_BUILD_EXAMPLES 및 GHC_FILESYSTEM_WITH_INSTALL 구현 한 경우 add_subdirectory 통해이를 통해이를 사용할 때 부모 프로젝트에서 설정하는 것이 금지되어 있습니다.이 수정을 다시 설정할 수 있습니다.fs::path 의 Windows 버전 버전은 원래 POSIX 기반 구현에서 생성되었으며, 나가는 문자열을 적응 시켰습니다. 이로 인해 fs::path 내부에 변한 캐시 const 발생했습니다. 차선책에 추가 패치를 추가하지 않기 위해 이번에는 path 코드를 재 작업하여 이제 기본 경로 표현을 저장했습니다. 이것은 많은 코드가 바뀌었지만 value_type 로서 wchar_t 와 결합하면 Win-API 호출에 대한 많은 전환을 피하는 데 도움이되었습니다.fs::path::native() 및 fs::path::c_str() 이제 표준 의무로 noexcept 할 수 있습니다.wchar_t 이제 fs::path::value_type 및 std::wstring fs::path::string_type 기본값입니다.fs::path 의 const 방법에 대한 스레드 안전성은 더 이상 문제가되지 않습니다.GHC_WIN_DISABLE_AUTO_PREFIXES 정의하여 Windows에서 긴 경로의 자동 접두사 std::filesystem::path 비활성화 할 수 있습니다.char / std::string 기반 접근법이 여전히 필요한 경우 GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE 로 활성화 할 수 있습니다.fs::file_status 이제 c ++ 20으로 std::filesystem 에 소개 된 operator== 지원합니다.fs::path::parent_path() 여전히 요소에서 부모를 재현하기 위해 루프 기반 접근 방식을 사용하고 있었기 때문에 성능 문제가있었습니다. 이것은 많은 시간을 만들어 냈으며 특히 긴 길에서 너무 느 렸습니다.char8_t 및 std::u8string Source 매개 변수 유형 인 경우 지원됩니다.fs::path::u8string() 및 fs::path::generic_u8string() 이제 std::u8string 반환합니다<=> 이제 fs::path 를 위해 지원되었습니다GHC_FILESYSTEM_ENFORCE_CPP17_API ghc::filesystem 이전 fs::path::u8string() 및 fs::path::generic_u8string() API로 돌아갑니다.fs::proximate(p, ec) 에 대한 버그 픽스 fs::current_path() 에 대한 내부 호출이 error_code 변형을 사용하지 않고 ec 설정하는 대신 가능한 예외를 던집니다.LWG_2936_BEHAVIOUR 기본적으로 켜져 있습니다.Source 매개 변수를 처리하는 고정 문제.constexpr 입니다.__MAC_OS_X_VERSION_MIN_REQUIRED 사용하여 std::filesystem 적어도 카탈리나 인 경우 MACOS에서만 선택되도록합니다.directory_iterator 및 recursive_directory_iterator 의 버그 픽스는 skip_permission_denied 옵션에 문제가있어 MACOS에서 SIP 보호 폴더를 건너 뛸 수 없습니다._MSVC_LANG 의 향상은 이제 __cplusplus 에 추가로 사용되며, /Zc:__cplusplus 사용되지 않더라도 작동 할 수 있도록 돕는 헤더에서 추가로 사용됩니다.false 한 맵핑 볼륨을 가리키며 fs::exists fs::status 존재하지 않거나 발견되지 않은 오류로 이어집니다. 네임 스패치 경로는 더 이상 필터링되지 않습니다.filesystem_test.cpp 의 TestAllocator 인 #72의 Bugfix는 devtoolset-9 사용하여 CentOS 7을 구축하기위한 요구 사항을 충족시키기 위해 완료되었습니다. Centos 7 및 Centos 8은 이제 CI 빌드의 일부입니다.[fs.path.compare] 17 fs::path::compare 동작을 활성화 할 수있는 새로운 동작 스위치 LWG_2936_BEHAVIOUR 추가합니다. v1.3.6에서 기본값이며 주문이 변경되면 V1.4.0에서 시작하여 기본값이됩니다.ghc::filesystem::fstream 랩퍼의 std::fstream 의 wchar_t 버전을 사용하십시오.fs::directory_options::skip_permission_denied 사용할 때 디렉토리 반복자에 대한 권한 문제를 더 잘 처리하고 Emscripten을 사용한 컴파일을위한 초기 지원.ghc::filesystem 이제 비활성화 된 예외가있는 프로젝트에서 사용을 지원합니다. 이 모드에서는 오류 처리에 대한 예외를 사용하는 API 서명이 없으므로 PR에 감사드립니다 ( #60 및 #43을 해결합니다)ERROR_FILE_TOO_LARGE 상수에 대한 오류로 컴파일이 실패 할 수 있습니다.fs::lexically_relative 의 버그 픽스는 기본 매개 변수의 후행 슬래시를 무시하지 않았습니다. PR #57에 감사드립니다.fs::create_directories returned true when nothing needed to be created, because the directory already existed.error_code was not reset, if cached result was returned.fs::path from a stream.timespec fields to avoid warnings.ghc::filesystem is re-licensed from BSD-3-Clause to MIT license. (see #47)fs::rename on Windows didn't replace an existing regular file as required by the standard, but gave an error. New tests and a fix as provided in the issue was implemented.fs_fwd.hpp or fs_std_fwd.hpp there was a use of DWORD in the forwarding part leading to an error if Windows.h was not included before the header. The tests were changed to give an error in that case too and the useage of DWORD was removed.GetProcAddress gave a warning with -Wcast-function-type on MSYS2 and MinGW GCC 9 builds.CMakeLists.txt will automatically exclude building examples and tests when used as submodule, the configuration options now use a prefixed name to reduce risk of conflicts.ghcFilesystemConfig.cmake in ${CMAKE_INSTALL_LIBDIR}/cmake/ghcFilesystem for find_package that exports a target as ghcFilesystem::ghc_filesystem .error: redundant redeclaration of 'constexpr' static data member deprecation warning in C++17 mode.fs::create_directories , thanks for the PR!GHC_FILESYSTEM_WITH_INSTALL that is defaulted to OFF if ghc::filesystem is used via add_subdirectory .fs::path::lexically_normal() that leaves a trailing separator in case of a resulting path ending with .. as last element.BUILD_TESTING and BUILD_EXAMPLES to NO , OFF or FALSE .std::string_view when available was added.std::string_view is available.fs::path::preferred_separator declaration was not compiling on pre C++17 compilers and no test accessed it, to show the problem. Fixed it to an construction C++11 compiler should accept and added a test that is successful on all combinations tested.fs::copy_options where not forwarded from fs::copy to fs::copy_file in one of the cases.strerror_r signature was expected. The complex preprocessor define mix was dropped in favor of the usual dispatch by overloading a unifying wrapper.ghc::filesystem missed a <vector> include in the windows case.wchar_t/std::wstring interface when compiling on Windows with defined GHC_WIN_WSTRING_STRING_TYPE , this is default when using the ghc/fs_std*.hpp header, to enhance compatibility.GHC_RAISE_UNICODE_ERRORS (instead of replacing invalid code points or UTF-8 encoding errors with the replacement character U+FFFD ).fs::copy_file .readdir/readdir_r code of fs::directory_iterator ; as readdir_r is now deprecated, I decided to drop it and the resulting code is much easier, shorter and due to more refactoring fasterstd::filesystemfs::path::lexically_normal() had some issues with ".." -sequences.fs::recursive_directory_iterator could run into endless loops, the methods depth() and pop() had issues and the copy behavior and input_iterator_tag conformance was broken, added testsstd::filesystem builds of tests and examples for interoperability checks.fs::weakly_canonical() tests against std::fsdu example showing the recursive_directory_iterator used to add the sizes of files in a directory tree.fs::file_time_type test helpersfs::copy() now conforms LWG #2682, disallowing the use of `copy_option::create_symlinks' to be used on directorieshpp as extension to be marked as c++ and they where moved to include/ghc/ to be able to include by <ghc/filesystem.hpp> as the former include name might have been to generic and conflict with other files.ghc::filesystem now can be used as a submodul and added with add_subdirectory and will export itself as ghc_filesystem target. To use it, only target_link_libraries(your-target ghc_filesystem) is needed and the include directories will be set so #include <ghc/filesystem.hpp> will be a valid directive. Still you can simply only add the header file to you project and include it from there.ghc::filesystem declarations ( fs_fwd.hpp ) and to wrap the implementation into a single cpp ( fs_impl.hpp )std::basic_string_view variants of the fs::path api are now supported when compiling with C++17.ghc::filesystem::path::generic_string()filesystem.h was renamed filesystem.hpp to better reflect that it is a c++ language header.ghc::filesystem::remove() and ghc::filesystem::remove_all() both are now able to remove a single file and both will not raise an error if the path doesn't exist.ghc::filesystem::remove() under Windows.ghc::filesystem::directory_iterator now releases resources when reaching end() like the POSIX one does.ghc::filesystem::copy() and ghc::filesystem::remove_all fixed.ghc::filesystem::recursive_directory_iterator::difference_type .-Wall -Wextra -Werror and fixed resulting issues.fs.op.permissions test to work with all tested std::filesystem implementations (gcc, clang, msvc++).ghc::filesystem::u8arguments as argv converter, to help follow the UTF-8 path on windows. Simply instantiate it with argc and argv and it will fetch the Unicode version of the command line and convert it to UTF-8. The destructor reverts the change.examples folder with hopefully some usefull example usage. Examples are tested (and build) with ghc::filesystem and C++17 std::filesystem when available.std::filesystem for comparison.fstream include.timespec / timeval usage.chrono conversion issues in test and example on clang 7.0.0.ghc::filesystem::canonical now sees empty path as non-existant and reports an error. Due to this ghc::filesystem::weakly_canonical now returns relative paths for non-existant argument paths. (#1)ghc::filesystem::remove_all now also counts directories removed (#2)recursive_directory_iterator tests didn't respect equality domain issues and dereferencapable constraints, leading to fails on std::filesystem tests.noexcept tagged methods and functions could indirectly throw exceptions due to UFT-8 decoding issues.std_filesystem_test is now also generated if LLVM/clang 7.0.0 is found. This was the first public release version. It implements the full range of C++17 std::filesystem , as far as possible without other C++17 dependencies.