I read an implementation of a Queue from some algorithm books, there is a snippet that is new/interesting to me which I didn't understand. I think it is something new like initialization list for vector in C++11, but I am not that confident due to the context of the code. Can anyone shed a light or provide some reference?
template <typename T>
class Queue {
private:
size_t head, tail, count;
vector<T> data;
public:
Queue(const size_t &cap=8) : head(0),tail(0),count(0),data({cap}) {}
//... more interfaces
//...
}
the questionable part is data({cap}), what is this? It resizes the vector to a capacity of cap? (Obviously the author of the code intends to give data a size of cap when constructing it.)
EDIT: after read the first answer and test, we know that the book had error in the snippet. It intends to give a initial cap, but it used erroneous {}.