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_ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // This template function declaration is used in defining arraysize. | 45 // This template function declaration is used in defining arraysize. |
46 // Note that the function doesn't need an implementation, as we only | 46 // Note that the function doesn't need an implementation, as we only |
47 // use its type. | 47 // use its type. |
48 template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N]; | 48 template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N]; |
49 #define arraysize(array) (sizeof(ArraySizeHelper(array))) | 49 #define arraysize(array) (sizeof(ArraySizeHelper(array))) |
50 | 50 |
51 // Used to explicitly mark the return value of a function as unused. If you are | 51 // Used to explicitly mark the return value of a function as unused. If you are |
52 // really sure you don't want to do anything with the return value of a function | 52 // really sure you don't want to do anything with the return value of a function |
53 // that has been marked WARN_UNUSED_RESULT, wrap it with this. Example: | 53 // that has been marked WARN_UNUSED_RESULT, wrap it with this. Example: |
54 // | 54 // |
55 // scoped_ptr<MyType> my_var = ...; | 55 // std::unique_ptr<MyType> my_var = ...; |
56 // if (TakeOwnership(my_var.get()) == SUCCESS) | 56 // if (TakeOwnership(my_var.get()) == SUCCESS) |
57 // ignore_result(my_var.release()); | 57 // ignore_result(my_var.release()); |
58 // | 58 // |
59 template<typename T> | 59 template<typename T> |
60 inline void ignore_result(const T&) { | 60 inline void ignore_result(const T&) { |
61 } | 61 } |
62 | 62 |
63 // The following enum should be used only as a constructor argument to indicate | 63 // The following enum should be used only as a constructor argument to indicate |
64 // that the variable has static storage class, and that the constructor should | 64 // that the variable has static storage class, and that the constructor should |
65 // do nothing to its state. It indicates to the reader that it is legal to | 65 // do nothing to its state. It indicates to the reader that it is legal to |
(...skipping 12 matching lines...) Expand all 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 |