Is there any other way to determine size of the container than :
//those are valid iterators from a container
BidIt begin;
BidIt end;
std::size_t size = 0;
while (begin != end)
{//Here throug iterating I'm getting adventually the correct size
++size;
++begin;
}
but I wonder if I could check size of this container by for example substracting addresses of this iterators or something like this.
Thanks for any help.
You can use the distance function. Note that if your iterators are not RandomAccessIterators the distance function will use basically the same method of calculating the distance that you've shown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With