PageRenderTime 25ms CodeModel.GetById 14ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/iterator/test/concept_tests.cpp

http://hadesmem.googlecode.com/
C++ | 94 lines | 79 code | 11 blank | 4 comment | 0 complexity | 7a873c509e54743a537ef6a86a107cd3 MD5 | raw file
 1// (C) Copyright Jeremy Siek 2002.
 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
 6#include <boost/iterator/iterator_concepts.hpp>
 7#include <boost/iterator/iterator_categories.hpp>
 8#include <boost/operators.hpp>
 9
10struct new_random_access
11  : std::random_access_iterator_tag
12  , boost::random_access_traversal_tag
13{};
14
15struct new_iterator
16  : public boost::iterator< new_random_access, int >
17{
18  int& operator*() const { return *m_x; }
19  new_iterator& operator++() { return *this; }
20  new_iterator operator++(int) { return *this; }
21  new_iterator& operator--() { return *this; }
22  new_iterator operator--(int) { return *this; }
23  new_iterator& operator+=(std::ptrdiff_t) { return *this; }
24  new_iterator operator+(std::ptrdiff_t) { return *this; }
25  new_iterator& operator-=(std::ptrdiff_t) { return *this; }
26  std::ptrdiff_t operator-(const new_iterator&) const { return 0; }
27  new_iterator operator-(std::ptrdiff_t) const { return *this; }
28  bool operator==(const new_iterator&) const { return false; }
29  bool operator!=(const new_iterator&) const { return false; }
30  bool operator<(const new_iterator&) const { return false; }
31  int* m_x;
32};
33new_iterator operator+(std::ptrdiff_t, new_iterator x) { return x; }
34
35struct old_iterator
36  : public boost::iterator<std::random_access_iterator_tag, int>
37{
38  int& operator*() const { return *m_x; }
39  old_iterator& operator++() { return *this; }
40  old_iterator operator++(int) { return *this; }
41  old_iterator& operator--() { return *this; }
42  old_iterator operator--(int) { return *this; }
43  old_iterator& operator+=(std::ptrdiff_t) { return *this; }
44  old_iterator operator+(std::ptrdiff_t) { return *this; }
45  old_iterator& operator-=(std::ptrdiff_t) { return *this; }
46  old_iterator operator-(std::ptrdiff_t) const { return *this; }
47  std::ptrdiff_t operator-(const old_iterator&) const { return 0; }
48  bool operator==(const old_iterator&) const { return false; }
49  bool operator!=(const old_iterator&) const { return false; }
50  bool operator<(const old_iterator&) const { return false; }
51  int* m_x;
52};
53old_iterator operator+(std::ptrdiff_t, old_iterator x) { return x; }
54
55int
56main()
57{
58  boost::iterator_traversal<new_iterator>::type tc;
59  boost::random_access_traversal_tag derived = tc;
60  (void)derived;
61  
62  boost::function_requires<
63    boost_concepts::WritableIteratorConcept<int*> >();
64  boost::function_requires<
65    boost_concepts::LvalueIteratorConcept<int*> >();
66  boost::function_requires<
67    boost_concepts::RandomAccessTraversalConcept<int*> >();
68
69  boost::function_requires<
70    boost_concepts::ReadableIteratorConcept<const int*> >();
71  boost::function_requires<
72    boost_concepts::LvalueIteratorConcept<const int*> >();
73  boost::function_requires<
74    boost_concepts::RandomAccessTraversalConcept<const int*> >();
75
76  boost::function_requires<
77    boost_concepts::WritableIteratorConcept<new_iterator> >();
78  boost::function_requires<
79    boost_concepts::LvalueIteratorConcept<new_iterator> >();
80  boost::function_requires<
81    boost_concepts::RandomAccessTraversalConcept<new_iterator> >();
82
83  boost::function_requires<
84    boost_concepts::WritableIteratorConcept<old_iterator> >();
85  boost::function_requires<
86    boost_concepts::LvalueIteratorConcept<old_iterator> >();
87  boost::function_requires<
88    boost_concepts::RandomAccessTraversalConcept<old_iterator> >();
89
90  boost::function_requires<
91    boost_concepts::InteroperableIteratorConcept<int*, int const*> >();
92
93  return 0;
94}