• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright David Abrahams 2003. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4 
5 #include <deque>
6 #include <iterator>
7 #include <iostream>
8 #include <cstddef> // std::ptrdiff_t
9 #include <boost/static_assert.hpp>
10 #include <boost/noncopyable.hpp>
11 #include <boost/iterator/is_readable_iterator.hpp>
12 
13 // Last, for BOOST_NO_LVALUE_RETURN_DETECTION
14 #include <boost/iterator/detail/config_def.hpp>
15 
16 struct v
17 {
18     v();
19     ~v();
20 };
21 
22 
23 struct value_iterator
24 {
25     typedef std::input_iterator_tag iterator_category;
26     typedef v value_type;
27     typedef std::ptrdiff_t difference_type;
28     typedef v* pointer;
29     typedef v& reference;
30 
31     v operator*() const;
32 };
33 
34 struct noncopyable_iterator
35 {
36     typedef std::forward_iterator_tag iterator_category;
37     typedef boost::noncopyable value_type;
38     typedef std::ptrdiff_t difference_type;
39     typedef boost::noncopyable* pointer;
40     typedef boost::noncopyable& reference;
41 
42     boost::noncopyable const& operator*() const;
43 };
44 
45 struct proxy_iterator
46 {
47     typedef std::output_iterator_tag iterator_category;
48     typedef v value_type;
49     typedef std::ptrdiff_t difference_type;
50     typedef v* pointer;
51     typedef v& reference;
52 
53     struct proxy
54     {
55         operator v&();
56         proxy& operator=(v) const;
57     };
58 
59     proxy operator*() const;
60 };
61 
62 struct proxy_iterator2
63 {
64     typedef std::output_iterator_tag iterator_category;
65     typedef v value_type;
66     typedef std::ptrdiff_t difference_type;
67     typedef v* pointer;
68     typedef v& reference;
69 
70     struct proxy
71     {
72         proxy& operator=(v) const;
73     };
74 
75     proxy operator*() const;
76 };
77 
78 
main()79 int main()
80 {
81     BOOST_STATIC_ASSERT(boost::is_readable_iterator<v*>::value);
82     BOOST_STATIC_ASSERT(boost::is_readable_iterator<v const*>::value);
83     BOOST_STATIC_ASSERT(boost::is_readable_iterator<std::deque<v>::iterator>::value);
84     BOOST_STATIC_ASSERT(boost::is_readable_iterator<std::deque<v>::const_iterator>::value);
85     BOOST_STATIC_ASSERT(!boost::is_readable_iterator<std::back_insert_iterator<std::deque<v> > >::value);
86     BOOST_STATIC_ASSERT(!boost::is_readable_iterator<std::ostream_iterator<v> >::value);
87     BOOST_STATIC_ASSERT(boost::is_readable_iterator<proxy_iterator>::value);
88     BOOST_STATIC_ASSERT(!boost::is_readable_iterator<proxy_iterator2>::value);
89     BOOST_STATIC_ASSERT(boost::is_readable_iterator<value_iterator>::value);
90 
91     // Make sure inaccessible copy constructor doesn't prevent
92     // readability
93     BOOST_STATIC_ASSERT(boost::is_readable_iterator<noncopyable_iterator>::value);
94 
95     return 0;
96 }
97