- Stack() :
- m_data(0),
- m_end(0),
- m_capacity(0)
- {
- }
- Stack(const Type& value) :
- m_data(0),
- m_end(0),
- m_capacity(0)
- {
- push(value);
- }
- Stack(const Stack& other) :
- DefaultAllocator<Type>(other)
- {
- m_capacity = other.m_capacity;
- m_data = Allocator::allocate(m_capacity);
- construct(other);
- m_end = m_data + other.size();
- }
- ~Stack()
- {
- destroy();
- Allocator::deallocate(m_data, m_capacity);
- }
-
- const_iterator begin() const
- {
- return m_data;
- }
- const_iterator end() const
- {
- return m_end;
- }
-
- bool empty() const
- {
- return end() == begin();
- }
- void clear()
- {
- destroy();
- m_end = m_data;
- }
-
- std::size_t size() const
- {
- return m_end - m_data;
- }
- Type operator[](const std::size_t i) const
- {
- return m_data[i];
- }
- /// \brief Pushes \p value onto the stack at the top element. If reserved storage is insufficient for the new element, this will invalidate all iterators.
- void push(const Type& value)
- {
- if(size() == m_capacity)
- {
- insert_overflow(value);
- }
- else
- {
- insert(value);
- }
- }
- /// \brief Removes the top element of the stack.
- void pop()
- {
- Allocator::destroy(--m_end);
- }
- /// \brief Returns the top element of the mutable stack.
- Type& top()
- {
- return *(m_end-1);
- }
- /// \brief Returns the top element of the non-mutable stack.
- const Type& top() const
- {
- return *(m_end-1);
- }
- /// \brief Returns the element below the top element of the mutable stack.
- Type& parent()
- {
- return *(m_end-2);
- }
- /// \brief Returns the element below the top element of the non-mutable stack.
- const Type& parent() const
- {
- return *(m_end-2);
- }
- /// \brief Swaps the values of this stack and \p other.
- void swap(Stack& other)
- {
- std::swap(m_data, other.m_data);
- std::swap(m_end, other.m_end);
- std::swap(m_capacity, other.m_capacity);
- }
+Stack() :
+ m_data( 0 ),
+ m_end( 0 ),
+ m_capacity( 0 ){
+}
+Stack( const Type& value ) :
+ m_data( 0 ),
+ m_end( 0 ),
+ m_capacity( 0 ){
+ push( value );
+}
+Stack( const Stack& other ) :
+ DefaultAllocator<Type>( other ){
+ m_capacity = other.m_capacity;
+ m_data = Allocator::allocate( m_capacity );
+ construct( other );
+ m_end = m_data + other.size();
+}
+~Stack(){
+ destroy();
+ Allocator::deallocate( m_data, m_capacity );
+}
+
+const_iterator begin() const {
+ return m_data;
+}
+const_iterator end() const {
+ return m_end;
+}
+
+bool empty() const {
+ return end() == begin();
+}
+void clear(){
+ destroy();
+ m_end = m_data;
+}
+
+std::size_t size() const {
+ return m_end - m_data;
+}
+Type operator[]( const std::size_t i ) const {
+ return m_data[i];
+}
+/// \brief Pushes \p value onto the stack at the top element. If reserved storage is insufficient for the new element, this will invalidate all iterators.
+void push( const Type& value ){
+ if ( size() == m_capacity ) {
+ insert_overflow( value );
+ }
+ else
+ {
+ insert( value );
+ }
+}
+/// \brief Removes the top element of the stack.
+void pop(){
+ Allocator::destroy( --m_end );
+}
+/// \brief Returns the top element of the mutable stack.
+Type& top(){
+ return *( m_end - 1 );
+}
+/// \brief Returns the top element of the non-mutable stack.
+const Type& top() const {
+ return *( m_end - 1 );
+}
+/// \brief Returns the element below the top element of the mutable stack.
+Type& parent(){
+ return *( m_end - 2 );
+}
+/// \brief Returns the element below the top element of the non-mutable stack.
+const Type& parent() const {
+ return *( m_end - 2 );
+}
+/// \brief Swaps the values of this stack and \p other.
+void swap( Stack& other ){
+ std::swap( m_data, other.m_data );
+ std::swap( m_end, other.m_end );
+ std::swap( m_capacity, other.m_capacity );
+}