From 943f6c3129b351946e81ef08a6a0531f828a7812 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 12 Aug 2019 13:20:38 +0200 Subject: Add few fdstream constructor overloads --- libbutl/fdstream.cxx | 8 +++--- libbutl/fdstream.ixx | 56 ++++++++++++++++++++++++++++++++------- libbutl/fdstream.mxx | 74 +++++++++++++++++++++++++++++++++++----------------- 3 files changed, 100 insertions(+), 38 deletions(-) (limited to 'libbutl') diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx index 9bc62d9..053ef13 100644 --- a/libbutl/fdstream.cxx +++ b/libbutl/fdstream.cxx @@ -785,13 +785,13 @@ namespace butl // ifdstream:: ifdstream (const char* f, openmode m, iostate e) - : ifdstream (f, translate_mode (m | in), e) // Delegate. + : ifdstream (f, translate_mode (m | in), e) { } ifdstream:: ifdstream (const char* f, fdopen_mode m, iostate e) - : ifdstream (fdopen (f, m | fdopen_mode::in), e) // Delegate. + : ifdstream (fdopen (f, m | fdopen_mode::in), e) { } @@ -886,13 +886,13 @@ namespace butl // ofdstream:: ofdstream (const char* f, openmode m, iostate e) - : ofdstream (f, translate_mode (m | out), e) // Delegate. + : ofdstream (f, translate_mode (m | out), e) { } ofdstream:: ofdstream (const char* f, fdopen_mode m, iostate e) - : ofdstream (fdopen (f, m | fdopen_mode::out), e) // Delegate. + : ofdstream (fdopen (f, m | fdopen_mode::out), e) { } diff --git a/libbutl/fdstream.ixx b/libbutl/fdstream.ixx index 5c325b0..531f196 100644 --- a/libbutl/fdstream.ixx +++ b/libbutl/fdstream.ixx @@ -63,7 +63,7 @@ namespace butl inline ifdstream:: ifdstream (iostate e) - : ifdstream (auto_fd (), e) // Delegate. + : ifdstream (auto_fd (), e) { } @@ -79,25 +79,43 @@ namespace butl inline ifdstream:: ifdstream (const std::string& f, openmode m, iostate e) - : ifdstream (f.c_str (), m, e) // Delegate. + : ifdstream (f.c_str (), m, e) { } inline ifdstream:: ifdstream (const path& f, openmode m, iostate e) - : ifdstream (f.string (), m, e) // Delegate. + : ifdstream (f.string (), m, e) { } inline ifdstream:: ifdstream (const std::string& f, fdopen_mode m, iostate e) - : ifdstream (f.c_str (), m, e) // Delegate. + : ifdstream (f.c_str (), m, e) { } inline ifdstream:: ifdstream (const path& f, fdopen_mode m, iostate e) - : ifdstream (f.string (), m, e) // Delegate. + : ifdstream (f.string (), m, e) + { + } + + inline ifdstream:: + ifdstream (const char* f, iostate e) + : ifdstream (f, in, e) + { + } + + inline ifdstream:: + ifdstream (const std::string& f, iostate e) + : ifdstream (f, in, e) + { + } + + inline ifdstream:: + ifdstream (const path& f, iostate e) + : ifdstream (f, in, e) { } @@ -165,7 +183,7 @@ namespace butl inline ofdstream:: ofdstream (iostate e) - : ofdstream (auto_fd (), e) // Delegate. + : ofdstream (auto_fd (), e) { } @@ -179,25 +197,43 @@ namespace butl inline ofdstream:: ofdstream (const std::string& f, openmode m, iostate e) - : ofdstream (f.c_str (), m, e) // Delegate. + : ofdstream (f.c_str (), m, e) { } inline ofdstream:: ofdstream (const path& f, openmode m, iostate e) - : ofdstream (f.string (), m, e) // Delegate. + : ofdstream (f.string (), m, e) { } inline ofdstream:: ofdstream (const std::string& f, fdopen_mode m, iostate e) - : ofdstream (f.c_str (), m, e) // Delegate. + : ofdstream (f.c_str (), m, e) { } inline ofdstream:: ofdstream (const path& f, fdopen_mode m, iostate e) - : ofdstream (f.string (), m, e) // Delegate. + : ofdstream (f.string (), m, e) + { + } + + inline ofdstream:: + ofdstream (const char* f, iostate e) + : ofdstream (f, out, e) + { + } + + inline ofdstream:: + ofdstream (const std::string& f, iostate e) + : ofdstream (f, out, e) + { + } + + inline ofdstream:: + ofdstream (const path& f, iostate e) + : ofdstream (f, out, e) { } diff --git a/libbutl/fdstream.mxx b/libbutl/fdstream.mxx index a3d9039..49c5dae 100644 --- a/libbutl/fdstream.mxx +++ b/libbutl/fdstream.mxx @@ -442,44 +442,57 @@ LIBBUTL_MODEXPORT namespace butl // Create an unopened object. // explicit - ifdstream (iostate e = badbit | failbit); + ifdstream (iostate = badbit | failbit); explicit ifdstream (auto_fd&&, - iostate e = badbit | failbit, + iostate = badbit | failbit, std::uint64_t pos = 0); ifdstream (auto_fd&&, fdstream_mode m, - iostate e = badbit | failbit, + iostate = badbit | failbit, std::uint64_t pos = 0); explicit ifdstream (const char*, - openmode = in, - iostate e = badbit | failbit); + iostate = badbit | failbit); explicit ifdstream (const std::string&, - openmode = in, - iostate e = badbit | failbit); + iostate = badbit | failbit); explicit ifdstream (const path&, - openmode = in, - iostate e = badbit | failbit); + iostate = badbit | failbit); + + // @@ In some implementations (for example, MSVC), iostate and openmode + // (and/or their respective constants) are not distinct enough which + // causes overload resolution errors. + // + ifdstream (const char*, + openmode, + iostate /*= badbit | failbit*/); + + ifdstream (const std::string&, + openmode, + iostate /*= badbit | failbit*/); + + ifdstream (const path&, + openmode, + iostate /*= badbit | failbit*/); ifdstream (const char*, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ifdstream (const std::string&, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ifdstream (const path&, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ~ifdstream () override; @@ -548,44 +561,57 @@ LIBBUTL_MODEXPORT namespace butl // Create an unopened object. // explicit - ofdstream (iostate e = badbit | failbit); + ofdstream (iostate = badbit | failbit); explicit ofdstream (auto_fd&&, - iostate e = badbit | failbit, + iostate = badbit | failbit, std::uint64_t pos = 0); ofdstream (auto_fd&&, fdstream_mode m, - iostate e = badbit | failbit, + iostate = badbit | failbit, std::uint64_t pos = 0); explicit ofdstream (const char*, - openmode = out, - iostate e = badbit | failbit); + iostate = badbit | failbit); explicit ofdstream (const std::string&, - openmode = out, - iostate e = badbit | failbit); + iostate = badbit | failbit); explicit ofdstream (const path&, - openmode = out, - iostate e = badbit | failbit); + iostate = badbit | failbit); + + // @@ In some implementations (for example, MSVC), iostate and openmode + // (and/or their respective constants) are not distinct enough which + // causes overload resolution errors. + // + ofdstream (const char*, + openmode, + iostate /*= badbit | failbit*/); + + ofdstream (const std::string&, + openmode, + iostate /*= badbit | failbit*/); + + ofdstream (const path&, + openmode, + iostate /*= badbit | failbit*/); ofdstream (const char*, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ofdstream (const std::string&, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ofdstream (const path&, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ~ofdstream () override; -- cgit v1.1