From 7ebcbee1e11c72967d5f3a9325f170ec5d7c146a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=91=D0=B0=D1=80?= =?utf8?q?=D0=B0=D0=BD=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2/AI=20Tools=20Lab=20/S?= =?utf8?q?RR/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 9 Oct 2019 20:07:00 +0300 Subject: [PATCH] [adtidas] Reformat using clang-format (#8013) * Reformat the component using clang-format. * Enable format checking. Signed-off-by: Sergei Barannikov --- compiler/adtidas/.FORMATDENY | 0 compiler/adtidas/include/adtidas/SmallVector.h | 78 ++++++++++++++------------ 2 files changed, 41 insertions(+), 37 deletions(-) delete mode 100644 compiler/adtidas/.FORMATDENY diff --git a/compiler/adtidas/.FORMATDENY b/compiler/adtidas/.FORMATDENY deleted file mode 100644 index e69de29..0000000 diff --git a/compiler/adtidas/include/adtidas/SmallVector.h b/compiler/adtidas/include/adtidas/SmallVector.h index 1ba48da..a6ee47e 100644 --- a/compiler/adtidas/include/adtidas/SmallVector.h +++ b/compiler/adtidas/include/adtidas/SmallVector.h @@ -14,14 +14,15 @@ * limitations under the License. */ -#ifndef _NNC_CORE_SMALL_VECTOR_H -#define _NNC_CORE_SMALL_VECTOR_H +#ifndef _ADTIDAS_SMALL_VECTOR_H_ +#define _ADTIDAS_SMALL_VECTOR_H_ #include #include #include -namespace adt { +namespace adt +{ /** * @brief vector with cheap memory allocation @@ -29,28 +30,30 @@ namespace adt { * @tparam Capacity maximum number of elements * @note much like std::array, but tracks number of used elements. Stored in stack */ -template -class small_vector { +template class small_vector +{ public: using value_type = T; - using reference = T&; - using iterator = T*; + using reference = T &; + using iterator = T *; using size_type = size_t; - template - small_vector(It begin, It end) : _size(std::distance(begin, end)) { + template small_vector(It begin, It end) : _size(std::distance(begin, end)) + { assert(_size <= Capacity); std::copy(begin, end, this->begin()); } - explicit small_vector(size_t size, value_type initializer = value_type()) : _size(size) { + explicit small_vector(size_t size, value_type initializer = value_type()) : _size(size) + { assert(_size <= Capacity); std::fill(begin(), end(), initializer); } explicit small_vector() : _size(0) {} - small_vector(std::initializer_list&& l) : _size(l.size()) { + small_vector(std::initializer_list l) : _size(l.size()) + { assert(_size <= Capacity); std::copy(std::begin(l), std::end(l), begin()); } @@ -58,24 +61,22 @@ public: /** * @return current size */ - inline size_t size() const noexcept { - return _size; - } + inline size_t size() const noexcept { return _size; } /** * @return maximum number of elements this vector can hold */ - constexpr size_t capacity() const { - return Capacity; - } + constexpr size_t capacity() const { return Capacity; } /** - * @brief resize to given new size - * @note if new size is greater than current size, new elements are default-initialized - */ - void resize(size_t new_size) noexcept { + * @brief resize to given new size + * @note if new size is greater than current size, new elements are default-initialized + */ + void resize(size_t new_size) noexcept + { assert(new_size <= Capacity); - if (new_size > _size) { + if (new_size > _size) + { std::fill(_storage + _size, _storage + new_size, T()); } _size = new_size; @@ -84,7 +85,8 @@ public: /** * @return reference to the element at position idx */ - inline reference operator[](size_t idx) noexcept { + inline reference operator[](size_t idx) noexcept + { assert(idx < _size); return _storage[idx]; } @@ -92,25 +94,24 @@ public: /** * @return value of element at position idx */ - inline constexpr value_type operator[](size_t idx) const noexcept { - //assert on the same line since c++11 does not allow multi-line constexpr functions + inline constexpr value_type operator[](size_t idx) const noexcept + { + // assert on the same line since c++11 does not allow multi-line constexpr functions return assert(idx < _size), _storage[idx]; } - inline iterator begin() noexcept { - return std::begin(_storage); - } + inline iterator begin() noexcept { return std::begin(_storage); } - inline iterator end() noexcept { - return _storage + _size; - } + inline iterator end() noexcept { return _storage + _size; } - inline void push_back(const value_type& e) noexcept { + inline void push_back(const value_type &e) noexcept + { assert(_size < Capacity); _storage[_size++] = e; } - inline void push_back(value_type&& e) noexcept { + inline void push_back(value_type &&e) noexcept + { assert(_size < Capacity); _storage[_size++] = std::move(e); } @@ -121,14 +122,17 @@ private: }; template -bool operator==(const small_vector& lhs, const small_vector& rhs) { - if (lhs.size() != rhs.size()) { +bool operator==(const small_vector &lhs, const small_vector &rhs) +{ + if (lhs.size() != rhs.size()) + { return false; } bool equal = true; size_t end = lhs.size(); - for (size_t i = 0; i < end; ++i) { + for (size_t i = 0; i < end; ++i) + { equal &= (lhs[i] == rhs[i]); } @@ -137,4 +141,4 @@ bool operator==(const small_vector& lhs, const small_vector