From 9a481d542c2745989453fba5805c0cad5fe384c2 Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Mon, 18 Jul 2016 15:26:19 +0100 Subject: [PATCH 1/2] FileStream constructor should be explicit --- util/file_stream.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/file_stream.hh b/util/file_stream.hh index be26a0921..aa73a5888 100644 --- a/util/file_stream.hh +++ b/util/file_stream.hh @@ -17,7 +17,7 @@ namespace util { class FileStream : public FakeOStream { public: - FileStream(int out = -1, std::size_t buffer_size = 8192) + explicit FileStream(int out = -1, std::size_t buffer_size = 8192) : buf_(util::MallocOrThrow(std::max(buffer_size, kToStringMaxBytes))), current_(static_cast(buf_.get())), end_(current_ + std::max(buffer_size, kToStringMaxBytes)), From f365d277eeb759472548bbc681acc869463beb2d Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Mon, 18 Jul 2016 15:31:57 +0100 Subject: [PATCH 2/2] Move semantics for FileStream --- util/file_stream.hh | 7 +++++++ util/scoped.hh | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/util/file_stream.hh b/util/file_stream.hh index aa73a5888..46360595b 100644 --- a/util/file_stream.hh +++ b/util/file_stream.hh @@ -23,6 +23,13 @@ class FileStream : public FakeOStream { end_(current_ + std::max(buffer_size, kToStringMaxBytes)), fd_(out) {} +#if __cplusplus >= 201103L + FileStream(FileStream &&from) noexcept : buf_(std::move(from.buf_)), current_(from.current_), end_(from.end_), fd_(from.fd_) { + from.end_ = reinterpret_cast(from.buf_.get()); + from.current_ = from.end_; + } +#endif + ~FileStream() { flush(); } diff --git a/util/scoped.hh b/util/scoped.hh index f4591d439..23782b626 100644 --- a/util/scoped.hh +++ b/util/scoped.hh @@ -53,9 +53,15 @@ template class scoped_base { protected: T *p_; +#if __cplusplus >= 201103L + public: + scoped_base(const scoped_base &) = delete; + scoped_base &operator=(const scoped_base &) = delete; +#else private: scoped_base(const scoped_base &); scoped_base &operator=(const scoped_base &); +#endif }; template class scoped : public scoped_base {