Console Library
8.0.0
A header-only library that makes C++ simple
Toggle main menu visibility
Loading...
Searching...
No Matches
adapter.h
Go to the documentation of this file.
1
11
12
/*
13
Copyright (c) 2026 MrXie1109
14
15
Permission is hereby granted, free of charge, to any person obtaining a copy
16
of this software and associated documentation files (the "Software"), to deal
17
in the Software without restriction, including without limitation the rights
18
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
copies of the Software, and to permit persons to whom the Software is
20
furnished to do so, subject to the following conditions:
21
22
The above copyright notice and this permission notice shall be included in all
23
copies or substantial portions of the Software.
24
25
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
SOFTWARE.
32
*/
33
34
#pragma once
35
#include <deque>
36
#include <iostream>
37
#include <queue>
38
#include <stack>
39
#include <string>
40
#include <utility>
41
#include <vector>
42
43
namespace
console
{
58
template
<
class
T,
class
Container = std::deque<T>>
59
class
Stack
:
public
std::stack<T, Container> {
60
using
base_type
= std::stack<T, Container>;
61
62
public
:
64
using
base_type::stack;
65
74
typename
base_type::value_type
pop
() {
75
auto
top = std::move(base_type::top());
76
base_type::pop();
77
return
top;
78
}
79
87
template
<
class
CharT,
class
Traits>
88
friend
std::basic_ostream<CharT, Traits> &
89
operator<<
(std::basic_ostream<CharT, Traits> &os,
const
Stack
&stack) {
90
return
os << stack.c;
91
}
92
};
93
108
template
<
class
T,
class
Container = std::deque<T>>
109
class
Queue
:
public
std::queue<T, Container> {
110
using
base_type
= std::queue<T, Container>;
111
112
public
:
114
using
base_type::queue;
115
124
typename
base_type::value_type
pop
() {
125
auto
top = std::move(base_type::front());
126
base_type::pop();
127
return
top;
128
}
129
137
template
<
class
CharT,
class
Traits>
138
friend
std::basic_ostream<CharT, Traits> &
139
operator<<
(std::basic_ostream<CharT, Traits> &os,
const
Queue
&queue) {
140
return
os << queue.c;
141
}
142
};
143
160
template
<
class
T,
161
class
Container = std::vector<T>,
162
class
Compare = std::less<T>>
163
class
PriorityQueue
:
public
std::priority_queue<T, Container, Compare> {
164
using
base_type
= std::priority_queue<T, Container, Compare>;
165
166
public
:
168
using
base_type::priority_queue;
169
178
typename
base_type::value_type
pop
() {
179
auto
top = std::move(base_type::top());
180
base_type::pop();
181
return
top;
182
}
183
191
template
<
class
CharT,
class
Traits>
192
friend
std::basic_ostream<CharT, Traits> &
operator<<
(
193
std::basic_ostream<CharT, Traits> &os,
const
PriorityQueue
&pq) {
194
return
os << pq.c;
195
}
196
};
197
}
console::PriorityQueue
优先队列容器适配器,扩展自 std::priority_queue。
Definition
adapter.h:163
console::PriorityQueue::operator<<
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const PriorityQueue &pq)
重载输出流运算符,将栈的内容输出到流中。
Definition
adapter.h:192
console::PriorityQueue::pop
base_type::value_type pop()
弹出优先级最高的元素并返回其值。
Definition
adapter.h:178
console::PriorityQueue::base_type
std::priority_queue< T, Container, Compare > base_type
Definition
adapter.h:164
console::Queue
队列容器适配器,扩展自 std::queue。
Definition
adapter.h:109
console::Queue::operator<<
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const Queue &queue)
重载输出流运算符,将栈的内容输出到流中。
Definition
adapter.h:139
console::Queue::base_type
std::queue< T, Container > base_type
Definition
adapter.h:110
console::Queue::pop
base_type::value_type pop()
弹出队首元素并返回其值。
Definition
adapter.h:124
console::Stack
栈容器适配器,扩展自 std::stack。
Definition
adapter.h:59
console::Stack::pop
base_type::value_type pop()
弹出栈顶元素并返回其值。
Definition
adapter.h:74
console::Stack::base_type
std::stack< T, Container > base_type
Definition
adapter.h:60
console::Stack::operator<<
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const Stack &stack)
重载输出流运算符,将栈的内容输出到流中。
Definition
adapter.h:89
console
本库所有组件所在的顶层命名空间。
include
container
adapter.h
Generated on
for Console Library by
1.18.0