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 
13 // ALL DISALLOW_xxx MACROS ARE DEPRECATED; DO NOT USE IN NEW CODE.
14 // Use explicit deletions instead.  See the section on copyability/movability in
15 // //styleguide/c++/c++-dos-and-donts.md for more information.
16 
17 // Put this in the declarations for a class to be uncopyable.
18 #define DISALLOW_COPY(TypeName) \
19   TypeName(const TypeName&) = delete
20 
21 // Put this in the declarations for a class to be unassignable.
22 #define DISALLOW_ASSIGN(TypeName) TypeName& operator=(const TypeName&) = delete
23 
24 // Put this in the declarations for a class to be uncopyable and unassignable.
25 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
26   DISALLOW_COPY(TypeName);                 \
27   DISALLOW_ASSIGN(TypeName)
28 
29 // A macro to disallow all the implicit constructors, namely the
30 // default constructor, copy constructor and operator= functions.
31 // This is especially useful for classes containing only static methods.
32 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
33   TypeName() = delete;                           \
34   DISALLOW_COPY_AND_ASSIGN(TypeName)
35 
36 // Used to explicitly mark the return value of a function as unused. If you are
37 // really sure you don't want to do anything with the return value of a function
38 // that has been marked WARN_UNUSED_RESULT, wrap it with this. Example:
39 //
40 //   std::unique_ptr<MyType> my_var = ...;
41 //   if (TakeOwnership(my_var.get()) == SUCCESS)
42 //     ignore_result(my_var.release());
43 //
44 template<typename T>
45 inline void ignore_result(const T&) {
46 }
47 
48 #endif  // BASE_MACROS_H_
49