From b22493ce7eba38f0bf5bdbaf5ab1b245d072683c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 24 Apr 2014 07:30:39 -0700 Subject: [PATCH] Add a move ctor to Array. --- format.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/format.h b/format.h index 8e428567..8c3d8da5 100644 --- a/format.h +++ b/format.h @@ -73,6 +73,12 @@ (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103) || _MSC_VER >= 1800) #endif +#ifndef FMT_USE_RVALUE_REFERENCES +# define FMT_USE_RVALUE_REFERENCES \ + (FMT_HAS_FEATURE(cxx_rvalue_references) || \ + (FMT_GCC_VERSION >= 403 && __cplusplus >= 201103) || _MSC_VER >= 1600) +#endif + // Define FMT_USE_NOEXCEPT to make format use noexcept (C++11 feature). #if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ (FMT_GCC_VERSION >= 408 && __cplusplus >= 201103) @@ -137,6 +143,20 @@ class Array { if (ptr_ != data_) delete [] ptr_; } +#if FMT_USE_RVALUE_REFERENCES + Array(Array &&other) + : size_(other.size_), + capacity_(other.capacity_) { + if (other.ptr_ == other.data_) { + ptr_ = data_; + std::copy(other.data_, other.data_ + size_, CheckPtr(data_, capacity_)); + } else { + ptr_ = other.ptr_; + other.ptr_ = 0; + } + } +#endif + // Returns the size of this array. std::size_t size() const { return size_; }