author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 29 Apr 2010 15:15:16 +0300 | |
branch | RCL_3 |
changeset 17 | 4b6ee5efea19 |
parent 4 | 3b1da2848fc7 |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the config.tests of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
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 ptrdiff_t difference_type; |
|
73 |
typedef T value_type; |
|
74 |
typedef T *pointer; |
|
75 |
typedef T &reference; |
|
76 |
||
77 |
inline DummyIterator() : i(0) {} |
|
78 |
inline DummyIterator(T *n) : i(n) {} |
|
79 |
inline DummyIterator(const DummyIterator &o): i(o.i){} |
|
80 |
inline T &operator*() const { return *i; } |
|
81 |
inline T *operator->() const { return i; } |
|
82 |
inline T &operator[](int j) const { return *(i + j); } |
|
83 |
inline bool operator==(const DummyIterator &o) const { return i == o.i; } |
|
84 |
inline bool operator!=(const DummyIterator &o) const { return i != o.i; } |
|
85 |
inline bool operator<(const DummyIterator& other) const { return i < other.i; } |
|
86 |
inline bool operator<=(const DummyIterator& other) const { return i <= other.i; } |
|
87 |
inline bool operator>(const DummyIterator& other) const { return i > other.i; } |
|
88 |
inline bool operator>=(const DummyIterator& other) const { return i >= other.i; } |
|
89 |
inline DummyIterator &operator++() { ++i; return *this; } |
|
90 |
inline DummyIterator operator++(int) { T *n = i; ++i; return n; } |
|
91 |
inline DummyIterator &operator--() { i--; return *this; } |
|
92 |
inline DummyIterator operator--(int) { T *n = i; i--; return n; } |
|
93 |
inline DummyIterator &operator+=(int j) { i+=j; return *this; } |
|
94 |
inline DummyIterator &operator-=(int j) { i-=j; return *this; } |
|
95 |
inline DummyIterator operator+(int j) const { return DummyIterator(i+j); } |
|
96 |
inline DummyIterator operator-(int j) const { return DummyIterator(i-j); } |
|
97 |
inline int operator-(DummyIterator j) const { return i - j.i; } |
|
98 |
}; |
|
99 |
||
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 |