| 1 | // Copyright David Abrahams 2003. | 
|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. (See | 
|---|
| 3 | // accompanying file LICENSE_1_0.txt or copy at | 
|---|
| 4 | // http://www.boost.org/LICENSE_1_0.txt) | 
|---|
| 5 | #include <boost/iterator/iterator_adaptor.hpp> | 
|---|
| 6 | #include <boost/static_assert.hpp> | 
|---|
| 7 |  | 
|---|
| 8 | #include "static_assert_same.hpp" | 
|---|
| 9 |  | 
|---|
| 10 | #include <boost/type_traits/broken_compiler_spec.hpp> | 
|---|
| 11 |  | 
|---|
| 12 | #include <boost/iterator/detail/minimum_category.hpp> | 
|---|
| 13 |  | 
|---|
| 14 | struct X { int a; }; | 
|---|
| 15 |  | 
|---|
| 16 | BOOST_TT_BROKEN_COMPILER_SPEC(X) | 
|---|
| 17 |  | 
|---|
| 18 | struct Xiter : boost::iterator_adaptor<Xiter,X*> | 
|---|
| 19 | { | 
|---|
| 20 |     Xiter(); | 
|---|
| 21 |     Xiter(X* p) : boost::iterator_adaptor<Xiter, X*>(p) {} | 
|---|
| 22 | }; | 
|---|
| 23 |  | 
|---|
| 24 | void take_xptr(X*) {} | 
|---|
| 25 | void operator_arrow_test() | 
|---|
| 26 | { | 
|---|
| 27 |     // check that the operator-> result is a pointer for lvalue iterators | 
|---|
| 28 |     X x; | 
|---|
| 29 |     take_xptr(Xiter(&x).operator->()); | 
|---|
| 30 | } | 
|---|
| 31 |  | 
|---|
| 32 | template <class T, class U, class Min> | 
|---|
| 33 | struct static_assert_min_cat | 
|---|
| 34 |   : static_assert_same< | 
|---|
| 35 |        typename boost::detail::minimum_category<T,U>::type, Min | 
|---|
| 36 |     > | 
|---|
| 37 | {}; | 
|---|
| 38 |  | 
|---|
| 39 | void category_test() | 
|---|
| 40 | { | 
|---|
| 41 |     using namespace boost; | 
|---|
| 42 |     using namespace boost::detail; | 
|---|
| 43 |      | 
|---|
| 44 |     BOOST_STATIC_ASSERT(( | 
|---|
| 45 |         !boost::is_convertible< | 
|---|
| 46 |             std::input_iterator_tag | 
|---|
| 47 |           , input_output_iterator_tag>::value)); | 
|---|
| 48 |      | 
|---|
| 49 |     BOOST_STATIC_ASSERT(( | 
|---|
| 50 |         !boost::is_convertible< | 
|---|
| 51 |             std::output_iterator_tag | 
|---|
| 52 |           , input_output_iterator_tag>::value)); | 
|---|
| 53 |      | 
|---|
| 54 |     BOOST_STATIC_ASSERT(( | 
|---|
| 55 |         boost::is_convertible< | 
|---|
| 56 |             input_output_iterator_tag | 
|---|
| 57 |           , std::input_iterator_tag>::value)); | 
|---|
| 58 |      | 
|---|
| 59 |     BOOST_STATIC_ASSERT(( | 
|---|
| 60 |         boost::is_convertible< | 
|---|
| 61 |             input_output_iterator_tag | 
|---|
| 62 |           , std::output_iterator_tag>::value)); | 
|---|
| 63 |  | 
|---|
| 64 | #if 0 // This seems wrong; we're not advertising | 
|---|
| 65 |       // input_output_iterator_tag are we? | 
|---|
| 66 |     BOOST_STATIC_ASSERT(( | 
|---|
| 67 |         boost::is_convertible< | 
|---|
| 68 |             std::forward_iterator_tag | 
|---|
| 69 |           , input_output_iterator_tag>::value)); | 
|---|
| 70 | #endif  | 
|---|
| 71 |  | 
|---|
| 72 |     int test = static_assert_min_cat< | 
|---|
| 73 |         std::input_iterator_tag,input_output_iterator_tag, std::input_iterator_tag | 
|---|
| 74 |     >::value; | 
|---|
| 75 |  | 
|---|
| 76 |     test = static_assert_min_cat< | 
|---|
| 77 |         input_output_iterator_tag,std::input_iterator_tag, std::input_iterator_tag | 
|---|
| 78 |     >::value; | 
|---|
| 79 |  | 
|---|
| 80 | #if 0 | 
|---|
| 81 |     test = static_assert_min_cat< | 
|---|
| 82 |         input_output_iterator_tag,std::forward_iterator_tag, input_output_iterator_tag | 
|---|
| 83 |     >::value; | 
|---|
| 84 | #endif  | 
|---|
| 85 |  | 
|---|
| 86 |     test = static_assert_min_cat< | 
|---|
| 87 |         std::input_iterator_tag,std::forward_iterator_tag, std::input_iterator_tag | 
|---|
| 88 |     >::value; | 
|---|
| 89 |  | 
|---|
| 90 |     test = static_assert_min_cat< | 
|---|
| 91 |         std::input_iterator_tag,std::random_access_iterator_tag, std::input_iterator_tag | 
|---|
| 92 |     >::value; | 
|---|
| 93 |  | 
|---|
| 94 | #if 0  // This would be wrong: a random access iterator is not | 
|---|
| 95 |        // neccessarily writable, as is an output iterator. | 
|---|
| 96 |     test = static_assert_min_cat< | 
|---|
| 97 |         std::output_iterator_tag,std::random_access_iterator_tag, std::output_iterator_tag | 
|---|
| 98 |     >::value; | 
|---|
| 99 | #endif  | 
|---|
| 100 |      | 
|---|
| 101 |     (void)test; | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 | int main() | 
|---|
| 105 | { | 
|---|
| 106 |     category_test(); | 
|---|
| 107 |     operator_arrow_test(); | 
|---|
| 108 |     return 0; | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|