1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the config.tests of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 /* Sample program for configure to test STL support on target
43 platforms.  We are mainly concerned with being able to instantiate
44 templates for common STL container classes.
45 */
46 
47 #include <iterator>
48 #include <map>
49 #include <vector>
50 #include <algorithm>
51 #include <iostream>
52 
53 // something mean to see if the compiler and C++ standard lib are good enough
54 template<class K, class T>
55 class DummyClass
56 {
57     // everything in std namespace ?
58     typedef std::bidirectional_iterator_tag i;
59     typedef std::ptrdiff_t d;
60     // typename implemented ?
61     typedef typename std::map<K,T>::iterator MyIterator;
62 };
63 
64 // extracted from QVector's strict iterator
65 template<class T>
66 class DummyIterator
67 {
68     typedef DummyIterator<int> iterator;
69 public:
70         T *i;
71         typedef std::random_access_iterator_tag  iterator_category;
72         typedef std::ptrdiff_t difference_type;
73         typedef T value_type;
74         typedef T *pointer;
75         typedef T &reference;
76 
DummyIterator()77         inline DummyIterator() : i(0) {}
DummyIterator(T * n)78         inline DummyIterator(T *n) : i(n) {}
DummyIterator(const DummyIterator & o)79         inline DummyIterator(const DummyIterator &o): i(o.i){}
operator *() const80         inline T &operator*() const { return *i; }
operator ->() const81         inline T *operator->() const { return i; }
operator [](int j) const82         inline T &operator[](int j) const { return *(i + j); }
operator ==(const DummyIterator & o) const83         inline bool operator==(const DummyIterator &o) const { return i == o.i; }
operator !=(const DummyIterator & o) const84         inline bool operator!=(const DummyIterator &o) const { return i != o.i; }
operator <(const DummyIterator & other) const85         inline bool operator<(const DummyIterator& other) const { return i < other.i; }
operator <=(const DummyIterator & other) const86         inline bool operator<=(const DummyIterator& other) const { return i <= other.i; }
operator >(const DummyIterator & other) const87         inline bool operator>(const DummyIterator& other) const { return i > other.i; }
operator >=(const DummyIterator & other) const88         inline bool operator>=(const DummyIterator& other) const { return i >= other.i; }
operator ++()89         inline DummyIterator &operator++() { ++i; return *this; }
operator ++(int)90         inline DummyIterator operator++(int) { T *n = i; ++i; return n; }
operator --()91         inline DummyIterator &operator--() { i--; return *this; }
operator --(int)92         inline DummyIterator operator--(int) { T *n = i; i--; return n; }
operator +=(int j)93         inline DummyIterator &operator+=(int j) { i+=j; return *this; }
operator -=(int j)94         inline DummyIterator &operator-=(int j) { i-=j; return *this; }
operator +(int j) const95         inline DummyIterator operator+(int j) const { return DummyIterator(i+j); }
operator -(int j) const96         inline DummyIterator operator-(int j) const { return DummyIterator(i-j); }
operator -(DummyIterator j) const97         inline int operator-(DummyIterator j) const { return i - j.i; }
98 };
99 
main()100 int main()
101 {
102     std::vector<int> v1;
103     v1.push_back( 0 );
104     v1.push_back( 1 );
105     v1.push_back( 2 );
106     v1.push_back( 3 );
107     v1.push_back( 4 );
108     int v1size = v1.size();
109     v1size = 0;
110     int v1capacity = v1.capacity();
111     v1capacity = 0;
112 
113     std::vector<int>::iterator v1it = std::find( v1.begin(), v1.end(), 99 );
114     bool v1notfound = (v1it == v1.end());
115     v1notfound = false;
116 
117     v1it = std::find( v1.begin(), v1.end(), 3 );
118     bool v1found = (v1it != v1.end());
119     v1found = false;
120 
121     std::vector<int> v2;
122     std::copy( v1.begin(), v1it, std::back_inserter( v2 ) );
123     int v2size = v2.size();
124     v2size = 0;
125 
126     std::map<int, double> m1;
127     m1.insert( std::make_pair( 1, 2.0 ) );
128     m1.insert( std::make_pair( 3, 2.0 ) );
129     m1.insert( std::make_pair( 5, 2.0 ) );
130     m1.insert( std::make_pair( 7, 2.0 ) );
131     int m1size = m1.size();
132     m1size = 0;
133     std::map<int,double>::iterator m1it = m1.begin();
134     for ( ; m1it != m1.end(); ++m1it ) {
135         int first = (*m1it).first;
136         first = 0;
137         double second = (*m1it).second;
138         second = 0.0;
139     }
140     std::map< int, double > m2( m1 );
141     int m2size = m2.size();
142     m2size = 0;
143 
144     DummyIterator<int> it1, it2;
145     int n = std::distance(it1, it2);
146     std::advance(it1, 3);
147 
148     return 0;
149 }
150 
151