mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-21 19:43:34 +00:00
fix: constrain file.h Open templates with C++20 concepts
Add HasValueType concept to prevent compilation errors when using raw pointers like const char* with Open() templates. The templates now only participate in overload resolution for types that have a value_type member (e.g., std::string, std::filesystem::path). Fixes C2039 and C2651 errors on Windows builds. Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
@@ -34,12 +34,21 @@ void OpenFileStream(FileStream& file_stream, const std::filesystem::path& path,
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
template <typename FileStream, typename Path>
|
||||
void OpenFileStream(FileStream& file_stream, const Path& path, std::ios_base::openmode open_mode) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
file_stream.open(std::filesystem::path{ToU8String(path)}, open_mode);
|
||||
#include <concepts>
|
||||
|
||||
// Concept to check if a type has a value_type member
|
||||
template <typename T>
|
||||
concept HasValueType = requires { typename T::value_type; };
|
||||
|
||||
// Only enable this overload if Path has value_type
|
||||
template <HasValueType Path>
|
||||
void Open(const Path& path, FileAccessMode mode, FileType type = FileType::BinaryFile,
|
||||
FileShareFlag flag = FileShareFlag::ShareReadOnly) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
Open(ToU8String(path), mode, type, flag);
|
||||
} else {
|
||||
file_stream.open(std::filesystem::path{path}, open_mode);
|
||||
Open(std::filesystem::path{path}, mode, type, flag);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -184,7 +193,7 @@ public:
|
||||
FileShareFlag flag = FileShareFlag::ShareReadOnly);
|
||||
|
||||
#ifdef _WIN32
|
||||
template <typename Path>
|
||||
template <HasValueType Path>
|
||||
void Open(const Path& path, FileAccessMode mode, FileType type = FileType::BinaryFile,
|
||||
FileShareFlag flag = FileShareFlag::ShareReadOnly) {
|
||||
using ValueType = typename Path::value_type;
|
||||
|
||||
Reference in New Issue
Block a user