macros.h 1.9 KB

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