OLD | NEW |
---|---|
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_ |
11 #define BASE_MACROS_H_ | 11 #define BASE_MACROS_H_ |
12 | 12 |
13 #include <stddef.h> // For size_t. | 13 #include <stddef.h> // For size_t. |
14 | 14 |
15 // Put this in the declarations for a class to be uncopyable. | 15 // Put this in the declarations for a class to be uncopyable. |
16 #define DISALLOW_COPY(TypeName) \ | 16 #define DISALLOW_COPY(TypeName) \ |
17 TypeName(const TypeName&) = delete | 17 TypeName(const TypeName&) = delete |
18 | 18 |
19 // Put this in the declarations for a class to be unassignable. | 19 // Put this in the declarations for a class to be unassignable. |
20 #define DISALLOW_ASSIGN(TypeName) \ | 20 #define DISALLOW_ASSIGN(TypeName) \ |
21 void operator=(const TypeName&) = delete | 21 void operator=(const TypeName&) = delete |
22 | 22 |
23 // A macro to disallow the copy constructor and operator= functions | 23 // A macro to disallow the copy constructor and operator= functions |
24 // This should be used in the private: declarations for a class | 24 // This should be used in the private: declarations for a class |
Ryan Hamilton
2016/05/25 14:10:06
Presumably, this advice about private: is no longe
Peter Kasting
2016/05/25 18:55:17
No, this advice is still correct. We have not mad
| |
25 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | 25 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
26 TypeName(const TypeName&); \ | 26 TypeName(const TypeName&) = delete; \ |
27 void operator=(const TypeName&) | 27 void operator=(const TypeName&) = delete |
28 | 28 |
29 // A macro to disallow all the implicit constructors, namely the | 29 // A macro to disallow all the implicit constructors, namely the |
30 // default constructor, copy constructor and operator= functions. | 30 // default constructor, copy constructor and operator= functions. |
31 // | 31 // |
32 // This should be used in the private: declarations for a class | 32 // This should be used in the private: declarations for a class |
Ryan Hamilton
2016/05/25 14:10:06
ditto
| |
33 // that wants to prevent anyone from instantiating it. This is | 33 // that wants to prevent anyone from instantiating it. This is |
34 // especially useful for classes containing only static methods. | 34 // especially useful for classes containing only static methods. |
35 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | 35 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
36 TypeName() = delete; \ | 36 TypeName() = delete; \ |
37 DISALLOW_COPY_AND_ASSIGN(TypeName) | 37 DISALLOW_COPY_AND_ASSIGN(TypeName) |
38 | 38 |
39 // The arraysize(arr) macro returns the # of elements in an array arr. The | 39 // The arraysize(arr) macro returns the # of elements in an array arr. The |
40 // expression is a compile-time constant, and therefore can be used in defining | 40 // expression is a compile-time constant, and therefore can be used in defining |
41 // new arrays, for example. If you use arraysize on a pointer by mistake, you | 41 // new arrays, for example. If you use arraysize on a pointer by mistake, you |
42 // will get a compile-time error. For the technical details, refer to | 42 // will get a compile-time error. For the technical details, refer to |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 | 78 |
79 // Use these to declare and define a static local variable (static T;) so that | 79 // Use these to declare and define a static local variable (static T;) so that |
80 // it is leaked so that its destructors are not called at exit. If you need | 80 // it is leaked so that its destructors are not called at exit. If you need |
81 // thread-safe initialization, use base/lazy_instance.h instead. | 81 // thread-safe initialization, use base/lazy_instance.h instead. |
82 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ | 82 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ |
83 static type& name = *new type arguments | 83 static type& name = *new type arguments |
84 | 84 |
85 } // base | 85 } // base |
86 | 86 |
87 #endif // BASE_MACROS_H_ | 87 #endif // BASE_MACROS_H_ |
OLD | NEW |