diff options
author | Kenneth Heafield <github@kheafield.com> | 2020-02-25 18:53:44 +0300 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2020-02-25 18:53:44 +0300 |
commit | 0929c4d225a3ab85fef68d9f44200838d6561992 (patch) | |
tree | ff67c5ea8fbd24ff0e51a97dd55ac2694ca69ea8 /util | |
parent | 9554781b086fa2b23526d2ba2b497739c6baedc6 (diff) |
More modern fixed_array
Diffstat (limited to 'util')
-rw-r--r-- | util/fixed_array.hh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/util/fixed_array.hh b/util/fixed_array.hh index c67e8ed..3da9d13 100644 --- a/util/fixed_array.hh +++ b/util/fixed_array.hh @@ -71,6 +71,21 @@ template <class T> class FixedArray { */ ~FixedArray() { clear(); } +#if __cplusplus >= 201103L + FixedArray(FixedArray &&from) + : block_(std::move(from.block_)), + newed_end_(from.newed_end_) +# ifndef NDEBUG + , allocated_end_(from.allocated_end_) +# endif // NDEBUG + { + from.newed_end_ = NULL; +# ifndef NDEBUG + from.allocated_end_ = NULL; +# endif // NDEBUG + } +#endif // C++11 + /** Gets a pointer to the first object currently stored in this data structure. */ T *begin() { return static_cast<T*>(block_.get()); } @@ -122,6 +137,20 @@ template <class T> class FixedArray { * The memory backing the constructed object is managed by this data structure. * I miss C++11 variadic templates. */ +#if __cplusplus >= 201103L + template <typename... Construct> T *emplace_back(Construct&&... construct) { + T *ret = end(); + new (end()) T(construct...); + Constructed(); + return ret; + } + template <typename... Construct> T *push_back(Construct&&... construct) { + T *ret = end(); + new (end()) T(construct...); + Constructed(); + return ret; + } +#else void push_back() { new (end()) T(); Constructed(); @@ -138,6 +167,7 @@ template <class T> class FixedArray { new (end()) T(c, d); Constructed(); } +#endif void pop_back() { back().~T(); |