From ce7ecdb7afb207dadf55c8ae457e14aa44e7f537 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 11 Apr 2022 12:16:05 -0700 Subject: [PATCH] Replace conditional compilation with SFINAE --- include/fmt/ostream.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 5f2141fec507..b35725a3e2e1 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -55,8 +55,18 @@ template FILE* get_file(std::basic_filebuf&) { return nullptr; } -#if FMT_MSC_VER -FILE* get_file(std::filebuf& buf); +struct dummy_filebuf { + FILE* _Myfile; +}; +template struct ms_filebuf { + using type = dummy_filebuf; +}; +template struct ms_filebuf { + using type = T; +}; +using filebuf_type = ms_filebuf::type; + +FILE* get_file(filebuf_type& buf); // Generate a unique explicit instantion in every translation unit using a tag // type in an anonymous namespace. @@ -65,12 +75,11 @@ struct filebuf_access_tag {}; } // namespace template class filebuf_access { - friend FILE* get_file(std::filebuf& buf) { return buf.*file; } + friend FILE* get_file(filebuf_type& buf) { return buf.*file; } }; template class filebuf_access; -#endif + decltype(&filebuf_type::_Myfile), + &filebuf_type::_Myfile>; inline bool write(std::filebuf& buf, fmt::string_view data) { print(get_file(buf), data);