【发布时间】:2015-08-08 05:56:36
【问题描述】:
我使用std::vector<T> 和std::vector<T>::iterator 编写了很多代码。现在我决定用 boost 中的循环缓冲区替换向量容器,即boost::circular_buffer<T>。
当然,现在编译器会抱怨每个使用std::... 的函数,而我将传递boost::... 对应项。我现在必须重写所有函数吗?我在问,因为来自 boost 的容器的工作原理完全相同。 Boost documentation 还声明如下:
circular_buffer 是一个符合 STL 的容器。它是一种类似于 std::list 或 std::deque 的序列。
“STL 兼容”部分是什么意思?它是指我想做的事情(可互换性)还是只是程序员的心理提示,容器在 boost 中的工作方式与在 STL 中的工作方式相同?
编辑:举个例子
class Item{ };
class Queue{
private:
std::vector<Item*> item_vector; // Want to replace only this...
std::vector<Item*>::iterator current_position; // ...and this
public:
Item* get_current_item() const {
return *current_position;
}
std::vector<Item*> get_item_vector(){
return item_vector;
}
};
【问题讨论】:
-
当你说“现在编译器会抱怨”时,你在使用什么样的函数?