From 365a80c9acaab2a7d23a40a3add7071f9b739f85 Mon Sep 17 00:00:00 2001 From: mandreyel Date: Thu, 18 Oct 2018 19:30:41 +0200 Subject: [PATCH] Fix char* being an invalid path type --- include/mio/detail/string_util.hpp | 15 +++++++++++++-- test/test.cpp | 6 +++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/mio/detail/string_util.hpp b/include/mio/detail/string_util.hpp index 31cae45..c716325 100644 --- a/include/mio/detail/string_util.hpp +++ b/include/mio/detail/string_util.hpp @@ -26,10 +26,21 @@ namespace mio { namespace detail { -template struct is_c_str +template +struct is_c_str { static constexpr bool value = std::is_same< - const char*, typename std::decay::type + char*, + // TODO: I'm so sorry for this... Can this be made cleaner? + typename std::add_pointer< + typename std::remove_cv< + typename std::remove_pointer< + typename std::decay< + String + >::type + >::type + >::type + >::type >::value; }; diff --git a/test/test.cpp b/test/test.cpp index acfd33c..aacae81 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -22,7 +22,11 @@ using mmap_source = mio::basic_mmap_source; int main() { - const char* path = "test-file"; + const char _path[] = "test-file"; + // Make sure mio compiles with non-const char* strings too. + const int path_len = sizeof(_path); + char* path = new char[path_len]; + std::copy(_path, _path + path_len, path); std::error_code error; // Fill buffer, then write it to file. std::string buffer(0x4000 - 250, 'M');