ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
SequenceStack.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File SequenceStack.h --------------------------*/
3/*--------------------------------------------------------------------------*/
28/*--------------------------------------------------------------------------*/
29/*----------------------------- DEFINITIONS --------------------------------*/
30/*--------------------------------------------------------------------------*/
31
32#ifndef __ADS_SequenceStack
33 #define __ADS_SequenceStack
34/* self-identification: #endif constant */
35
36/*--------------------------------------------------------------------------*/
37/*------------------------------ INCLUDES ----------------------------------*/
38/*--------------------------------------------------------------------------*/
39
40#include "ADS/ADT.h"
41#include "ADS/Contract.h"
42
43#include <ranges>
44
45/*--------------------------------------------------------------------------*/
46/*--------------------------- NAMESPACE ------------------------------------*/
47/*--------------------------------------------------------------------------*/
48
49namespace ADS
50{
51
52/*--------------------------------------------------------------------------*/
53/*-------------------------- CLASS SequenceStack ---------------------------*/
54/*--------------------------------------------------------------------------*/
55
57template< Sequence S >
59{
60
61/*--------------------------------------------------------------------------*/
62 public:
63 using Item = typename S::Item;
64
66 [[nodiscard]] bool empty( void ) const;
67
78 [[nodiscard]] const Item & top( void ) const;
79
93 Item pop( void );
94
105 void push( const Item & v );
106
108 [[nodiscard]] bool operator==( const SequenceStack & o ) const = default;
109
110/*------------------------- THE STANDARD INTERFACE -------------------------*/
111
112 // a constant view of the items from the top to the bottom, with the
113 // iterators of the sequence, when it has them
114
116 [[nodiscard]] auto begin( void ) const
117 requires std::ranges::range< const S >
118 {
119 return( std::ranges::cbegin( f_s ) );
120 }
121
123 [[nodiscard]] auto end( void ) const
124 requires std::ranges::range< const S >
125 {
126 return( std::ranges::cend( f_s ) );
127 }
128
129/*--------------------------------------------------------------------------*/
130 private:
131 S f_s;
132
133 }; // end( class SequenceStack )
134
135/*--------------------------------------------------------------------------*/
136
137} // end( namespace ADS )
138
139/*--------------------------------------------------------------------------*/
140/*-------------------------- IMPLEMENTATION --------------------------------*/
141/*--------------------------------------------------------------------------*/
142
143#include "ADS/stack/impl/SequenceStack.tpp"
144
145/*--------------------------------------------------------------------------*/
146
147#endif /* SequenceStack.h included */
148
149/*--------------------------------------------------------------------------*/
150/*------------------------ End File SequenceStack.h ------------------------*/
151/*--------------------------------------------------------------------------*/
The abstract data types of the book, as concepts of C++20: SEQUENCE, SET and DICTIONARY (chapter 3),...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
a STACK simulated with the operations of a SEQUENCE S, the top first
Definition SequenceStack.h:59
typename S::Item Item
the type of the items
Definition SequenceStack.h:63
auto end(void) const
the iterator of the sequence past the item at the bottom
Definition SequenceStack.h:123
Item pop(void)
removes the item on top and returns it, remove( head() )
bool empty(void) const
true if there is no item, empty() of the sequence
auto begin(void) const
the iterator of the sequence on the item on top
Definition SequenceStack.h:116
bool operator==(const SequenceStack &o) const =default
the same items in the same order, those of the sequences
void push(const Item &v)
puts on top, insert( head() , v )
const Item & top(void) const
the item on top, read( head() )
Definition ADT.h:96