google_hash 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.txt +2 -0
- data/VERSION +1 -1
- data/ext/clean.bat +0 -0
- data/ext/clean.sh +4 -0
- data/ext/extconf.rb +4 -5
- data/ext/go.bat +0 -0
- data/ext/sparsehash-2.0.2/AUTHORS +2 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/COPYING +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/ChangeLog +60 -0
- data/ext/sparsehash-2.0.2/INSTALL +365 -0
- data/ext/sparsehash-2.0.2/Makefile +1336 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/Makefile.am +97 -40
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/Makefile.in +538 -256
- data/ext/sparsehash-2.0.2/NEWS +188 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/README +4 -10
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/README_windows.txt +3 -3
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/TODO +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/aclocal.m4 +266 -166
- data/ext/sparsehash-2.0.2/allocator.patch +31 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/config.guess +235 -234
- data/ext/sparsehash-2.0.2/config.status +1238 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/config.sub +198 -64
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/configure +1118 -1000
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/configure.ac +4 -5
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/depcomp +136 -36
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/dense_hash_map.html +182 -67
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/dense_hash_set.html +173 -74
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/designstyle.css +0 -6
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/implementation.html +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/index.html +4 -5
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/performance.html +1 -1
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/sparse_hash_map.html +190 -58
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/sparse_hash_set.html +180 -65
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/sparsetable.html +1 -1
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/Makefile +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/README +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/example.c +1 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/libchash.c +1 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/libchash.h +1 -0
- data/ext/sparsehash-2.0.2/install-sh +520 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/acx_pthread.m4 +34 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/google_namespace.m4 +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/namespaces.m4 +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/stl_hash.m4 +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/stl_hash_fun.m4 +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/missing +60 -44
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb.sh +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/README +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/changelog +42 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/compat +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/control +1 -1
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/copyright +5 -4
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/docs +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/rules +0 -0
- data/ext/sparsehash-2.0.2/packages/deb/sparsehash.dirs +5 -0
- data/ext/sparsehash-2.0.2/packages/deb/sparsehash.install +6 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/rpm.sh +1 -1
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/rpm/rpm.spec +5 -3
- data/ext/{sparsehash-1.8.1/google-sparsehash.sln → sparsehash-2.0.2/sparsehash.sln} +0 -0
- data/ext/sparsehash-2.0.2/src/config.h +132 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/config.h.in +0 -3
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/config.h.include +0 -1
- data/ext/sparsehash-2.0.2/src/google/dense_hash_map +34 -0
- data/ext/sparsehash-2.0.2/src/google/dense_hash_set +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparse_hash_map +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparse_hash_set +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparsehash/densehashtable.h +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparsehash/hashtable-common.h +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparsehash/libc_allocator_with_realloc.h +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparsehash/sparsehashtable.h +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparsetable +34 -0
- data/ext/sparsehash-2.0.2/src/google/template_util.h +34 -0
- data/ext/sparsehash-2.0.2/src/google/type_traits.h +34 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/hash_test_interface.h +64 -37
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/hashtable_test.cc +415 -141
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/libc_allocator_with_realloc_test.cc +16 -23
- data/ext/sparsehash-2.0.2/src/simple_compat_test.cc +106 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/simple_test.cc +8 -5
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/dense_hash_map +80 -37
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/dense_hash_set +64 -34
- data/ext/{sparsehash-1.8.1/src/google/sparsehash → sparsehash-2.0.2/src/sparsehash/internal}/densehashtable.h +247 -173
- data/ext/sparsehash-2.0.2/src/sparsehash/internal/hashtable-common.h +381 -0
- data/ext/{sparsehash-1.8.1/src/google/sparsehash → sparsehash-2.0.2/src/sparsehash/internal}/libc_allocator_with_realloc.h +5 -7
- data/ext/{sparsehash-1.8.1/src/google/sparsehash → sparsehash-2.0.2/src/sparsehash/internal}/sparsehashtable.h +154 -93
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/sparse_hash_map +96 -36
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/sparse_hash_set +85 -32
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/sparsetable +520 -258
- data/ext/sparsehash-2.0.2/src/sparsehash/template_util.h +134 -0
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/type_traits.h +153 -35
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/sparsetable_unittest.cc +108 -22
- data/ext/sparsehash-2.0.2/src/stamp-h1 +1 -0
- data/ext/sparsehash-2.0.2/src/template_util_unittest.cc +134 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/testutil.h +16 -1
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/time_hash_map.cc +259 -94
- data/ext/sparsehash-2.0.2/src/type_traits_unittest.cc +636 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/windows/config.h +4 -4
- data/ext/sparsehash-2.0.2/src/windows/google/sparsehash/sparseconfig.h +49 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/windows/port.cc +1 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/windows/port.h +4 -13
- data/ext/sparsehash-2.0.2/src/windows/sparsehash/internal/sparseconfig.h +49 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/hashtable_test/hashtable_test.vcproj +11 -11
- data/ext/sparsehash-2.0.2/vsprojects/libc_allocator_with_realloc_test/libc_allocator_with_realloc_test.vcproj +161 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/simple_test/simple_test.vcproj +10 -10
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/sparsetable_unittest/sparsetable_unittest.vcproj +4 -4
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/time_hash_map/time_hash_map.vcproj +10 -10
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/type_traits_unittest/type_traits_unittest.vcproj +3 -3
- data/ext/spec.bat +0 -0
- data/ext/template/google_hash.cpp.erb +6 -5
- metadata +106 -86
- data/ext/sparsehash-1.8.1/AUTHORS +0 -2
- data/ext/sparsehash-1.8.1/INSTALL +0 -236
- data/ext/sparsehash-1.8.1/NEWS +0 -71
- data/ext/sparsehash-1.8.1/compile +0 -99
- data/ext/sparsehash-1.8.1/install-sh +0 -323
- data/ext/sparsehash-1.8.1/m4/stl_namespace.m4 +0 -25
- data/ext/sparsehash-1.8.1/mkinstalldirs +0 -158
- data/ext/sparsehash-1.8.1/packages/deb/sparsehash.dirs +0 -2
- data/ext/sparsehash-1.8.1/packages/deb/sparsehash.install +0 -2
- data/ext/sparsehash-1.8.1/src/google/sparsehash/hashtable-common.h +0 -178
- data/ext/sparsehash-1.8.1/src/type_traits_unittest.cc +0 -502
- data/ext/sparsehash-1.8.1/src/windows/google/sparsehash/sparseconfig.h +0 -32
@@ -0,0 +1,636 @@
|
|
1
|
+
// Copyright (c) 2006, Google Inc.
|
2
|
+
// All rights reserved.
|
3
|
+
//
|
4
|
+
// Redistribution and use in source and binary forms, with or without
|
5
|
+
// modification, are permitted provided that the following conditions are
|
6
|
+
// met:
|
7
|
+
//
|
8
|
+
// * Redistributions of source code must retain the above copyright
|
9
|
+
// notice, this list of conditions and the following disclaimer.
|
10
|
+
// * Redistributions in binary form must reproduce the above
|
11
|
+
// copyright notice, this list of conditions and the following disclaimer
|
12
|
+
// in the documentation and/or other materials provided with the
|
13
|
+
// distribution.
|
14
|
+
// * Neither the name of Google Inc. nor the names of its
|
15
|
+
// contributors may be used to endorse or promote products derived from
|
16
|
+
// this software without specific prior written permission.
|
17
|
+
//
|
18
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
|
30
|
+
// ----
|
31
|
+
|
32
|
+
#include <sparsehash/internal/sparseconfig.h>
|
33
|
+
#include <config.h>
|
34
|
+
#include <sparsehash/type_traits.h>
|
35
|
+
|
36
|
+
#include <stdlib.h> // for exit()
|
37
|
+
#include <stdio.h>
|
38
|
+
#include <string>
|
39
|
+
#include <vector>
|
40
|
+
#include "testutil.h"
|
41
|
+
|
42
|
+
typedef int int32;
|
43
|
+
typedef long int64;
|
44
|
+
|
45
|
+
using std::string;
|
46
|
+
using std::vector;
|
47
|
+
using std::pair;
|
48
|
+
|
49
|
+
using GOOGLE_NAMESPACE::add_reference;
|
50
|
+
using GOOGLE_NAMESPACE::has_trivial_assign;
|
51
|
+
using GOOGLE_NAMESPACE::has_trivial_constructor;
|
52
|
+
using GOOGLE_NAMESPACE::has_trivial_copy;
|
53
|
+
using GOOGLE_NAMESPACE::has_trivial_destructor;
|
54
|
+
#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
|
55
|
+
using GOOGLE_NAMESPACE::is_convertible;
|
56
|
+
using GOOGLE_NAMESPACE::is_enum;
|
57
|
+
#endif
|
58
|
+
using GOOGLE_NAMESPACE::is_floating_point;
|
59
|
+
using GOOGLE_NAMESPACE::is_integral;
|
60
|
+
using GOOGLE_NAMESPACE::is_pointer;
|
61
|
+
using GOOGLE_NAMESPACE::is_pod;
|
62
|
+
using GOOGLE_NAMESPACE::is_reference;
|
63
|
+
using GOOGLE_NAMESPACE::is_same;
|
64
|
+
using GOOGLE_NAMESPACE::remove_const;
|
65
|
+
using GOOGLE_NAMESPACE::remove_cv;
|
66
|
+
using GOOGLE_NAMESPACE::remove_pointer;
|
67
|
+
using GOOGLE_NAMESPACE::remove_reference;
|
68
|
+
using GOOGLE_NAMESPACE::remove_volatile;
|
69
|
+
|
70
|
+
|
71
|
+
// This assertion produces errors like "error: invalid use of
|
72
|
+
// incomplete type 'struct <unnamed>::AssertTypesEq<const int, int>'"
|
73
|
+
// when it fails.
|
74
|
+
template<typename T, typename U> struct AssertTypesEq;
|
75
|
+
template<typename T> struct AssertTypesEq<T, T> {};
|
76
|
+
#define COMPILE_ASSERT_TYPES_EQ(T, U) static_cast<void>(AssertTypesEq<T, U>())
|
77
|
+
|
78
|
+
// A user-defined POD type.
|
79
|
+
struct A {
|
80
|
+
int n_;
|
81
|
+
};
|
82
|
+
|
83
|
+
// A user-defined non-POD type with a trivial copy constructor.
|
84
|
+
class B {
|
85
|
+
public:
|
86
|
+
explicit B(int n) : n_(n) { }
|
87
|
+
private:
|
88
|
+
int n_;
|
89
|
+
};
|
90
|
+
|
91
|
+
// Another user-defined non-POD type with a trivial copy constructor.
|
92
|
+
// We will explicitly declare C to have a trivial copy constructor
|
93
|
+
// by specializing has_trivial_copy.
|
94
|
+
class C {
|
95
|
+
public:
|
96
|
+
explicit C(int n) : n_(n) { }
|
97
|
+
private:
|
98
|
+
int n_;
|
99
|
+
};
|
100
|
+
|
101
|
+
_START_GOOGLE_NAMESPACE_
|
102
|
+
template<> struct has_trivial_copy<C> : true_type { };
|
103
|
+
_END_GOOGLE_NAMESPACE_
|
104
|
+
|
105
|
+
// Another user-defined non-POD type with a trivial assignment operator.
|
106
|
+
// We will explicitly declare C to have a trivial assignment operator
|
107
|
+
// by specializing has_trivial_assign.
|
108
|
+
class D {
|
109
|
+
public:
|
110
|
+
explicit D(int n) : n_(n) { }
|
111
|
+
private:
|
112
|
+
int n_;
|
113
|
+
};
|
114
|
+
|
115
|
+
_START_GOOGLE_NAMESPACE_
|
116
|
+
template<> struct has_trivial_assign<D> : true_type { };
|
117
|
+
_END_GOOGLE_NAMESPACE_
|
118
|
+
|
119
|
+
// Another user-defined non-POD type with a trivial constructor.
|
120
|
+
// We will explicitly declare E to have a trivial constructor
|
121
|
+
// by specializing has_trivial_constructor.
|
122
|
+
class E {
|
123
|
+
public:
|
124
|
+
int n_;
|
125
|
+
};
|
126
|
+
|
127
|
+
_START_GOOGLE_NAMESPACE_
|
128
|
+
template<> struct has_trivial_constructor<E> : true_type { };
|
129
|
+
_END_GOOGLE_NAMESPACE_
|
130
|
+
|
131
|
+
// Another user-defined non-POD type with a trivial destructor.
|
132
|
+
// We will explicitly declare E to have a trivial destructor
|
133
|
+
// by specializing has_trivial_destructor.
|
134
|
+
class F {
|
135
|
+
public:
|
136
|
+
explicit F(int n) : n_(n) { }
|
137
|
+
private:
|
138
|
+
int n_;
|
139
|
+
};
|
140
|
+
|
141
|
+
_START_GOOGLE_NAMESPACE_
|
142
|
+
template<> struct has_trivial_destructor<F> : true_type { };
|
143
|
+
_END_GOOGLE_NAMESPACE_
|
144
|
+
|
145
|
+
enum G {};
|
146
|
+
|
147
|
+
union H {};
|
148
|
+
|
149
|
+
class I {
|
150
|
+
public:
|
151
|
+
operator int() const;
|
152
|
+
};
|
153
|
+
|
154
|
+
class J {
|
155
|
+
private:
|
156
|
+
operator int() const;
|
157
|
+
};
|
158
|
+
|
159
|
+
namespace {
|
160
|
+
|
161
|
+
// A base class and a derived class that inherits from it, used for
|
162
|
+
// testing conversion type traits.
|
163
|
+
class Base {
|
164
|
+
public:
|
165
|
+
virtual ~Base() { }
|
166
|
+
};
|
167
|
+
|
168
|
+
class Derived : public Base {
|
169
|
+
};
|
170
|
+
|
171
|
+
TEST(TypeTraitsTest, TestIsInteger) {
|
172
|
+
// Verify that is_integral is true for all integer types.
|
173
|
+
EXPECT_TRUE(is_integral<bool>::value);
|
174
|
+
EXPECT_TRUE(is_integral<char>::value);
|
175
|
+
EXPECT_TRUE(is_integral<unsigned char>::value);
|
176
|
+
EXPECT_TRUE(is_integral<signed char>::value);
|
177
|
+
EXPECT_TRUE(is_integral<wchar_t>::value);
|
178
|
+
EXPECT_TRUE(is_integral<int>::value);
|
179
|
+
EXPECT_TRUE(is_integral<unsigned int>::value);
|
180
|
+
EXPECT_TRUE(is_integral<short>::value);
|
181
|
+
EXPECT_TRUE(is_integral<unsigned short>::value);
|
182
|
+
EXPECT_TRUE(is_integral<long>::value);
|
183
|
+
EXPECT_TRUE(is_integral<unsigned long>::value);
|
184
|
+
|
185
|
+
// Verify that is_integral is false for a few non-integer types.
|
186
|
+
EXPECT_FALSE(is_integral<void>::value);
|
187
|
+
EXPECT_FALSE(is_integral<float>::value);
|
188
|
+
EXPECT_FALSE(is_integral<string>::value);
|
189
|
+
EXPECT_FALSE(is_integral<int*>::value);
|
190
|
+
EXPECT_FALSE(is_integral<A>::value);
|
191
|
+
EXPECT_FALSE((is_integral<pair<int, int> >::value));
|
192
|
+
|
193
|
+
// Verify that cv-qualified integral types are still integral, and
|
194
|
+
// cv-qualified non-integral types are still non-integral.
|
195
|
+
EXPECT_TRUE(is_integral<const char>::value);
|
196
|
+
EXPECT_TRUE(is_integral<volatile bool>::value);
|
197
|
+
EXPECT_TRUE(is_integral<const volatile unsigned int>::value);
|
198
|
+
EXPECT_FALSE(is_integral<const float>::value);
|
199
|
+
EXPECT_FALSE(is_integral<int* volatile>::value);
|
200
|
+
EXPECT_FALSE(is_integral<const volatile string>::value);
|
201
|
+
}
|
202
|
+
|
203
|
+
TEST(TypeTraitsTest, TestIsFloating) {
|
204
|
+
// Verify that is_floating_point is true for all floating-point types.
|
205
|
+
EXPECT_TRUE(is_floating_point<float>::value);
|
206
|
+
EXPECT_TRUE(is_floating_point<double>::value);
|
207
|
+
EXPECT_TRUE(is_floating_point<long double>::value);
|
208
|
+
|
209
|
+
// Verify that is_floating_point is false for a few non-float types.
|
210
|
+
EXPECT_FALSE(is_floating_point<void>::value);
|
211
|
+
EXPECT_FALSE(is_floating_point<long>::value);
|
212
|
+
EXPECT_FALSE(is_floating_point<string>::value);
|
213
|
+
EXPECT_FALSE(is_floating_point<float*>::value);
|
214
|
+
EXPECT_FALSE(is_floating_point<A>::value);
|
215
|
+
EXPECT_FALSE((is_floating_point<pair<int, int> >::value));
|
216
|
+
|
217
|
+
// Verify that cv-qualified floating point types are still floating, and
|
218
|
+
// cv-qualified non-floating types are still non-floating.
|
219
|
+
EXPECT_TRUE(is_floating_point<const float>::value);
|
220
|
+
EXPECT_TRUE(is_floating_point<volatile double>::value);
|
221
|
+
EXPECT_TRUE(is_floating_point<const volatile long double>::value);
|
222
|
+
EXPECT_FALSE(is_floating_point<const int>::value);
|
223
|
+
EXPECT_FALSE(is_floating_point<volatile string>::value);
|
224
|
+
EXPECT_FALSE(is_floating_point<const volatile char>::value);
|
225
|
+
}
|
226
|
+
|
227
|
+
TEST(TypeTraitsTest, TestIsPointer) {
|
228
|
+
// Verify that is_pointer is true for some pointer types.
|
229
|
+
EXPECT_TRUE(is_pointer<int*>::value);
|
230
|
+
EXPECT_TRUE(is_pointer<void*>::value);
|
231
|
+
EXPECT_TRUE(is_pointer<string*>::value);
|
232
|
+
EXPECT_TRUE(is_pointer<const void*>::value);
|
233
|
+
EXPECT_TRUE(is_pointer<volatile float* const*>::value);
|
234
|
+
|
235
|
+
// Verify that is_pointer is false for some non-pointer types.
|
236
|
+
EXPECT_FALSE(is_pointer<void>::value);
|
237
|
+
EXPECT_FALSE(is_pointer<float&>::value);
|
238
|
+
EXPECT_FALSE(is_pointer<long>::value);
|
239
|
+
EXPECT_FALSE(is_pointer<vector<int*> >::value);
|
240
|
+
EXPECT_FALSE(is_pointer<int[5]>::value);
|
241
|
+
|
242
|
+
// A function pointer is a pointer, but a function type, or a function
|
243
|
+
// reference type, is not.
|
244
|
+
EXPECT_TRUE(is_pointer<int (*)(int x)>::value);
|
245
|
+
EXPECT_FALSE(is_pointer<void(char x)>::value);
|
246
|
+
EXPECT_FALSE(is_pointer<double (&)(string x)>::value);
|
247
|
+
|
248
|
+
// Verify that is_pointer<T> is true for some cv-qualified pointer types,
|
249
|
+
// and false for some cv-qualified non-pointer types.
|
250
|
+
EXPECT_TRUE(is_pointer<int* const>::value);
|
251
|
+
EXPECT_TRUE(is_pointer<const void* volatile>::value);
|
252
|
+
EXPECT_TRUE(is_pointer<char** const volatile>::value);
|
253
|
+
EXPECT_FALSE(is_pointer<const int>::value);
|
254
|
+
EXPECT_FALSE(is_pointer<volatile vector<int*> >::value);
|
255
|
+
EXPECT_FALSE(is_pointer<const volatile double>::value);
|
256
|
+
}
|
257
|
+
|
258
|
+
TEST(TypeTraitsTest, TestIsEnum) {
|
259
|
+
// is_enum isn't supported on MSVC or gcc 3.x
|
260
|
+
#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
|
261
|
+
// Verify that is_enum is true for enum types.
|
262
|
+
EXPECT_TRUE(is_enum<G>::value);
|
263
|
+
EXPECT_TRUE(is_enum<const G>::value);
|
264
|
+
EXPECT_TRUE(is_enum<volatile G>::value);
|
265
|
+
EXPECT_TRUE(is_enum<const volatile G>::value);
|
266
|
+
|
267
|
+
// Verify that is_enum is false for a few non-enum types.
|
268
|
+
EXPECT_FALSE(is_enum<void>::value);
|
269
|
+
EXPECT_FALSE(is_enum<G&>::value);
|
270
|
+
EXPECT_FALSE(is_enum<G[1]>::value);
|
271
|
+
EXPECT_FALSE(is_enum<const G[1]>::value);
|
272
|
+
EXPECT_FALSE(is_enum<G[]>::value);
|
273
|
+
EXPECT_FALSE(is_enum<int>::value);
|
274
|
+
EXPECT_FALSE(is_enum<float>::value);
|
275
|
+
EXPECT_FALSE(is_enum<A>::value);
|
276
|
+
EXPECT_FALSE(is_enum<A*>::value);
|
277
|
+
EXPECT_FALSE(is_enum<const A>::value);
|
278
|
+
EXPECT_FALSE(is_enum<H>::value);
|
279
|
+
EXPECT_FALSE(is_enum<I>::value);
|
280
|
+
EXPECT_FALSE(is_enum<J>::value);
|
281
|
+
EXPECT_FALSE(is_enum<void()>::value);
|
282
|
+
EXPECT_FALSE(is_enum<void(*)()>::value);
|
283
|
+
EXPECT_FALSE(is_enum<int A::*>::value);
|
284
|
+
EXPECT_FALSE(is_enum<void (A::*)()>::value);
|
285
|
+
#endif
|
286
|
+
}
|
287
|
+
|
288
|
+
TEST(TypeTraitsTest, TestIsReference) {
|
289
|
+
// Verifies that is_reference is true for all reference types.
|
290
|
+
typedef float& RefFloat;
|
291
|
+
EXPECT_TRUE(is_reference<float&>::value);
|
292
|
+
EXPECT_TRUE(is_reference<const int&>::value);
|
293
|
+
EXPECT_TRUE(is_reference<const int*&>::value);
|
294
|
+
EXPECT_TRUE(is_reference<int (&)(bool)>::value);
|
295
|
+
EXPECT_TRUE(is_reference<RefFloat>::value);
|
296
|
+
EXPECT_TRUE(is_reference<const RefFloat>::value);
|
297
|
+
EXPECT_TRUE(is_reference<volatile RefFloat>::value);
|
298
|
+
EXPECT_TRUE(is_reference<const volatile RefFloat>::value);
|
299
|
+
|
300
|
+
|
301
|
+
// Verifies that is_reference is false for all non-reference types.
|
302
|
+
EXPECT_FALSE(is_reference<float>::value);
|
303
|
+
EXPECT_FALSE(is_reference<const float>::value);
|
304
|
+
EXPECT_FALSE(is_reference<volatile float>::value);
|
305
|
+
EXPECT_FALSE(is_reference<const volatile float>::value);
|
306
|
+
EXPECT_FALSE(is_reference<const int*>::value);
|
307
|
+
EXPECT_FALSE(is_reference<int()>::value);
|
308
|
+
EXPECT_FALSE(is_reference<void(*)(const char&)>::value);
|
309
|
+
}
|
310
|
+
|
311
|
+
TEST(TypeTraitsTest, TestAddReference) {
|
312
|
+
COMPILE_ASSERT_TYPES_EQ(int&, add_reference<int>::type);
|
313
|
+
COMPILE_ASSERT_TYPES_EQ(const int&, add_reference<const int>::type);
|
314
|
+
COMPILE_ASSERT_TYPES_EQ(volatile int&,
|
315
|
+
add_reference<volatile int>::type);
|
316
|
+
COMPILE_ASSERT_TYPES_EQ(const volatile int&,
|
317
|
+
add_reference<const volatile int>::type);
|
318
|
+
COMPILE_ASSERT_TYPES_EQ(int&, add_reference<int&>::type);
|
319
|
+
COMPILE_ASSERT_TYPES_EQ(const int&, add_reference<const int&>::type);
|
320
|
+
COMPILE_ASSERT_TYPES_EQ(volatile int&,
|
321
|
+
add_reference<volatile int&>::type);
|
322
|
+
COMPILE_ASSERT_TYPES_EQ(const volatile int&,
|
323
|
+
add_reference<const volatile int&>::type);
|
324
|
+
}
|
325
|
+
|
326
|
+
TEST(TypeTraitsTest, TestIsPod) {
|
327
|
+
// Verify that arithmetic types and pointers are marked as PODs.
|
328
|
+
EXPECT_TRUE(is_pod<bool>::value);
|
329
|
+
EXPECT_TRUE(is_pod<char>::value);
|
330
|
+
EXPECT_TRUE(is_pod<unsigned char>::value);
|
331
|
+
EXPECT_TRUE(is_pod<signed char>::value);
|
332
|
+
EXPECT_TRUE(is_pod<wchar_t>::value);
|
333
|
+
EXPECT_TRUE(is_pod<int>::value);
|
334
|
+
EXPECT_TRUE(is_pod<unsigned int>::value);
|
335
|
+
EXPECT_TRUE(is_pod<short>::value);
|
336
|
+
EXPECT_TRUE(is_pod<unsigned short>::value);
|
337
|
+
EXPECT_TRUE(is_pod<long>::value);
|
338
|
+
EXPECT_TRUE(is_pod<unsigned long>::value);
|
339
|
+
EXPECT_TRUE(is_pod<float>::value);
|
340
|
+
EXPECT_TRUE(is_pod<double>::value);
|
341
|
+
EXPECT_TRUE(is_pod<long double>::value);
|
342
|
+
EXPECT_TRUE(is_pod<string*>::value);
|
343
|
+
EXPECT_TRUE(is_pod<A*>::value);
|
344
|
+
EXPECT_TRUE(is_pod<const B*>::value);
|
345
|
+
EXPECT_TRUE(is_pod<C**>::value);
|
346
|
+
EXPECT_TRUE(is_pod<const int>::value);
|
347
|
+
EXPECT_TRUE(is_pod<char* volatile>::value);
|
348
|
+
EXPECT_TRUE(is_pod<const volatile double>::value);
|
349
|
+
#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
|
350
|
+
EXPECT_TRUE(is_pod<G>::value);
|
351
|
+
EXPECT_TRUE(is_pod<const G>::value);
|
352
|
+
EXPECT_TRUE(is_pod<volatile G>::value);
|
353
|
+
EXPECT_TRUE(is_pod<const volatile G>::value);
|
354
|
+
#endif
|
355
|
+
|
356
|
+
// Verify that some non-POD types are not marked as PODs.
|
357
|
+
EXPECT_FALSE(is_pod<void>::value);
|
358
|
+
EXPECT_FALSE(is_pod<string>::value);
|
359
|
+
EXPECT_FALSE((is_pod<pair<int, int> >::value));
|
360
|
+
EXPECT_FALSE(is_pod<A>::value);
|
361
|
+
EXPECT_FALSE(is_pod<B>::value);
|
362
|
+
EXPECT_FALSE(is_pod<C>::value);
|
363
|
+
EXPECT_FALSE(is_pod<const string>::value);
|
364
|
+
EXPECT_FALSE(is_pod<volatile A>::value);
|
365
|
+
EXPECT_FALSE(is_pod<const volatile B>::value);
|
366
|
+
}
|
367
|
+
|
368
|
+
TEST(TypeTraitsTest, TestHasTrivialConstructor) {
|
369
|
+
// Verify that arithmetic types and pointers have trivial constructors.
|
370
|
+
EXPECT_TRUE(has_trivial_constructor<bool>::value);
|
371
|
+
EXPECT_TRUE(has_trivial_constructor<char>::value);
|
372
|
+
EXPECT_TRUE(has_trivial_constructor<unsigned char>::value);
|
373
|
+
EXPECT_TRUE(has_trivial_constructor<signed char>::value);
|
374
|
+
EXPECT_TRUE(has_trivial_constructor<wchar_t>::value);
|
375
|
+
EXPECT_TRUE(has_trivial_constructor<int>::value);
|
376
|
+
EXPECT_TRUE(has_trivial_constructor<unsigned int>::value);
|
377
|
+
EXPECT_TRUE(has_trivial_constructor<short>::value);
|
378
|
+
EXPECT_TRUE(has_trivial_constructor<unsigned short>::value);
|
379
|
+
EXPECT_TRUE(has_trivial_constructor<long>::value);
|
380
|
+
EXPECT_TRUE(has_trivial_constructor<unsigned long>::value);
|
381
|
+
EXPECT_TRUE(has_trivial_constructor<float>::value);
|
382
|
+
EXPECT_TRUE(has_trivial_constructor<double>::value);
|
383
|
+
EXPECT_TRUE(has_trivial_constructor<long double>::value);
|
384
|
+
EXPECT_TRUE(has_trivial_constructor<string*>::value);
|
385
|
+
EXPECT_TRUE(has_trivial_constructor<A*>::value);
|
386
|
+
EXPECT_TRUE(has_trivial_constructor<const B*>::value);
|
387
|
+
EXPECT_TRUE(has_trivial_constructor<C**>::value);
|
388
|
+
|
389
|
+
// Verify that pairs and arrays of such types have trivial
|
390
|
+
// constructors.
|
391
|
+
typedef int int10[10];
|
392
|
+
EXPECT_TRUE((has_trivial_constructor<pair<int, char*> >::value));
|
393
|
+
EXPECT_TRUE(has_trivial_constructor<int10>::value);
|
394
|
+
|
395
|
+
// Verify that pairs of types without trivial constructors
|
396
|
+
// are not marked as trivial.
|
397
|
+
EXPECT_FALSE((has_trivial_constructor<pair<int, string> >::value));
|
398
|
+
EXPECT_FALSE((has_trivial_constructor<pair<string, int> >::value));
|
399
|
+
|
400
|
+
// Verify that types without trivial constructors are
|
401
|
+
// correctly marked as such.
|
402
|
+
EXPECT_FALSE(has_trivial_constructor<string>::value);
|
403
|
+
EXPECT_FALSE(has_trivial_constructor<vector<int> >::value);
|
404
|
+
|
405
|
+
// Verify that E, which we have declared to have a trivial
|
406
|
+
// constructor, is correctly marked as such.
|
407
|
+
EXPECT_TRUE(has_trivial_constructor<E>::value);
|
408
|
+
}
|
409
|
+
|
410
|
+
TEST(TypeTraitsTest, TestHasTrivialCopy) {
|
411
|
+
// Verify that arithmetic types and pointers have trivial copy
|
412
|
+
// constructors.
|
413
|
+
EXPECT_TRUE(has_trivial_copy<bool>::value);
|
414
|
+
EXPECT_TRUE(has_trivial_copy<char>::value);
|
415
|
+
EXPECT_TRUE(has_trivial_copy<unsigned char>::value);
|
416
|
+
EXPECT_TRUE(has_trivial_copy<signed char>::value);
|
417
|
+
EXPECT_TRUE(has_trivial_copy<wchar_t>::value);
|
418
|
+
EXPECT_TRUE(has_trivial_copy<int>::value);
|
419
|
+
EXPECT_TRUE(has_trivial_copy<unsigned int>::value);
|
420
|
+
EXPECT_TRUE(has_trivial_copy<short>::value);
|
421
|
+
EXPECT_TRUE(has_trivial_copy<unsigned short>::value);
|
422
|
+
EXPECT_TRUE(has_trivial_copy<long>::value);
|
423
|
+
EXPECT_TRUE(has_trivial_copy<unsigned long>::value);
|
424
|
+
EXPECT_TRUE(has_trivial_copy<float>::value);
|
425
|
+
EXPECT_TRUE(has_trivial_copy<double>::value);
|
426
|
+
EXPECT_TRUE(has_trivial_copy<long double>::value);
|
427
|
+
EXPECT_TRUE(has_trivial_copy<string*>::value);
|
428
|
+
EXPECT_TRUE(has_trivial_copy<A*>::value);
|
429
|
+
EXPECT_TRUE(has_trivial_copy<const B*>::value);
|
430
|
+
EXPECT_TRUE(has_trivial_copy<C**>::value);
|
431
|
+
|
432
|
+
// Verify that pairs and arrays of such types have trivial
|
433
|
+
// copy constructors.
|
434
|
+
typedef int int10[10];
|
435
|
+
EXPECT_TRUE((has_trivial_copy<pair<int, char*> >::value));
|
436
|
+
EXPECT_TRUE(has_trivial_copy<int10>::value);
|
437
|
+
|
438
|
+
// Verify that pairs of types without trivial copy constructors
|
439
|
+
// are not marked as trivial.
|
440
|
+
EXPECT_FALSE((has_trivial_copy<pair<int, string> >::value));
|
441
|
+
EXPECT_FALSE((has_trivial_copy<pair<string, int> >::value));
|
442
|
+
|
443
|
+
// Verify that types without trivial copy constructors are
|
444
|
+
// correctly marked as such.
|
445
|
+
EXPECT_FALSE(has_trivial_copy<string>::value);
|
446
|
+
EXPECT_FALSE(has_trivial_copy<vector<int> >::value);
|
447
|
+
|
448
|
+
// Verify that C, which we have declared to have a trivial
|
449
|
+
// copy constructor, is correctly marked as such.
|
450
|
+
EXPECT_TRUE(has_trivial_copy<C>::value);
|
451
|
+
}
|
452
|
+
|
453
|
+
TEST(TypeTraitsTest, TestHasTrivialAssign) {
|
454
|
+
// Verify that arithmetic types and pointers have trivial assignment
|
455
|
+
// operators.
|
456
|
+
EXPECT_TRUE(has_trivial_assign<bool>::value);
|
457
|
+
EXPECT_TRUE(has_trivial_assign<char>::value);
|
458
|
+
EXPECT_TRUE(has_trivial_assign<unsigned char>::value);
|
459
|
+
EXPECT_TRUE(has_trivial_assign<signed char>::value);
|
460
|
+
EXPECT_TRUE(has_trivial_assign<wchar_t>::value);
|
461
|
+
EXPECT_TRUE(has_trivial_assign<int>::value);
|
462
|
+
EXPECT_TRUE(has_trivial_assign<unsigned int>::value);
|
463
|
+
EXPECT_TRUE(has_trivial_assign<short>::value);
|
464
|
+
EXPECT_TRUE(has_trivial_assign<unsigned short>::value);
|
465
|
+
EXPECT_TRUE(has_trivial_assign<long>::value);
|
466
|
+
EXPECT_TRUE(has_trivial_assign<unsigned long>::value);
|
467
|
+
EXPECT_TRUE(has_trivial_assign<float>::value);
|
468
|
+
EXPECT_TRUE(has_trivial_assign<double>::value);
|
469
|
+
EXPECT_TRUE(has_trivial_assign<long double>::value);
|
470
|
+
EXPECT_TRUE(has_trivial_assign<string*>::value);
|
471
|
+
EXPECT_TRUE(has_trivial_assign<A*>::value);
|
472
|
+
EXPECT_TRUE(has_trivial_assign<const B*>::value);
|
473
|
+
EXPECT_TRUE(has_trivial_assign<C**>::value);
|
474
|
+
|
475
|
+
// Verify that pairs and arrays of such types have trivial
|
476
|
+
// assignment operators.
|
477
|
+
typedef int int10[10];
|
478
|
+
EXPECT_TRUE((has_trivial_assign<pair<int, char*> >::value));
|
479
|
+
EXPECT_TRUE(has_trivial_assign<int10>::value);
|
480
|
+
|
481
|
+
// Verify that pairs of types without trivial assignment operators
|
482
|
+
// are not marked as trivial.
|
483
|
+
EXPECT_FALSE((has_trivial_assign<pair<int, string> >::value));
|
484
|
+
EXPECT_FALSE((has_trivial_assign<pair<string, int> >::value));
|
485
|
+
|
486
|
+
// Verify that types without trivial assignment operators are
|
487
|
+
// correctly marked as such.
|
488
|
+
EXPECT_FALSE(has_trivial_assign<string>::value);
|
489
|
+
EXPECT_FALSE(has_trivial_assign<vector<int> >::value);
|
490
|
+
|
491
|
+
// Verify that D, which we have declared to have a trivial
|
492
|
+
// assignment operator, is correctly marked as such.
|
493
|
+
EXPECT_TRUE(has_trivial_assign<D>::value);
|
494
|
+
}
|
495
|
+
|
496
|
+
TEST(TypeTraitsTest, TestHasTrivialDestructor) {
|
497
|
+
// Verify that arithmetic types and pointers have trivial destructors.
|
498
|
+
EXPECT_TRUE(has_trivial_destructor<bool>::value);
|
499
|
+
EXPECT_TRUE(has_trivial_destructor<char>::value);
|
500
|
+
EXPECT_TRUE(has_trivial_destructor<unsigned char>::value);
|
501
|
+
EXPECT_TRUE(has_trivial_destructor<signed char>::value);
|
502
|
+
EXPECT_TRUE(has_trivial_destructor<wchar_t>::value);
|
503
|
+
EXPECT_TRUE(has_trivial_destructor<int>::value);
|
504
|
+
EXPECT_TRUE(has_trivial_destructor<unsigned int>::value);
|
505
|
+
EXPECT_TRUE(has_trivial_destructor<short>::value);
|
506
|
+
EXPECT_TRUE(has_trivial_destructor<unsigned short>::value);
|
507
|
+
EXPECT_TRUE(has_trivial_destructor<long>::value);
|
508
|
+
EXPECT_TRUE(has_trivial_destructor<unsigned long>::value);
|
509
|
+
EXPECT_TRUE(has_trivial_destructor<float>::value);
|
510
|
+
EXPECT_TRUE(has_trivial_destructor<double>::value);
|
511
|
+
EXPECT_TRUE(has_trivial_destructor<long double>::value);
|
512
|
+
EXPECT_TRUE(has_trivial_destructor<string*>::value);
|
513
|
+
EXPECT_TRUE(has_trivial_destructor<A*>::value);
|
514
|
+
EXPECT_TRUE(has_trivial_destructor<const B*>::value);
|
515
|
+
EXPECT_TRUE(has_trivial_destructor<C**>::value);
|
516
|
+
|
517
|
+
// Verify that pairs and arrays of such types have trivial
|
518
|
+
// destructors.
|
519
|
+
typedef int int10[10];
|
520
|
+
EXPECT_TRUE((has_trivial_destructor<pair<int, char*> >::value));
|
521
|
+
EXPECT_TRUE(has_trivial_destructor<int10>::value);
|
522
|
+
|
523
|
+
// Verify that pairs of types without trivial destructors
|
524
|
+
// are not marked as trivial.
|
525
|
+
EXPECT_FALSE((has_trivial_destructor<pair<int, string> >::value));
|
526
|
+
EXPECT_FALSE((has_trivial_destructor<pair<string, int> >::value));
|
527
|
+
|
528
|
+
// Verify that types without trivial destructors are
|
529
|
+
// correctly marked as such.
|
530
|
+
EXPECT_FALSE(has_trivial_destructor<string>::value);
|
531
|
+
EXPECT_FALSE(has_trivial_destructor<vector<int> >::value);
|
532
|
+
|
533
|
+
// Verify that F, which we have declared to have a trivial
|
534
|
+
// destructor, is correctly marked as such.
|
535
|
+
EXPECT_TRUE(has_trivial_destructor<F>::value);
|
536
|
+
}
|
537
|
+
|
538
|
+
// Tests remove_pointer.
|
539
|
+
TEST(TypeTraitsTest, TestRemovePointer) {
|
540
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_pointer<int>::type);
|
541
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_pointer<int*>::type);
|
542
|
+
COMPILE_ASSERT_TYPES_EQ(const int, remove_pointer<const int*>::type);
|
543
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_pointer<int* const>::type);
|
544
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_pointer<int* volatile>::type);
|
545
|
+
}
|
546
|
+
|
547
|
+
TEST(TypeTraitsTest, TestRemoveConst) {
|
548
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_const<int>::type);
|
549
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_const<const int>::type);
|
550
|
+
COMPILE_ASSERT_TYPES_EQ(int *, remove_const<int * const>::type);
|
551
|
+
// TR1 examples.
|
552
|
+
COMPILE_ASSERT_TYPES_EQ(const int *, remove_const<const int *>::type);
|
553
|
+
COMPILE_ASSERT_TYPES_EQ(volatile int,
|
554
|
+
remove_const<const volatile int>::type);
|
555
|
+
}
|
556
|
+
|
557
|
+
TEST(TypeTraitsTest, TestRemoveVolatile) {
|
558
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_volatile<int>::type);
|
559
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_volatile<volatile int>::type);
|
560
|
+
COMPILE_ASSERT_TYPES_EQ(int *, remove_volatile<int * volatile>::type);
|
561
|
+
// TR1 examples.
|
562
|
+
COMPILE_ASSERT_TYPES_EQ(volatile int *,
|
563
|
+
remove_volatile<volatile int *>::type);
|
564
|
+
COMPILE_ASSERT_TYPES_EQ(const int,
|
565
|
+
remove_volatile<const volatile int>::type);
|
566
|
+
}
|
567
|
+
|
568
|
+
TEST(TypeTraitsTest, TestRemoveCV) {
|
569
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_cv<int>::type);
|
570
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_cv<volatile int>::type);
|
571
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_cv<const int>::type);
|
572
|
+
COMPILE_ASSERT_TYPES_EQ(int *, remove_cv<int * const volatile>::type);
|
573
|
+
// TR1 examples.
|
574
|
+
COMPILE_ASSERT_TYPES_EQ(const volatile int *,
|
575
|
+
remove_cv<const volatile int *>::type);
|
576
|
+
COMPILE_ASSERT_TYPES_EQ(int,
|
577
|
+
remove_cv<const volatile int>::type);
|
578
|
+
}
|
579
|
+
|
580
|
+
TEST(TypeTraitsTest, TestRemoveReference) {
|
581
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_reference<int>::type);
|
582
|
+
COMPILE_ASSERT_TYPES_EQ(int, remove_reference<int&>::type);
|
583
|
+
COMPILE_ASSERT_TYPES_EQ(const int, remove_reference<const int&>::type);
|
584
|
+
COMPILE_ASSERT_TYPES_EQ(int*, remove_reference<int * &>::type);
|
585
|
+
}
|
586
|
+
|
587
|
+
TEST(TypeTraitsTest, TestIsSame) {
|
588
|
+
EXPECT_TRUE((is_same<int32, int32>::value));
|
589
|
+
EXPECT_FALSE((is_same<int32, int64>::value));
|
590
|
+
EXPECT_FALSE((is_same<int64, int32>::value));
|
591
|
+
EXPECT_FALSE((is_same<int, const int>::value));
|
592
|
+
|
593
|
+
EXPECT_TRUE((is_same<void, void>::value));
|
594
|
+
EXPECT_FALSE((is_same<void, int>::value));
|
595
|
+
EXPECT_FALSE((is_same<int, void>::value));
|
596
|
+
|
597
|
+
EXPECT_TRUE((is_same<int*, int*>::value));
|
598
|
+
EXPECT_TRUE((is_same<void*, void*>::value));
|
599
|
+
EXPECT_FALSE((is_same<int*, void*>::value));
|
600
|
+
EXPECT_FALSE((is_same<void*, int*>::value));
|
601
|
+
EXPECT_FALSE((is_same<void*, const void*>::value));
|
602
|
+
EXPECT_FALSE((is_same<void*, void* const>::value));
|
603
|
+
|
604
|
+
EXPECT_TRUE((is_same<Base*, Base*>::value));
|
605
|
+
EXPECT_TRUE((is_same<Derived*, Derived*>::value));
|
606
|
+
EXPECT_FALSE((is_same<Base*, Derived*>::value));
|
607
|
+
EXPECT_FALSE((is_same<Derived*, Base*>::value));
|
608
|
+
}
|
609
|
+
|
610
|
+
TEST(TypeTraitsTest, TestConvertible) {
|
611
|
+
#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
|
612
|
+
EXPECT_TRUE((is_convertible<int, int>::value));
|
613
|
+
EXPECT_TRUE((is_convertible<int, long>::value));
|
614
|
+
EXPECT_TRUE((is_convertible<long, int>::value));
|
615
|
+
|
616
|
+
EXPECT_TRUE((is_convertible<int*, void*>::value));
|
617
|
+
EXPECT_FALSE((is_convertible<void*, int*>::value));
|
618
|
+
|
619
|
+
EXPECT_TRUE((is_convertible<Derived*, Base*>::value));
|
620
|
+
EXPECT_FALSE((is_convertible<Base*, Derived*>::value));
|
621
|
+
EXPECT_TRUE((is_convertible<Derived*, const Base*>::value));
|
622
|
+
EXPECT_FALSE((is_convertible<const Derived*, Base*>::value));
|
623
|
+
#endif
|
624
|
+
}
|
625
|
+
|
626
|
+
} // namespace
|
627
|
+
|
628
|
+
#include <iostream>
|
629
|
+
|
630
|
+
int main(int, char **) {
|
631
|
+
// All the work is done in the static constructors. If they don't
|
632
|
+
// die, the tests have all passed.
|
633
|
+
std::cout << "PASS\n";
|
634
|
+
return 0;
|
635
|
+
}
|
636
|
+
|