Boost loop buffer

Source: Internet
Author: User

Boost loop buffer

[CPP]View plaincopy
  1. # Include <boost/circular_buffer.hpp>
  2. Int _ tmain (INT argc, _ tchar * argv [])
  3. {
  4. Boost: circular_buffer <int> CB (3 );
  5. // Insert some elements into the buffer.
  6. CB. push_back (1 );
  7. CB. push_back (2 );
  8. CB. push_back (3 );
  9. Int A = CB [0]; // A = 1
  10. Int B = CB [1]; // B = 2
  11. Int c = CB [2]; // C = 3
  12. // The buffer is full now, pushing subsequent
  13. // Elements will overwrite the front-most elements.
  14. CB. push_back (4); // overwrite 1 with 4.
  15. CB. push_back (5); // overwrite 2 with 5.
  16. // The buffer now contains 3, 4 and 5.
  17. A = CB [0]; // A = 3
  18. B = CB [1]; // B = 4
  19. C = CB [2]; // C = 5
  20. // Elements can be popped from either the front or the back.
  21. CB. pop_back (); // 5 is removed.
  22. CB. pop_front (); // 3 is removed.
  23. Int d = CB [0]; // d = 4
  24. Return 0;
  25. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.