diff --git a/vector.h b/vector.h index 6980cfac..315e2fec 100644 --- a/vector.h +++ b/vector.h @@ -30,10 +30,13 @@ SOFTWARE. #define __ETL_VECTOR__ #include +#include #include #include "ivector.h" #include "container.h" +#include "alignment.h" +#include "array.h" //***************************************************************************** ///\defgroup vector vector @@ -62,7 +65,7 @@ namespace etl /// Constructor. //************************************************************************* vector() - : ivector(buffer, MAX_SIZE) + : ivector(reinterpret_cast(&buffer.value[0]), MAX_SIZE) { } @@ -71,7 +74,7 @@ namespace etl ///\param initialSize The initial size of the vector. //************************************************************************* explicit vector(size_t initialSize) - : ivector(buffer, MAX_SIZE) + : ivector(reinterpret_cast(&buffer.value[0]), MAX_SIZE) { ivector::resize(initialSize); } @@ -82,7 +85,7 @@ namespace etl ///\param value The value to fill the vector with. //************************************************************************* vector(size_t initialSize, typename ivector::parameter_t value) - : ivector(buffer, MAX_SIZE) + : ivector(reinterpret_cast(&buffer.value[0]), MAX_SIZE) { ivector::resize(initialSize, value); } @@ -95,7 +98,7 @@ namespace etl //************************************************************************* template vector(TIterator first, TIterator last) - : ivector(buffer, MAX_SIZE) + : ivector(reinterpret_cast(&buffer.value[0]), MAX_SIZE) { ivector::assign(first, last); } @@ -105,33 +108,18 @@ namespace etl //************************************************************************* vector& operator = (const vector& rhs) { - ivector::assign(rhs.cbegin(), rhs.cend()); + if (&rhs != this) + { + ivector::assign(rhs.cbegin(), rhs.cend()); + } return *this; } - //************************************************************************* - /// Swap - //************************************************************************* - void swap(vector& other) - { - std::swap_ranges(etl::begin(buffer), etl::end(buffer), etl::begin(other.buffer)); - std::swap(this->current_size, other.current_size); - } - private: - T buffer[MAX_SIZE]; ///, T> buffer; }; - - //************************************************************************* - /// Swap - //************************************************************************* - template - void swap(etl::vector& first, etl::vector& second) - { - first.swap(second); - } } #endif diff --git a/vector_base.h b/vector_base.h index 79d19fcc..d1729c97 100644 --- a/vector_base.h +++ b/vector_base.h @@ -163,46 +163,6 @@ namespace etl return max_size() - size(); } - //************************************************************************* - /// Clears the vector. - //************************************************************************* - void clear() - { - current_size = 0; - } - - //************************************************************************* - /// Increases the size of the vector by one, but does not initialise the new element. - /// If ETL_THROW_EXCEPTIONS is defined, throws a vector_full if the vector is already full. - //************************************************************************* - void push_back() - { -#ifdef ETL_THROW_EXCEPTIONS - if (current_size == MAX_SIZE) - { - throw vector_full(); - } -#else - { - error_handler::error(vector_full()); - } -#endif - - ++current_size; - } - - //************************************************************************* - /// Removes an element from the end of the vector. - /// Does nothing if the vector is empty. - //************************************************************************* - void pop_back() - { - if (current_size > 0) - { - --current_size; - } - } - protected: //*************************************************************************