Add a move ctor to Array.

This commit is contained in:
Victor Zverovich 2014-04-24 07:30:39 -07:00
parent 81217a2cc0
commit b22493ce7e

View File

@ -73,6 +73,12 @@
(FMT_GCC_VERSION >= 404 && __cplusplus >= 201103) || _MSC_VER >= 1800) (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103) || _MSC_VER >= 1800)
#endif #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). // Define FMT_USE_NOEXCEPT to make format use noexcept (C++11 feature).
#if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ #if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
(FMT_GCC_VERSION >= 408 && __cplusplus >= 201103) (FMT_GCC_VERSION >= 408 && __cplusplus >= 201103)
@ -137,6 +143,20 @@ class Array {
if (ptr_ != data_) delete [] ptr_; 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. // Returns the size of this array.
std::size_t size() const { return size_; } std::size_t size() const { return size_; }