circular_buffer_iter_example.cpp 923 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2003-2008 Jan Gaspar.
  2. // Copyright 2013 Paul A. Bristow. Added some Quickbook snippet markers.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See the accompanying file LICENSE_1_0.txt
  5. // or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
  6. #undef BOOST_CB_ENABLE_DEBUG
  7. //[circular_buffer_iter_example_1
  8. /*`
  9. */
  10. #define BOOST_CB_ENABLE_DEBUG 0 // The Debug Support has to be disabled, otherwise the code produces a runtime error.
  11. #include <boost/circular_buffer.hpp>
  12. #include <boost/assert.hpp>
  13. #include <assert.h>
  14. int main(int /*argc*/, char* /*argv*/[])
  15. {
  16. boost::circular_buffer<int> cb(3);
  17. cb.push_back(1);
  18. cb.push_back(2);
  19. cb.push_back(3);
  20. boost::circular_buffer<int>::iterator it = cb.begin();
  21. assert(*it == 1);
  22. cb.push_back(4);
  23. assert(*it == 4); // The iterator still points to the initialized memory.
  24. return 0;
  25. }
  26. //] [/circular_buffer_iter_example_1]