OLD | NEW |
1 // Copyright 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright 2006-2008 The Chromium 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 MINI_CHROMIUM_BASE_BASICTYPES_H_ | 5 #ifndef MINI_CHROMIUM_BASE_BASICTYPES_H_ |
6 #define MINI_CHROMIUM_BASE_BASICTYPES_H_ | 6 #define MINI_CHROMIUM_BASE_BASICTYPES_H_ |
7 | 7 |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 template <typename T, size_t N> | 38 template <typename T, size_t N> |
39 char (&ArraySizeHelper(const T (&array)[N]))[N]; | 39 char (&ArraySizeHelper(const T (&array)[N]))[N]; |
40 | 40 |
41 #define arraysize(array) (sizeof(ArraySizeHelper(array))) | 41 #define arraysize(array) (sizeof(ArraySizeHelper(array))) |
42 | 42 |
43 #define ARRAYSIZE_UNSAFE(a) \ | 43 #define ARRAYSIZE_UNSAFE(a) \ |
44 ((sizeof(a) / sizeof(*(a))) / \ | 44 ((sizeof(a) / sizeof(*(a))) / \ |
45 static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) | 45 static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) |
46 | 46 |
47 template<typename To, typename From> | |
48 inline To implicit_cast(const From& f) { | |
49 return f; | |
50 } | |
51 | |
52 template <typename Dest, typename Source> | 47 template <typename Dest, typename Source> |
53 inline Dest bit_cast(const Source& source) { | 48 inline Dest bit_cast(const Source& source) { |
54 static_assert(sizeof(Dest) == sizeof(Source), "sizes must be equal"); | 49 static_assert(sizeof(Dest) == sizeof(Source), "sizes must be equal"); |
55 | 50 |
56 Dest dest; | 51 Dest dest; |
57 memcpy(&dest, &source, sizeof(dest)); | 52 memcpy(&dest, &source, sizeof(dest)); |
58 return dest; | 53 return dest; |
59 } | 54 } |
60 | 55 |
61 template<typename T> | 56 template<typename T> |
62 inline void ignore_result(const T&) { | 57 inline void ignore_result(const T&) { |
63 } | 58 } |
64 | 59 |
65 #endif // MINI_CHROMIUM_BASE_BASICTYPES_H_ | 60 #endif // MINI_CHROMIUM_BASE_BASICTYPES_H_ |
OLD | NEW |