OLD | NEW |
| (Empty) |
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 // Define a set of C++ specific macros. | |
6 // Mojo C++ API users can assume that mojo/public/cpp/system/macros.h | |
7 // includes mojo/public/c/include/mojo/macros.h. | |
8 | |
9 #ifndef MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_ | |
10 #define MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_ | |
11 | |
12 #include <mojo/macros.h> | |
13 | |
14 #include <utility> | |
15 | |
16 // A macro to disallow the copy constructor and operator= functions. This is | |
17 // typically used like: | |
18 // | |
19 // class MyUncopyableClass { | |
20 // public: | |
21 // ... | |
22 // private: | |
23 // ... | |
24 // MOJO_DISALLOW_COPY_AND_ASSIGN(MyUncopyableClass); | |
25 // }; | |
26 #define MOJO_DISALLOW_COPY_AND_ASSIGN(TypeName) \ | |
27 TypeName(const TypeName&) = delete; \ | |
28 void operator=(const TypeName&) = delete | |
29 | |
30 // Used to calculate the number of elements in an array. | |
31 // (See |arraysize()| in Chromium's base/macros.h for more details.) | |
32 namespace mojo { | |
33 namespace internal { | |
34 template <typename T, size_t N> | |
35 char(&ArraySizeHelper(T(&array)[N]))[N]; | |
36 #if !defined(_MSC_VER) | |
37 template <typename T, size_t N> | |
38 char(&ArraySizeHelper(const T(&array)[N]))[N]; | |
39 #endif | |
40 } // namespace internal | |
41 } // namespace mojo | |
42 #define MOJO_ARRAYSIZE(array) (sizeof(::mojo::internal::ArraySizeHelper(array))) | |
43 | |
44 // Used to make a type move-only. (The MoveOnlyTypeForCPP03 typedef is for | |
45 // Chromium's base/callback.h to tell that this type is move-only.) This is | |
46 // typically used like: | |
47 // | |
48 // class MyMoveOnlyClass { | |
49 // public: | |
50 // ... | |
51 // private: | |
52 // ... | |
53 // MOJO_MOVE_ONLY_TYPE(MyMoveOnlyClass); | |
54 // }; | |
55 // | |
56 // (Note: Class members following the use of this macro will have private access | |
57 // by default.) | |
58 #define MOJO_MOVE_ONLY_TYPE(type) \ | |
59 public: \ | |
60 type&& Pass() MOJO_WARN_UNUSED_RESULT { return std::move(*this); } \ | |
61 typedef void MoveOnlyTypeForCPP03; \ | |
62 \ | |
63 private: \ | |
64 type(const type&) = delete; \ | |
65 void operator=(const type&) = delete | |
66 | |
67 namespace mojo { | |
68 | |
69 // Used to explicitly mark the return value of a function as unused. (Use this | |
70 // if you are really sure you don't want to do anything with the return value of | |
71 // a function marked with |MOJO_WARN_UNUSED_RESULT|. | |
72 template <typename T> | |
73 inline void ignore_result(const T&) { | |
74 } | |
75 | |
76 } // namespace mojo | |
77 | |
78 #endif // MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_ | |
OLD | NEW |