vimpunk / mio

Cross-platform C++11 header-only library for memory mapped file IO
MIT License
1.71k stars 157 forks source link

Add support for Windows wchar paths #19

Closed vimpunk closed 5 years ago

vimpunk commented 6 years ago

16 explicitly disabled Windows' wide character types due to #15. As suggested in the issue, I also believe this could be solved with some SFINAE by extracting the Windows API calls into a template wrapper so that we can make the compiler choose the right function based on the String's character type, e.g. using std::char_traits<String>::char_type.

vimpunk commented 6 years ago

Nevermind the bit about char_traits, I forgot that it takes some char type as its template argument and not a string. So for this some custom template struct that gives back the underlying character type of the string would have to be created, e.g. char_type<S>::type, where S may be a char*, std::string, vector<char>, wchar_t* etc.

[edit to continue] And then we could choose the specific function with SFINAE based on the character type, e.g. (pseudocode):

template <
    class S,
    class = typename std::enable_if<
        std::is_same<typename char_type<S>::type, char>::value
    >::type
> file_handle_type create_file(const S& path, access_mode mode) {
    return ::CreateFileA(...);
}

template <
    class S,
    class = typename std::enable_if<
        std::is_same<typename char_type<S>::type, wchar_t>::value
    >::type
> file_handle_type create_file(const S& path, access_mode mode) {
    return ::CreateFileW(...);
}

And where CreateFileA had preivously been used, we would now call create_file(...).