diff options
author | Andrew Geissler <andrewg@us.ibm.com> | 2016-03-11 08:46:44 -0600 |
---|---|---|
committer | A. P. Williams III <iawillia@us.ibm.com> | 2016-03-17 11:44:46 -0400 |
commit | 71cf29da3d308290ffd860fb263b4a05ddcb364a (patch) | |
tree | d8ff026c8cb8eb2d1beff2adadbbd118549c9e56 /src/include/vector | |
parent | 497d9f20a3bc65847435c82358b32cd2cd6d6951 (diff) | |
download | talos-hostboot-71cf29da3d308290ffd860fb263b4a05ddcb364a.tar.gz talos-hostboot-71cf29da3d308290ffd860fb263b4a05ddcb364a.zip |
Need to implement new Ctor for std::vector
Change-Id: Ia7743dc8d3a83b4be361626b1dea57f39e4dd483
RTC: 149398
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/21938
Tested-by: Jenkins Server
Reviewed-by: Christian R. Geddes <crgeddes@us.ibm.com>
Reviewed-by: A. P. Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/include/vector')
-rw-r--r-- | src/include/vector | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/src/include/vector b/src/include/vector index bbe33df47..da83776e8 100644 --- a/src/include/vector +++ b/src/include/vector @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2011,2015 */ +/* Contributors Listed Below - COPYRIGHT 2011,2016 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -39,6 +39,7 @@ #include <new> #include <algorithm> #include <assert.h> +#include <initializer_list> namespace std { @@ -122,6 +123,24 @@ namespace std } /** + * CTOR create a vector from initializer_list + * @param[in] init_list Initializer list + * @returns None. + * @post vector is created with init_list items + */ + vector(std::initializer_list<T> init_list) + : + iv_start(NULL), + iv_finish(NULL), + iv_end_of_storage(NULL) + { + for (auto&& i: init_list) + { + push_back(i); + } + } + + /** * CTOR create a vector from a container slice * @param[in] first iterator first in source sequence * @param[in] last iterator one past end of source sequence @@ -158,7 +177,7 @@ namespace std /** * Assignment operator. * @param[in] x A vector. - * @return A vector (for the purpose of multiple assigns). + * @return A vector (for the purpose of multiple assigns). * @pre None. * @post *this == x, this->capacity() == x.size(). * All previously obtained iterators are invalid. @@ -168,11 +187,11 @@ namespace std clear(); reserve(x.size()); iv_finish = ctor_copy(x.iv_start, x.iv_finish, iv_start); - return(*this); + return(*this); } - + // Iterators -------------------- - + /** * Get iterator to the first vector element * @return iterator of rist vector element @@ -181,7 +200,7 @@ namespace std */ __attribute__ ((always_inline)) iterator begin() - { + { return (iv_start); } @@ -193,7 +212,7 @@ namespace std */ __attribute__ ((always_inline)) const_iterator begin() const - { + { return (iv_start); } @@ -205,7 +224,7 @@ namespace std */ __attribute__ ((always_inline)) iterator end() - { + { return (iv_finish); } @@ -217,7 +236,7 @@ namespace std */ __attribute__ ((always_inline)) const_iterator end() const - { + { return (iv_finish); } @@ -267,7 +286,7 @@ namespace std /** * Get the number of elements the vector can hold before needing to reallocate storage. - * @return element capacity of the vector + * @return element capacity of the vector * @pre None. * @post None. */ @@ -310,7 +329,7 @@ namespace std __attribute__ ((always_inline)) reference operator[](size_type n) { - return(*(iv_start + n)); + return(*(iv_start + n)); } /** @@ -339,7 +358,7 @@ namespace std const_reference operator[](size_type index) const { assert(index < size()); - return(*(iv_start + index)); + return(*(iv_start + index)); } /** @@ -426,7 +445,7 @@ namespace std /* * Assign new content to the vector object * @param[in] n number of elements to assign - * @param[in] x reference to element to copy in + * @param[in] x reference to element to copy in */ void assign ( size_type n, const T& x) { @@ -444,7 +463,7 @@ namespace std * @post All previously obtained iterators are invalid. */ __attribute__ ((always_inline)) - void push_back(const T& x) + void push_back(const T& x) { reserve(size() + 1); new (iv_finish++) T(x); @@ -500,7 +519,7 @@ namespace std * @note element pointed to by last is not inserted. */ template <class InputIterator> - void insert (iterator position, InputIterator first, + void insert (iterator position, InputIterator first, InputIterator last); @@ -530,7 +549,7 @@ namespace std * @post All previously obtained iterators are invalid. * @note The element pointed to be last is not deleted. */ - iterator erase(iterator first, iterator last) + iterator erase(iterator first, iterator last) { assert(last >= first); assert(first >= iv_start); @@ -545,7 +564,7 @@ namespace std iv_finish->~T(); } return first; - } + } /** @@ -653,7 +672,7 @@ namespace std ++first; } } - + /** * Free all the storage allocated to this vector @@ -670,7 +689,7 @@ namespace std * @param[in] n, number of elements required */ __attribute__ ((always_inline)) - iterator allocate_storage(size_type n) + iterator allocate_storage(size_type n) { return (iterator) new uint8_t[n * sizeof(T)]; } @@ -794,7 +813,7 @@ void std::vector<T>::insert (iterator position, size_type n, const T& x) template <class T> template <class InputIterator> void std::vector<T>::insert (iterator position, - InputIterator first, + InputIterator first, InputIterator last) // Should only move storage if there is not room // InputIterators are not random access (eg. can't do diff = last - first) @@ -863,5 +882,5 @@ void std::vector<T>::resize(size_type n, T x) // else n == size() do nothing } -#endif +#endif /* vim: set filetype=cpp : */ |