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

Side by Side Diff: base/macros.h

Issue 1467003002: Switch to static_assert in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: / Created 5 years 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 | « base/mac/foundation_util_unittest.mm ('k') | base/memory/scoped_ptr.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 Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This file contains macros and macro-like constructs (e.g., templates) that 5 // This file contains macros and macro-like constructs (e.g., templates) that
6 // are commonly used throughout Chromium source. (It may also contain things 6 // are commonly used throughout Chromium source. (It may also contain things
7 // that are closely related to things that are commonly used that belong in this 7 // that are closely related to things that are commonly used that belong in this
8 // file.) 8 // file.)
9 9
10 #ifndef BASE_MACROS_H_ 10 #ifndef BASE_MACROS_H_
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // memcpy(d,s,4) compiles to one load and one store, and memcpy(d,s,8) 122 // memcpy(d,s,4) compiles to one load and one store, and memcpy(d,s,8)
123 // compiles to two loads and two stores. 123 // compiles to two loads and two stores.
124 // 124 //
125 // I tested this code with gcc 2.95.3, gcc 4.0.1, icc 8.1, and msvc 7.1. 125 // I tested this code with gcc 2.95.3, gcc 4.0.1, icc 8.1, and msvc 7.1.
126 // 126 //
127 // WARNING: if Dest or Source is a non-POD type, the result of the memcpy 127 // WARNING: if Dest or Source is a non-POD type, the result of the memcpy
128 // is likely to surprise you. 128 // is likely to surprise you.
129 129
130 template <class Dest, class Source> 130 template <class Dest, class Source>
131 inline Dest bit_cast(const Source& source) { 131 inline Dest bit_cast(const Source& source) {
132 COMPILE_ASSERT(sizeof(Dest) == sizeof(Source), VerifySizesAreEqual); 132 static_assert(sizeof(Dest) == sizeof(Source),
133 "bit_cast requires source and destination to be the same size");
133 134
134 Dest dest; 135 Dest dest;
135 memcpy(&dest, &source, sizeof(dest)); 136 memcpy(&dest, &source, sizeof(dest));
136 return dest; 137 return dest;
137 } 138 }
138 139
139 // Used to explicitly mark the return value of a function as unused. If you are 140 // Used to explicitly mark the return value of a function as unused. If you are
140 // really sure you don't want to do anything with the return value of a function 141 // really sure you don't want to do anything with the return value of a function
141 // that has been marked WARN_UNUSED_RESULT, wrap it with this. Example: 142 // that has been marked WARN_UNUSED_RESULT, wrap it with this. Example:
142 // 143 //
(...skipping 23 matching lines...) Expand all
166 167
167 // Use these to declare and define a static local variable (static T;) so that 168 // Use these to declare and define a static local variable (static T;) so that
168 // it is leaked so that its destructors are not called at exit. If you need 169 // it is leaked so that its destructors are not called at exit. If you need
169 // thread-safe initialization, use base/lazy_instance.h instead. 170 // thread-safe initialization, use base/lazy_instance.h instead.
170 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ 171 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \
171 static type& name = *new type arguments 172 static type& name = *new type arguments
172 173
173 } // base 174 } // base
174 175
175 #endif // BASE_MACROS_H_ 176 #endif // BASE_MACROS_H_
OLDNEW
« no previous file with comments | « base/mac/foundation_util_unittest.mm ('k') | base/memory/scoped_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698