这已经作为std::stack
和存在std::queue
。令人讨厌的是,它们之间的界面并不完全相同,但可以修复。void pop()
这也提供了修复疣的机会。
template <typename Traversal, typename T, typename Container>
struct GraphNeighbors;
template<typename T, typename Container=std::deque<T>>
struct GraphNeighbors<class FIFO, T, Container>
{
private:
std::queue<T, Container> nodes;
public:
T pop()
{
T elem = std::move(nodes.front());
nodes.pop();
return elem;
}
void push(const T & elem)
{
nodes.push(elem);
}
void push(T&& elem)
nodes.emplace(std::move(elem));
}
};
template<typename T, typename Container=std::deque<T>>
struct GraphNeighbors<class LIFO, T, Container>
{
private:
std::stack<T, Container> nodes;
public:
T pop()
{
T elem = std::move(nodes.top());
nodes.pop();
return elem;
}
void push(const T & elem)
{
nodes.push(elem);
}
void push(T&& elem)
nodes.emplace(std::move(elem));
}
};