OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 #endif | 105 #endif |
106 | 106 |
107 namespace WTF { | 107 namespace WTF { |
108 | 108 |
109 /* | 109 /* |
110 * C++'s idea of a reinterpret_cast lacks sufficient cojones. | 110 * C++'s idea of a reinterpret_cast lacks sufficient cojones. |
111 */ | 111 */ |
112 template<typename TO, typename FROM> | 112 template<typename TO, typename FROM> |
113 inline TO bitwise_cast(FROM from) | 113 inline TO bitwise_cast(FROM from) |
114 { | 114 { |
115 COMPILE_ASSERT(sizeof(TO) == sizeof(FROM), WTF_bitwise_cast_sizeof_casted_ty
pes_is_equal); | 115 static_assert(sizeof(TO) == sizeof(FROM), "WTF::bitwise_cast sizeof casted t
ypes should be equal"); |
116 union { | 116 union { |
117 FROM from; | 117 FROM from; |
118 TO to; | 118 TO to; |
119 } u; | 119 } u; |
120 u.from = from; | 120 u.from = from; |
121 return u.to; | 121 return u.to; |
122 } | 122 } |
123 | 123 |
124 template<typename To, typename From> | 124 template<typename To, typename From> |
125 inline To safeCast(From value) | 125 inline To safeCast(From value) |
(...skipping 17 matching lines...) Expand all Loading... |
143 inline void* operator new(size_t, NotNullTag, void* location) | 143 inline void* operator new(size_t, NotNullTag, void* location) |
144 { | 144 { |
145 ASSERT(location); | 145 ASSERT(location); |
146 return location; | 146 return location; |
147 } | 147 } |
148 | 148 |
149 using WTF::bitwise_cast; | 149 using WTF::bitwise_cast; |
150 using WTF::safeCast; | 150 using WTF::safeCast; |
151 | 151 |
152 #endif // WTF_StdLibExtras_h | 152 #endif // WTF_StdLibExtras_h |
OLD | NEW |