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

Side by Side Diff: src/base/functional.h

Issue 2395553002: Reland "Turn libbase into a component" (Closed)
Patch Set: Created 4 years, 2 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 | « src/base/file-utils.cc ('k') | src/base/ieee754.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 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_BASE_FUNCTIONAL_H_ 5 #ifndef V8_BASE_FUNCTIONAL_H_
6 #define V8_BASE_FUNCTIONAL_H_ 6 #define V8_BASE_FUNCTIONAL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <cstddef> 11 #include <cstddef>
12 #include <cstring> 12 #include <cstring>
13 #include <functional> 13 #include <functional>
14 #include <utility> 14 #include <utility>
15 15
16 #include "src/base/base-export.h"
16 #include "src/base/macros.h" 17 #include "src/base/macros.h"
17 18
18 namespace v8 { 19 namespace v8 {
19 namespace base { 20 namespace base {
20 21
21 // base::hash is an implementation of the hash function object specified by 22 // base::hash is an implementation of the hash function object specified by
22 // C++11. It was designed to be compatible with std::hash (in C++11) and 23 // C++11. It was designed to be compatible with std::hash (in C++11) and
23 // boost:hash (which in turn is based on the hash function object specified by 24 // boost:hash (which in turn is based on the hash function object specified by
24 // the Draft Technical Report on C++ Library Extensions (TR1)). 25 // the Draft Technical Report on C++ Library Extensions (TR1)).
25 // 26 //
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // Based on the "Hashing User-Defined Types in C++1y" proposal from Jeffrey 61 // Based on the "Hashing User-Defined Types in C++1y" proposal from Jeffrey
61 // Yasskin and Chandler Carruth, see 62 // Yasskin and Chandler Carruth, see
62 // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2012/n3333.html. 63 // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2012/n3333.html.
63 64
64 template <typename> 65 template <typename>
65 struct hash; 66 struct hash;
66 67
67 68
68 V8_INLINE size_t hash_combine() { return 0u; } 69 V8_INLINE size_t hash_combine() { return 0u; }
69 V8_INLINE size_t hash_combine(size_t seed) { return seed; } 70 V8_INLINE size_t hash_combine(size_t seed) { return seed; }
70 size_t hash_combine(size_t seed, size_t value); 71 V8_BASE_EXPORT size_t hash_combine(size_t seed, size_t value);
71 template <typename T, typename... Ts> 72 template <typename T, typename... Ts>
72 V8_INLINE size_t hash_combine(T const& v, Ts const&... vs) { 73 V8_INLINE size_t hash_combine(T const& v, Ts const&... vs) {
73 return hash_combine(hash_combine(vs...), hash<T>()(v)); 74 return hash_combine(hash_combine(vs...), hash<T>()(v));
74 } 75 }
75 76
76 77
77 template <typename Iterator> 78 template <typename Iterator>
78 V8_INLINE size_t hash_range(Iterator first, Iterator last) { 79 V8_INLINE size_t hash_range(Iterator first, Iterator last) {
79 size_t seed = 0; 80 size_t seed = 0;
80 for (; first != last; ++first) { 81 for (; first != last; ++first) {
81 seed = hash_combine(seed, *first); 82 seed = hash_combine(seed, *first);
82 } 83 }
83 return seed; 84 return seed;
84 } 85 }
85 86
86 87
87 #define V8_BASE_HASH_VALUE_TRIVIAL(type) \ 88 #define V8_BASE_HASH_VALUE_TRIVIAL(type) \
88 V8_INLINE size_t hash_value(type v) { return static_cast<size_t>(v); } 89 V8_INLINE size_t hash_value(type v) { return static_cast<size_t>(v); }
89 V8_BASE_HASH_VALUE_TRIVIAL(bool) 90 V8_BASE_HASH_VALUE_TRIVIAL(bool)
90 V8_BASE_HASH_VALUE_TRIVIAL(unsigned char) 91 V8_BASE_HASH_VALUE_TRIVIAL(unsigned char)
91 V8_BASE_HASH_VALUE_TRIVIAL(unsigned short) // NOLINT(runtime/int) 92 V8_BASE_HASH_VALUE_TRIVIAL(unsigned short) // NOLINT(runtime/int)
92 #undef V8_BASE_HASH_VALUE_TRIVIAL 93 #undef V8_BASE_HASH_VALUE_TRIVIAL
93 94
94 size_t hash_value(unsigned int); 95 V8_BASE_EXPORT size_t hash_value(unsigned int);
95 size_t hash_value(unsigned long); // NOLINT(runtime/int) 96 V8_BASE_EXPORT size_t hash_value(unsigned long); // NOLINT(runtime/int)
96 size_t hash_value(unsigned long long); // NOLINT(runtime/int) 97 V8_BASE_EXPORT size_t hash_value(unsigned long long); // NOLINT(runtime/int)
97 98
98 #define V8_BASE_HASH_VALUE_SIGNED(type) \ 99 #define V8_BASE_HASH_VALUE_SIGNED(type) \
99 V8_INLINE size_t hash_value(signed type v) { \ 100 V8_INLINE size_t hash_value(signed type v) { \
100 return hash_value(bit_cast<unsigned type>(v)); \ 101 return hash_value(bit_cast<unsigned type>(v)); \
101 } 102 }
102 V8_BASE_HASH_VALUE_SIGNED(char) 103 V8_BASE_HASH_VALUE_SIGNED(char)
103 V8_BASE_HASH_VALUE_SIGNED(short) // NOLINT(runtime/int) 104 V8_BASE_HASH_VALUE_SIGNED(short) // NOLINT(runtime/int)
104 V8_BASE_HASH_VALUE_SIGNED(int) // NOLINT(runtime/int) 105 V8_BASE_HASH_VALUE_SIGNED(int) // NOLINT(runtime/int)
105 V8_BASE_HASH_VALUE_SIGNED(long) // NOLINT(runtime/int) 106 V8_BASE_HASH_VALUE_SIGNED(long) // NOLINT(runtime/int)
106 V8_BASE_HASH_VALUE_SIGNED(long long) // NOLINT(runtime/int) 107 V8_BASE_HASH_VALUE_SIGNED(long long) // NOLINT(runtime/int)
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } \ 219 } \
219 }; 220 };
220 V8_BASE_BIT_SPECIALIZE_BIT_CAST(float, uint32_t) 221 V8_BASE_BIT_SPECIALIZE_BIT_CAST(float, uint32_t)
221 V8_BASE_BIT_SPECIALIZE_BIT_CAST(double, uint64_t) 222 V8_BASE_BIT_SPECIALIZE_BIT_CAST(double, uint64_t)
222 #undef V8_BASE_BIT_SPECIALIZE_BIT_CAST 223 #undef V8_BASE_BIT_SPECIALIZE_BIT_CAST
223 224
224 } // namespace base 225 } // namespace base
225 } // namespace v8 226 } // namespace v8
226 227
227 #endif // V8_BASE_FUNCTIONAL_H_ 228 #endif // V8_BASE_FUNCTIONAL_H_
OLDNEW
« no previous file with comments | « src/base/file-utils.cc ('k') | src/base/ieee754.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698