【发布时间】:2017-04-21 13:24:59
【问题描述】:
我正在尝试弄清楚如何将以下构造函数用于 boost::circular_buffer:
circular_buffer(capacity_type buffer_capacity, size_type n, const_reference item, const allocator_type& alloc = allocator_type());
我有一个自定义类:
template<class T> class Custom
{
public:
Custom() :
time(0.0)
{}
double time;
T data_;
};
使用构造函数定义我的循环缓冲区,只占用一个容量:
boost::circular_buffer<Custom<T>> buffer(10);
我对分配器的工作不多,我想在构造时使用默认/空/零值初始化我的缓冲区,但似乎上面提到的构造函数是使用 boost::circular_buffer 的方法我不确定如何使用 boost 构造函数。如果它是一个普通的向量,我假设我可以执行以下操作:
int num_elements = 10;
Custom<T> custom;
std::vector<Custom<T>> buffer(10, custom);
我真的找不到任何具体的例子,所以任何帮助或指导都非常感谢。
【问题讨论】:
标签: c++ c++11 boost allocator circular-buffer