31 #ifndef OPM_FAST_SMALL_VECTOR_HPP
32 #define OPM_FAST_SMALL_VECTOR_HPP
45 template <
typename ValueType,
unsigned N>
53 dataPtr_ = smallBuf_.data();
68 std::fill(dataPtr_, dataPtr_ + size_, value);
75 dataPtr_ = smallBuf_.data();
84 dataPtr_ = smallBuf_.data();
86 (*this) = std::move(other);
92 if (dataPtr_ != smallBuf_.data())
100 if (dataPtr_ != smallBuf_.data() && dataPtr_ != other.dataPtr_)
105 smallBuf_ = std::move(other.smallBuf_);
106 dataPtr_ = smallBuf_.data();
109 dataPtr_ = other.dataPtr_;
111 other.dataPtr_ =
nullptr;
123 smallBuf_ = other.smallBuf_;
124 dataPtr_ = smallBuf_.data();
126 else if (dataPtr_ != other.dataPtr_) {
127 if (dataPtr_ != smallBuf_.data())
129 dataPtr_ =
new ValueType[size_];
131 std::copy(other.dataPtr_, other.dataPtr_ + size_, dataPtr_);
139 {
return dataPtr_[idx]; }
143 {
return dataPtr_[idx]; }
150 void init_(
size_t numElem)
155 dataPtr_ =
new ValueType[size_];
157 dataPtr_ = smallBuf_.data();
160 std::array<ValueType, N> smallBuf_;
An implementation of vector/array based on small object optimization.
Definition: FastSmallVector.hpp:47
FastSmallVector()
default constructor
Definition: FastSmallVector.hpp:50
FastSmallVector & operator=(const FastSmallVector &other)
copy assignment
Definition: FastSmallVector.hpp:118
size_t size() const
number of the element
Definition: FastSmallVector.hpp:146
const ValueType & operator[](size_t idx) const
const access the idx th element
Definition: FastSmallVector.hpp:142
FastSmallVector(FastSmallVector &&other)
move constructor
Definition: FastSmallVector.hpp:81
FastSmallVector(const size_t numElem, const ValueType value)
constructor based on the number of the element, and all the elements will have the same value
Definition: FastSmallVector.hpp:64
~FastSmallVector()
destructor
Definition: FastSmallVector.hpp:90
FastSmallVector(const size_t numElem)
constructor based on the number of the element
Definition: FastSmallVector.hpp:57
FastSmallVector(const FastSmallVector &other)
copy constructor
Definition: FastSmallVector.hpp:72
FastSmallVector & operator=(FastSmallVector &&other)
move assignment
Definition: FastSmallVector.hpp:98
ValueType & operator[](size_t idx)
access the idx th element
Definition: FastSmallVector.hpp:138