fixed_size_queue_fail_tests.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*=============================================================================
  2. Copyright (c) 2001-2003 Daniel Nuffer
  3. Copyright (c) 2003 Hartmut Kaiser
  4. http://spirit.sourceforge.net/
  5. Use, modification and distribution is subject to the Boost Software
  6. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt)
  8. =============================================================================*/
  9. #include <boost/spirit/include/classic_fixed_size_queue.hpp>
  10. #include <boost/mpl/assert.hpp>
  11. #include <boost/type_traits/is_same.hpp>
  12. #include <boost/concept_check.hpp>
  13. #include <boost/detail/lightweight_test.hpp>
  14. #include <iostream>
  15. typedef BOOST_SPIRIT_CLASSIC_NS::fixed_size_queue<int, 5> queue_t;
  16. typedef queue_t::iterator iter_t;
  17. typedef queue_t::const_iterator const_iter_t;
  18. BOOST_CLASS_REQUIRE(const_iter_t, boost, RandomAccessIteratorConcept);
  19. // Right now, the iterator is not a full compliant MutableRandomAccessIterator
  20. // because operator[] does not return a reference. This seems a problem in
  21. // boost::iterator_adaptors. Anyway, this feature is not used in multi_pass
  22. // iterator, and this class is not really meant for public use yet.
  23. BOOST_CLASS_REQUIRE(iter_t, boost, RandomAccessIteratorConcept);
  24. int main(int, char**)
  25. {
  26. // Iterators are random access.
  27. BOOST_MPL_ASSERT(( boost::is_same<
  28. iter_t::iterator_category,
  29. std::random_access_iterator_tag > ));
  30. BOOST_MPL_ASSERT(( boost::is_same<
  31. const_iter_t::iterator_category,
  32. std::random_access_iterator_tag > ));
  33. queue_t q;
  34. const queue_t& cq = q;
  35. iter_t b = q.begin();
  36. const_iter_t c = cq.begin();
  37. // MSVC7.1 and EDG aren't able to compile this code for the new iterator
  38. // adaptors
  39. // The problem here is, that the old fixed_size_queue code wasn't a complete
  40. // and 'clean' iterator implementation, some of the required iterator concepts
  41. // were missing. It was never meant to be exposed outside the multi_pass. So I
  42. // haven't added any features while porting. The #ifdef'ed tests expose the
  43. // code weaknesses ((un-)fortunately only on conformant compilers, with a quite
  44. // good STL implementation). The simplest way to solve this issue was to switch
  45. // of the tests for these compilers then.
  46. // Check comparisons and interoperations (we are comparing
  47. // const and non-const iterators)
  48. (void) c == b;
  49. (void) c+4 > b;
  50. (void) c < b+4;
  51. return boost::report_errors();
  52. }