In Part 3 we expanded on the original buffer and it now supports any type and any size. Our RingBuffer almost behaves like any of the STL types, such as std::vector and I say almost. Consider the following code:
int main()
{
RingBuffer<int, 10> my_buffer;
for (int i = 0; i < 10; ++i)
{
my_buffer.push_back(i);
}
for (auto x : my_buffer) // This line produces an error.
{
std::cout << x << ' ';
}
}
This code should work, but if we actually try to run it we will get a compiler error.
In
In
Hello! If you recall from the previous series, we built a program that handled text input, stored numbers into a vector and performed calculations. However there were some concepts in there that we used, but that I didn’t really explain. I am referring to iterators. In this new series I aim to go over what they are, how they work and how to use them, so get ready because it will be a bumpy ride and as usual, we will have to build our way there because fundamentals are always important.