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