ADS
Algorithms and Data Structures
Toggle main menu visibility
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
49
namespace
ADS
50
{
51
52
/*--------------------------------------------------------------------------*/
53
/*-------------------------- CLASS SequenceStack ---------------------------*/
54
/*--------------------------------------------------------------------------*/
55
57
template
< Sequence S >
58
class
SequenceStack
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
/*--------------------------------------------------------------------------*/
ADT.h
The abstract data types of the book, as concepts of C++20: SEQUENCE, SET and DICTIONARY (chapter 3),...
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
ADS::SequenceStack
a STACK simulated with the operations of a SEQUENCE S, the top first
Definition
SequenceStack.h:59
ADS::SequenceStack::Item
typename S::Item Item
the type of the items
Definition
SequenceStack.h:63
ADS::SequenceStack::end
auto end(void) const
the iterator of the sequence past the item at the bottom
Definition
SequenceStack.h:123
ADS::SequenceStack::pop
Item pop(void)
removes the item on top and returns it, remove( head() )
ADS::SequenceStack::empty
bool empty(void) const
true if there is no item, empty() of the sequence
ADS::SequenceStack::begin
auto begin(void) const
the iterator of the sequence on the item on top
Definition
SequenceStack.h:116
ADS::SequenceStack::operator==
bool operator==(const SequenceStack &o) const =default
the same items in the same order, those of the sequences
ADS::SequenceStack::push
void push(const Item &v)
puts on top, insert( head() , v )
ADS::SequenceStack::top
const Item & top(void) const
the item on top, read( head() )
ADS
Definition
ADT.h:96
ADS
stack
SequenceStack.h
Generated by
1.17.0