How to get an element from circle_buffer

I am using boost library in MAC ( xcode ). I have two questions about boost::circular_buffer .

1 - I get syntax error when declaring round_buffer

 boost::circular_buffer<int> cb(10); Expected parameter decelerator Expected ')' 

2 - Second question: when I add an element to boost::circular_buffer using push_back, how to extract / get an element from circle_buffer, pop_front does not give an element.

+2
source share
1 answer

boost::circular_buffer<T>::front() gives a link to an element to "front", and boost::circular_buffer<T>::pop_front() removes this element.

boost::circular_buffer<T>::back() gives a link to the element at the back, and boost::circular_buffer<T>::pop_back() removes this element.

It looks like your syntax error comes from the most unpleasant parsing. Try instead:

 boost::circular_buffer<int> cb; cb.set_capacity(10); 

Or more succinctly:

 boost::circular_buffer<int> cb((10)); 
+4
source

Source: https://habr.com/ru/post/1259135/


All Articles