[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
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 | ||||
7 | // that are closely related to things that are commonly used that belong in this | ||||
8 | // file.) | ||||
9 | |||||
10 | #ifndef BASE_MACROS_H_ | ||||
11 | #define BASE_MACROS_H_ | ||||
12 | |||||
mlamouri | a99741d5 | 2015-05-21 22:54:05 | [diff] [blame] | 13 | // Put this in the declarations for a class to be uncopyable. |
[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 14 | #define DISALLOW_COPY(TypeName) \ |
mlamouri | a99741d5 | 2015-05-21 22:54:05 | [diff] [blame] | 15 | TypeName(const TypeName&) = delete |
[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 16 | |
mlamouri | a99741d5 | 2015-05-21 22:54:05 | [diff] [blame] | 17 | // Put this in the declarations for a class to be unassignable. |
Clemens Hammacher | cec5fde | 2017-07-20 08:53:16 | [diff] [blame] | 18 | #define DISALLOW_ASSIGN(TypeName) TypeName& operator=(const TypeName&) = delete |
[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 19 | |
Clemens Hammacher | cec5fde | 2017-07-20 08:53:16 | [diff] [blame] | 20 | // Put this in the declarations for a class to be uncopyable and unassignable. |
pkasting | 999f15f | 2016-05-26 22:03:34 | [diff] [blame] | 21 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
Clemens Hammacher | cec5fde | 2017-07-20 08:53:16 | [diff] [blame] | 22 | DISALLOW_COPY(TypeName); \ |
23 | DISALLOW_ASSIGN(TypeName) | ||||
[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 24 | |
[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 25 | // A macro to disallow all the implicit constructors, namely the |
26 | // default constructor, copy constructor and operator= functions. | ||||
Clemens Hammacher | cec5fde | 2017-07-20 08:53:16 | [diff] [blame] | 27 | // This is especially useful for classes containing only static methods. |
[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 28 | #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
mlamouri | 8cd0029 | 2015-07-03 10:27:50 | [diff] [blame] | 29 | TypeName() = delete; \ |
[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 30 | DISALLOW_COPY_AND_ASSIGN(TypeName) |
31 | |||||
[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 32 | // Used to explicitly mark the return value of a function as unused. If you are |
33 | // really sure you don't want to do anything with the return value of a function | ||||
34 | // that has been marked WARN_UNUSED_RESULT, wrap it with this. Example: | ||||
35 | // | ||||
dcheng | 093de9b | 2016-04-04 21:25:51 | [diff] [blame] | 36 | // std::unique_ptr<MyType> my_var = ...; |
[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 37 | // if (TakeOwnership(my_var.get()) == SUCCESS) |
38 | // ignore_result(my_var.release()); | ||||
39 | // | ||||
40 | template<typename T> | ||||
41 | inline void ignore_result(const T&) { | ||||
42 | } | ||||
43 | |||||
[email protected] | a1683a1 | 2014-01-08 21:38:30 | [diff] [blame] | 44 | #endif // BASE_MACROS_H_ |