| 152 | |
| 153 | template <typename T> |
| 154 | class OwnedVector { |
| 155 | public: |
| 156 | MOVE_ONLY_WITH_DEFAULT_CONSTRUCTORS(OwnedVector); |
| 157 | OwnedVector(std::unique_ptr<T[]> data, size_t length) |
| 158 | : data_(std::move(data)), length_(length) { |
| 159 | DCHECK_IMPLIES(length_ > 0, data_ != nullptr); |
| 160 | } |
| 161 | |
| 162 | // Implicit conversion from {OwnedVector<U>} to {OwnedVector<T>}, instantiable |
| 163 | // if {std::unique_ptr<U>} can be converted to {std::unique_ptr<T>}. |
| 164 | // Can be used to convert {OwnedVector<T>} to {OwnedVector<const T>}. |
| 165 | template <typename U, |
| 166 | typename = typename std::enable_if<std::is_convertible< |
| 167 | std::unique_ptr<U>, std::unique_ptr<T>>::value>::type> |
| 168 | OwnedVector(OwnedVector<U>&& other) |
| 169 | : data_(std::move(other.data_)), length_(other.length_) { |
| 170 | STATIC_ASSERT(sizeof(U) == sizeof(T)); |
| 171 | other.length_ = 0; |
| 172 | } |
| 173 | |
| 174 | // Returns the length of the vector as a size_t. |
| 175 | constexpr size_t size() const { return length_; } |
| 176 | |
| 177 | // Returns whether or not the vector is empty. |
| 178 | constexpr bool empty() const { return length_ == 0; } |
no outgoing calls
no test coverage detected