我一直在使用 boost asio 库,其中大多数对象都需要 io_context 对象作为构造函数的参数。我已经阅读了 io_context 对象,根据文档,它指出它是
io_context 类为异步 I/O 对象的用户提供核心 I/O 功能
这让我很困惑,因为这不是iostream所做的。我真的确定我遗漏了一些东西,请帮我澄清一下,而且我没有看到I/O 对象与套接字之间的太大区别,除了套接字可用于在两个设备之间交换数据,而 I/O 对象使我们能够与计算机交换数据。此时我真的很困惑!
I wanted to implement a fixed size queue, I could have easily done with a struct having a queue as one of the data members and a member function that takes care of the push part of the queue, but rather wanted to try it out by inheriting queue like this.
template<typename T>
struct f_queue : public queue<T>{
int n;
T prev;
f_queue(int n_):
n(n_){}
void push(T data){
if(this->size() < this->n){
this->push(data);
}else{
prev = this->front();
this->pop();
this->push(data);
}
} …Run Code Online (Sandbox Code Playgroud)