Boost circular buffer example

From kangssu
Jump to: navigation, search
#include <boost/circular_buffer.hpp>
int main(int argc, char **argv)
{ 
    boost::circular_buffer<int> cb(5);
    cb.push_back(20);
    printf("size: %d \n", cb.size());
    cb.push_back(30);
    printf("size: %d \n", cb.size());
    cb.push_back(40);
    printf("size: %d \n", cb.size());
    cb.push_back(15);
    printf("size: %d \n", cb.size());
    cb.push_back(60);
    printf("size: %d \n", cb.size());
    cb.push_back(100);
    printf("size: %d \n", cb.size());
    for(auto i : cb) {
        printf("%d ", i);
    }
    printf("\n");
    for(int i=0; i<5; i++) {
        printf("%d ", cb[i]);
    }
    printf("\n");

    return 0;
}

result:

size: 1 
size: 2 
size: 3 
size: 4 
size: 5 
size: 5 
30 40 15 60 100 
30 40 15 60 100