/** * Copyright 2020 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MINDSPORE_LITE_INTERNAL_INCLUDE_VECTOR_H #define MINDSPORE_LITE_INTERNAL_INCLUDE_VECTOR_H #include #include #include #include #define DEFAULT_CAPACITY 4 struct MSTensor; struct Node; template class Vector { public: Vector(); explicit Vector(size_t size); Vector(size_t size, const T &value); Vector(const Vector &vector); ~Vector(); void clear(); void push_back(const T &elem); void push_back(T &&); void pop_back(); void insert(const T &elem, size_t index); T *begin(); const T *begin() const; T *end(); const T *end() const; T &front(); const T &front() const; T &back(); const T &back() const; T &at(size_t index); const T &at(size_t index) const; T &operator[](size_t index); const T &operator[](size_t index) const; T *data(); const T *data() const; size_t size() const; size_t capacity() const; bool empty() const; void erase(size_t index); void resize(size_t size); void reserve(size_t capacity); Vector &operator=(const Vector &v); private: size_t size_; size_t elem_size_; size_t capacity_; T *data_; }; template bool operator==(const Vector &lhs, const Vector &rhs) { if (lhs.size() != rhs.size()) { return false; } for (int i = 0; i < lhs.size(); ++i) { if (lhs[i] != rhs[i]) { return false; } } return true; } template bool operator!=(const Vector &lhs, const Vector &rhs) { return !(lhs == rhs); } #endif // MINDSPORE_LITE_INTERNAL_INCLUDE_VECTOR_H