1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://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 https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 /* Sample program for configure to test STL support on target
41 platforms.  We are mainly concerned with being able to instantiate
42 templates for common STL container classes.
43 */
44 
45 #include <iterator>
46 #include <map>
47 #include <vector>
48 #include <algorithm>
49 #include <iostream>
50 #include <cstddef>
51 
52 // something mean to see if the compiler and C++ standard lib are good enough
53 template<class K, class T>
54 class DummyClass
55 {
56     // everything in std namespace ?
57     typedef std::bidirectional_iterator_tag i;
58     typedef std::ptrdiff_t d;
59     // typename implemented ?
60     typedef typename std::map<K,T>::iterator MyIterator;
61 };
62 
63 // extracted from QVector's strict iterator
64 template<class T>
65 class DummyIterator
66 {
67     typedef DummyIterator<int> iterator;
68 public:
69         T *i;
70         typedef std::random_access_iterator_tag  iterator_category;
71         typedef std::ptrdiff_t difference_type;
72         typedef T value_type;
73         typedef T *pointer;
74         typedef T &reference;
75 
DummyIterator()76         inline DummyIterator() : i(0) {}
DummyIterator(T * n)77         inline DummyIterator(T *n) : i(n) {}
DummyIterator(const DummyIterator & o)78         inline DummyIterator(const DummyIterator &o): i(o.i){}
operator *() const79         inline T &operator*() const { return *i; }
operator ->() const80         inline T *operator->() const { return i; }
operator [](int j) const81         inline T &operator[](int j) const { return *(i + j); }
operator ==(const DummyIterator & o) const82         inline bool operator==(const DummyIterator &o) const { return i == o.i; }
operator !=(const DummyIterator & o) const83         inline bool operator!=(const DummyIterator &o) const { return i != o.i; }
operator <(const DummyIterator & other) const84         inline bool operator<(const DummyIterator& other) const { return i < other.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 ++()88         inline DummyIterator &operator++() { ++i; return *this; }
operator ++(int)89         inline DummyIterator operator++(int) { T *n = i; ++i; return n; }
operator --()90         inline DummyIterator &operator--() { i--; return *this; }
operator --(int)91         inline DummyIterator operator--(int) { T *n = i; i--; return n; }
operator +=(int j)92         inline DummyIterator &operator+=(int j) { i+=j; return *this; }
operator -=(int j)93         inline DummyIterator &operator-=(int j) { i-=j; return *this; }
operator +(int j) const94         inline DummyIterator operator+(int j) const { return DummyIterator(i+j); }
operator -(int j) const95         inline DummyIterator operator-(int j) const { return DummyIterator(i-j); }
operator -(DummyIterator j) const96         inline int operator-(DummyIterator j) const { return i - j.i; }
97 };
98 
main()99 int main()
100 {
101     std::vector<int> v1;
102     v1.push_back( 0 );
103     v1.push_back( 1 );
104     v1.push_back( 2 );
105     v1.push_back( 3 );
106     v1.push_back( 4 );
107     int v1size = v1.size();
108     v1size = 0;
109     int v1capacity = v1.capacity();
110     v1capacity = 0;
111 
112     std::vector<int>::iterator v1it = std::find( v1.begin(), v1.end(), 99 );
113     bool v1notfound = (v1it == v1.end());
114     v1notfound = false;
115 
116     v1it = std::find( v1.begin(), v1.end(), 3 );
117     bool v1found = (v1it != v1.end());
118     v1found = false;
119 
120     std::vector<int> v2;
121     std::copy( v1.begin(), v1it, std::back_inserter( v2 ) );
122     int v2size = v2.size();
123     v2size = 0;
124 
125     std::map<int, double> m1;
126     m1.insert( std::make_pair( 1, 2.0 ) );
127     m1.insert( std::make_pair( 3, 2.0 ) );
128     m1.insert( std::make_pair( 5, 2.0 ) );
129     m1.insert( std::make_pair( 7, 2.0 ) );
130     int m1size = m1.size();
131     m1size = 0;
132     std::map<int,double>::iterator m1it = m1.begin();
133     for ( ; m1it != m1.end(); ++m1it ) {
134         int first = (*m1it).first;
135         first = 0;
136         double second = (*m1it).second;
137         second = 0.0;
138     }
139     std::map< int, double > m2( m1 );
140     int m2size = m2.size();
141     m2size = 0;
142 
143     DummyIterator<int> it1, it2;
144     int n = std::distance(it1, it2);
145     std::advance(it1, 3);
146 
147     return 0;
148 }
149 
150