Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: Source/wtf/TypeTraits.cpp

Issue 581683002: Expanding Type Traits to make Vector use mem ops more. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: More efficient Vector with more type traits. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/wtf/TypeTraits.h ('k') | Source/wtf/VectorTraits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 COMPILE_ASSERT(!IsInteger<const char*>::value, WTF_IsInteger_const_char_pointer_ false); 45 COMPILE_ASSERT(!IsInteger<const char*>::value, WTF_IsInteger_const_char_pointer_ false);
46 COMPILE_ASSERT(!IsInteger<volatile char*>::value, WTF_IsInteger_volatile_char_po inter_false); 46 COMPILE_ASSERT(!IsInteger<volatile char*>::value, WTF_IsInteger_volatile_char_po inter_false);
47 COMPILE_ASSERT(!IsInteger<double>::value, WTF_IsInteger_double_false); 47 COMPILE_ASSERT(!IsInteger<double>::value, WTF_IsInteger_double_false);
48 COMPILE_ASSERT(!IsInteger<float>::value, WTF_IsInteger_float_false); 48 COMPILE_ASSERT(!IsInteger<float>::value, WTF_IsInteger_float_false);
49 49
50 COMPILE_ASSERT(IsFloatingPoint<float>::value, WTF_IsFloatingPoint_float_true); 50 COMPILE_ASSERT(IsFloatingPoint<float>::value, WTF_IsFloatingPoint_float_true);
51 COMPILE_ASSERT(IsFloatingPoint<double>::value, WTF_IsFloatingPoint_double_true); 51 COMPILE_ASSERT(IsFloatingPoint<double>::value, WTF_IsFloatingPoint_double_true);
52 COMPILE_ASSERT(IsFloatingPoint<long double>::value, WTF_IsFloatingPoint_long_dou ble_true); 52 COMPILE_ASSERT(IsFloatingPoint<long double>::value, WTF_IsFloatingPoint_long_dou ble_true);
53 COMPILE_ASSERT(!IsFloatingPoint<int>::value, WTF_IsFloatingPoint_int_false); 53 COMPILE_ASSERT(!IsFloatingPoint<int>::value, WTF_IsFloatingPoint_int_false);
54 54
55 COMPILE_ASSERT(IsPointer<void*>::value, WTF_IsPointer_void_star_true);
56 COMPILE_ASSERT(IsPointer<char*>::value, WTF_IsPointer_char_star_true);
57 COMPILE_ASSERT(IsPointer<const char*>::value, WTF_IsPointer_const_char_star_true );
58 COMPILE_ASSERT(!IsPointer<char>::value, WTF_IsPointer_char_false);
59 COMPILE_ASSERT(!IsPointer<int>::value, WTF_IsPointer_int_false);
60 COMPILE_ASSERT(!IsPointer<long>::value, WTF_IsPointer_long_false);
61
62 enum TestEnum { TestEnumValue };
63 COMPILE_ASSERT(IsEnum<TestEnum>::value, WTF_IsEnum_enum_true);
64 COMPILE_ASSERT(!IsEnum<int>::value, WTF_IsEnum_int_false);
65 COMPILE_ASSERT(!IsEnum<TestEnum*>::value, WTF_IsEnum_enum_star_false);
66
67 COMPILE_ASSERT(IsScalar<TestEnum>::value, WTF_IsScalar_enum_true);
68 COMPILE_ASSERT(IsScalar<int>::value, WTF_IsScalar_int_true);
69 COMPILE_ASSERT(IsScalar<TestEnum*>::value, WTF_IsScalar_enum_star_true);
70 COMPILE_ASSERT(IsScalar<double>::value, WTF_IsScalar_double_true);
71
55 COMPILE_ASSERT(IsPod<bool>::value, WTF_IsPod_bool_true); 72 COMPILE_ASSERT(IsPod<bool>::value, WTF_IsPod_bool_true);
56 COMPILE_ASSERT(IsPod<char>::value, WTF_IsPod_char_true); 73 COMPILE_ASSERT(IsPod<char>::value, WTF_IsPod_char_true);
57 COMPILE_ASSERT(IsPod<signed char>::value, WTF_IsPod_signed_char_true); 74 COMPILE_ASSERT(IsPod<signed char>::value, WTF_IsPod_signed_char_true);
58 COMPILE_ASSERT(IsPod<unsigned char>::value, WTF_IsPod_unsigned_char_true); 75 COMPILE_ASSERT(IsPod<unsigned char>::value, WTF_IsPod_unsigned_char_true);
59 COMPILE_ASSERT(IsPod<short>::value, WTF_IsPod_short_true); 76 COMPILE_ASSERT(IsPod<short>::value, WTF_IsPod_short_true);
60 COMPILE_ASSERT(IsPod<unsigned short>::value, WTF_IsPod_unsigned_short_true); 77 COMPILE_ASSERT(IsPod<unsigned short>::value, WTF_IsPod_unsigned_short_true);
61 COMPILE_ASSERT(IsPod<int>::value, WTF_IsPod_int_true); 78 COMPILE_ASSERT(IsPod<int>::value, WTF_IsPod_int_true);
62 COMPILE_ASSERT(IsPod<unsigned>::value, WTF_IsPod_unsigned_int_true); 79 COMPILE_ASSERT(IsPod<unsigned>::value, WTF_IsPod_unsigned_int_true);
63 COMPILE_ASSERT(IsPod<long>::value, WTF_IsPod_long_true); 80 COMPILE_ASSERT(IsPod<long>::value, WTF_IsPod_long_true);
64 COMPILE_ASSERT(IsPod<unsigned long>::value, WTF_IsPod_unsigned_long_true); 81 COMPILE_ASSERT(IsPod<unsigned long>::value, WTF_IsPod_unsigned_long_true);
65 COMPILE_ASSERT(IsPod<long long>::value, WTF_IsPod_long_long_true); 82 COMPILE_ASSERT(IsPod<long long>::value, WTF_IsPod_long_long_true);
66 COMPILE_ASSERT(IsPod<unsigned long long>::value, WTF_IsPod_unsigned_long_long_tr ue); 83 COMPILE_ASSERT(IsPod<unsigned long long>::value, WTF_IsPod_unsigned_long_long_tr ue);
67 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED) 84 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
68 COMPILE_ASSERT(IsPod<wchar_t>::value, WTF_IsPod_wchar_t_true); 85 COMPILE_ASSERT(IsPod<wchar_t>::value, WTF_IsPod_wchar_t_true);
69 #endif 86 #endif
70 COMPILE_ASSERT(IsPod<char*>::value, WTF_IsPod_char_pointer_true); 87 COMPILE_ASSERT(IsPod<char*>::value, WTF_IsPod_char_pointer_true);
71 COMPILE_ASSERT(IsPod<const char*>::value, WTF_IsPod_const_char_pointer_true); 88 COMPILE_ASSERT(IsPod<const char*>::value, WTF_IsPod_const_char_pointer_true);
72 COMPILE_ASSERT(IsPod<volatile char*>::value, WTF_IsPod_volatile_char_pointer_tru e); 89 COMPILE_ASSERT(IsPod<volatile char*>::value, WTF_IsPod_volatile_char_pointer_tru e);
73 COMPILE_ASSERT(IsPod<double>::value, WTF_IsPod_double_true); 90 COMPILE_ASSERT(IsPod<double>::value, WTF_IsPod_double_true);
74 COMPILE_ASSERT(IsPod<long double>::value, WTF_IsPod_long_double_true); 91 COMPILE_ASSERT(IsPod<long double>::value, WTF_IsPod_long_double_true);
75 COMPILE_ASSERT(IsPod<float>::value, WTF_IsPod_float_true); 92 COMPILE_ASSERT(IsPod<float>::value, WTF_IsPod_float_true);
76 COMPILE_ASSERT(!IsPod<IsPod<bool> >::value, WTF_IsPod_struct_false); 93 struct VirtualClass {
94 virtual void A() { }
95 };
96 COMPILE_ASSERT(!IsTriviallyMoveAssignable<VirtualClass>::value, WTF_IsTriviallyM oveAssignable_VirtualClass_false);
97 COMPILE_ASSERT(!IsScalar<VirtualClass>::value, WTF_IsScalar_class_false);
98 COMPILE_ASSERT(IsScalar<VirtualClass*>::value, WTF_IsScalar_class_ptr_true);
99
100 struct DestructorClass {
101 ~DestructorClass() { }
102 };
103 COMPILE_ASSERT(IsTriviallyMoveAssignable<DestructorClass>::value, WTF_IsTriviall yMoveAssignable_DestructorClass_true);
104 COMPILE_ASSERT(IsTriviallyCopyAssignable<DestructorClass>::value, WTF_IsTriviall yCopyAssignable_DestructorClass_true);
105 COMPILE_ASSERT(IsTriviallyDefaultConstructible<DestructorClass>::value, WTF_IsTr iviallyDefaultConstructable_DestructorClass_true);
106
107 struct MixedPrivate {
108 int M2() { return m2; }
109 int m1;
110 private:
111 int m2;
112 };
113 COMPILE_ASSERT(IsTriviallyMoveAssignable<MixedPrivate>::value, WTF_IsTriviallyMo veAssignable_MixedPrivate_true);
114 COMPILE_ASSERT(IsTriviallyCopyAssignable<MixedPrivate>::value, WTF_IsTriviallyCo pyAssignable_MixedPrivate_true);
115 COMPILE_ASSERT(IsTriviallyDefaultConstructible<MixedPrivate>::value, WTF_IsTrivi allyDefaultConstructable_MixedPrivate_true);
116 struct JustPrivate {
117 int M2() { return m2; }
118 private:
119 int m2;
120 };
121 COMPILE_ASSERT(IsTriviallyMoveAssignable<JustPrivate>::value, WTF_IsTriviallyMov eAssignable_JustPrivate_true);
122 COMPILE_ASSERT(IsTriviallyCopyAssignable<JustPrivate>::value, WTF_IsTriviallyCop yAssignable_JustPrivate_true);
123 COMPILE_ASSERT(IsTriviallyDefaultConstructible<JustPrivate>::value, WTF_IsTrivia llyDefaultConstructable_JustPrivate_true);
124 struct JustPublic {
125 int m2;
126 };
127 COMPILE_ASSERT(IsTriviallyMoveAssignable<JustPublic>::value, WTF_IsTriviallyMove Assignable_JustPublic_true);
128 COMPILE_ASSERT(IsTriviallyCopyAssignable<JustPublic>::value, WTF_IsTriviallyCopy Assignable_JustPublic_true);
129 COMPILE_ASSERT(IsTriviallyDefaultConstructible<JustPublic>::value, WTF_IsTrivial lyDefaultConstructable_JustPublic_true);
130 struct NestedInherited : public JustPublic, JustPrivate {
131 float m3;
132 };
133 COMPILE_ASSERT(IsTriviallyMoveAssignable<NestedInherited>::value, WTF_IsTriviall yMoveAssignable_NestedInherited_true);
134 COMPILE_ASSERT(IsTriviallyCopyAssignable<NestedInherited>::value, WTF_IsTriviall yCopyAssignable_NestedInherited_true);
135 COMPILE_ASSERT(IsTriviallyDefaultConstructible<NestedInherited>::value, WTF_IsTr iviallyDefaultConstructable_NestedInherited_true);
136 struct NestedOwned {
137 JustPublic m1;
138 JustPrivate m2;
139 float m3;
140 };
141
142 COMPILE_ASSERT(IsTriviallyMoveAssignable<NestedOwned>::value, WTF_IsTriviallyMov eAssignable_NestedOwned_true);
143 COMPILE_ASSERT(IsTriviallyCopyAssignable<NestedOwned>::value, WTF_IsTriviallyCop yAssignable_NestedOwned_true);
144 COMPILE_ASSERT(IsTriviallyDefaultConstructible<NestedOwned>::value, WTF_IsTrivia llyDefaultConstructable_NestedOwned_true);
145
146 class NonCopyableClass {
147 #if COMPILER_SUPPORTS(CXX_DELETED_FUNCTIONS)
148 NonCopyableClass(const NonCopyableClass&) = delete;
149 NonCopyableClass& operator=(const NonCopyableClass&) = delete;
150 #else
151 NonCopyableClass(const NonCopyableClass&);
152 NonCopyableClass& operator=(const NonCopyableClass&);
153 #endif // COMPILER_SUPPORTS(CXX_DELETED_FUNCTIONS)
154 };
155 #if 0 // Compilers don't get this "right" yet if using = delete.
156 COMPILE_ASSERT(!IsTriviallyMoveAssignable<NonCopyableClass>::value, WTF_IsTrivia llyMoveAssignable_NonCopyableClass_false);
157 COMPILE_ASSERT(!IsTriviallyCopyAssignable<NonCopyableClass>::value, WTF_IsTrivia llyCopyAssignable_NonCopyableClass_false);
158 COMPILE_ASSERT(IsTriviallyDefaultConstructible<NonCopyableClass>::value, WTF_IsT riviallyDefaultConstructable_NonCopyableClass_true);
159 #endif // 0
77 160
78 enum IsConvertibleToIntegerCheck { }; 161 enum IsConvertibleToIntegerCheck { };
79 COMPILE_ASSERT(IsConvertibleToInteger<IsConvertibleToIntegerCheck>::value, WTF_I sConvertibleToInteger_enum_true); 162 COMPILE_ASSERT(IsConvertibleToInteger<IsConvertibleToIntegerCheck>::value, WTF_I sConvertibleToInteger_enum_true);
80 COMPILE_ASSERT(IsConvertibleToInteger<bool>::value, WTF_IsConvertibleToInteger_b ool_true); 163 COMPILE_ASSERT(IsConvertibleToInteger<bool>::value, WTF_IsConvertibleToInteger_b ool_true);
81 COMPILE_ASSERT(IsConvertibleToInteger<char>::value, WTF_IsConvertibleToInteger_c har_true); 164 COMPILE_ASSERT(IsConvertibleToInteger<char>::value, WTF_IsConvertibleToInteger_c har_true);
82 COMPILE_ASSERT(IsConvertibleToInteger<signed char>::value, WTF_IsConvertibleToIn teger_signed_char_true); 165 COMPILE_ASSERT(IsConvertibleToInteger<signed char>::value, WTF_IsConvertibleToIn teger_signed_char_true);
83 COMPILE_ASSERT(IsConvertibleToInteger<unsigned char>::value, WTF_IsConvertibleTo Integer_unsigned_char_true); 166 COMPILE_ASSERT(IsConvertibleToInteger<unsigned char>::value, WTF_IsConvertibleTo Integer_unsigned_char_true);
84 COMPILE_ASSERT(IsConvertibleToInteger<short>::value, WTF_IsConvertibleToInteger_ short_true); 167 COMPILE_ASSERT(IsConvertibleToInteger<short>::value, WTF_IsConvertibleToInteger_ short_true);
85 COMPILE_ASSERT(IsConvertibleToInteger<unsigned short>::value, WTF_IsConvertibleT oInteger_unsigned_short_true); 168 COMPILE_ASSERT(IsConvertibleToInteger<unsigned short>::value, WTF_IsConvertibleT oInteger_unsigned_short_true);
86 COMPILE_ASSERT(IsConvertibleToInteger<int>::value, WTF_IsConvertibleToInteger_in t_true); 169 COMPILE_ASSERT(IsConvertibleToInteger<int>::value, WTF_IsConvertibleToInteger_in t_true);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 typedef int IntArray[]; 233 typedef int IntArray[];
151 typedef int IntArraySized[4]; 234 typedef int IntArraySized[4];
152 235
153 COMPILE_ASSERT((IsArray<IntArray>::value), WTF_Test_IsArray_int_array); 236 COMPILE_ASSERT((IsArray<IntArray>::value), WTF_Test_IsArray_int_array);
154 COMPILE_ASSERT((IsArray<IntArraySized>::value), WTF_Test_IsArray_int_sized_array ); 237 COMPILE_ASSERT((IsArray<IntArraySized>::value), WTF_Test_IsArray_int_sized_array );
155 238
156 COMPILE_ASSERT((IsSameType<int, RemoveExtent<IntArray>::Type>::value), WTF_Test_ RemoveExtent_int_array); 239 COMPILE_ASSERT((IsSameType<int, RemoveExtent<IntArray>::Type>::value), WTF_Test_ RemoveExtent_int_array);
157 COMPILE_ASSERT((IsSameType<int, RemoveExtent<IntArraySized>::Type>::value), WTF_ Test_RemoveReference_int_sized_array); 240 COMPILE_ASSERT((IsSameType<int, RemoveExtent<IntArraySized>::Type>::value), WTF_ Test_RemoveReference_int_sized_array);
158 241
159 } // namespace WTF 242 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/TypeTraits.h ('k') | Source/wtf/VectorTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698