一种读写可并发进行的队列的实现方法

本文介绍了一种基于模板类实现的读写列表结构。该结构通过两个模板类`WriteList`和`ReadList`来提供对列表的操作,包括添加元素、删除元素等基本功能,并提供了检查列表是否为空及获取列表大小的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

五.

}
};
};

template
class WriteList
{
LIST& m_list;
public:
typedef typename LIST::value_type value_type;
typedef typename LIST::size_type size_type;
typedef typename LIST::difference_type difference_type;
typedef typename LIST::reference reference;
typedef typename LIST::const_reference const_reference;
typedef typename LIST::pointer pointer;
typedef typename LIST::const_pointer const_pointer;
WriteList(LIST& l): m_list(l)
{
}
void push_back(const_reference data)
{
m_list.push_back(data);
}
bool empty()
{
return m_list.empty();
}
size_type size()
{
return m_list.size();
}
size_type buffer_size()
{
return m_list.buffer_size();
}
};

template
class ReadList
{
LIST& m_list;
public:
typedef typename LIST::value_type value_type;
typedef typename LIST::size_type size_type;
typedef typename LIST::difference_type difference_type;
typedef typename LIST::reference reference;
typedef typename LIST::const_reference const_reference;
typedef typename LIST::pointer pointer;
typedef typename LIST::const_pointer const_pointer;
ReadList(LIST& l): m_list(l)
{
}
void pop_front()
{
m_list.pop_front();
}
reference front()
{
return m_list.front();
}
const_reference front() const
{
return m_list.front();
}
bool empty()
{
return m_list.empty();
}
size_type size()
{
return m_list.size();
}
size_type buffer_size()
{
return m_list.buffer_size();
}
};


#endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值