xref: /aosp_15_r20/external/libchrome-gestures/include/macros.h (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1*aed3e508SAndroid Build Coastguard Worker // Copyright 2014 The ChromiumOS Authors
2*aed3e508SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*aed3e508SAndroid Build Coastguard Worker // found in the LICENSE file.
4*aed3e508SAndroid Build Coastguard Worker 
5*aed3e508SAndroid Build Coastguard Worker #ifndef GESTURES_MACROS_H_
6*aed3e508SAndroid Build Coastguard Worker #define GESTURES_MACROS_H_
7*aed3e508SAndroid Build Coastguard Worker 
8*aed3e508SAndroid Build Coastguard Worker #include <stddef.h>
9*aed3e508SAndroid Build Coastguard Worker 
10*aed3e508SAndroid Build Coastguard Worker // A macro to disallow the copy constructor and operator= functions
11*aed3e508SAndroid Build Coastguard Worker // This should be used in the private: declarations for a class
12*aed3e508SAndroid Build Coastguard Worker #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
13*aed3e508SAndroid Build Coastguard Worker   TypeName(const TypeName&);               \
14*aed3e508SAndroid Build Coastguard Worker   void operator=(const TypeName&)
15*aed3e508SAndroid Build Coastguard Worker 
16*aed3e508SAndroid Build Coastguard Worker // The arraysize(arr) macro returns the # of elements in an array arr.
17*aed3e508SAndroid Build Coastguard Worker // The expression is a compile-time constant, and therefore can be
18*aed3e508SAndroid Build Coastguard Worker // used in defining new arrays, for example.  If you use arraysize on
19*aed3e508SAndroid Build Coastguard Worker // a pointer by mistake, you will get a compile-time error.
20*aed3e508SAndroid Build Coastguard Worker //
21*aed3e508SAndroid Build Coastguard Worker // One caveat is that arraysize() doesn't accept any array of an
22*aed3e508SAndroid Build Coastguard Worker // anonymous type or a type defined inside a function.  In these rare
23*aed3e508SAndroid Build Coastguard Worker // cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below.  This is
24*aed3e508SAndroid Build Coastguard Worker // due to a limitation in C++'s template system.  The limitation might
25*aed3e508SAndroid Build Coastguard Worker // eventually be removed, but it hasn't happened yet.
26*aed3e508SAndroid Build Coastguard Worker 
27*aed3e508SAndroid Build Coastguard Worker // This template function declaration is used in defining arraysize.
28*aed3e508SAndroid Build Coastguard Worker // Note that the function doesn't need an implementation, as we only
29*aed3e508SAndroid Build Coastguard Worker // use its type.
30*aed3e508SAndroid Build Coastguard Worker template <typename T, size_t N>
31*aed3e508SAndroid Build Coastguard Worker char (&ArraySizeHelper(T (&array)[N]))[N];
32*aed3e508SAndroid Build Coastguard Worker 
33*aed3e508SAndroid Build Coastguard Worker // That gcc wants both of these prototypes seems mysterious. VC, for
34*aed3e508SAndroid Build Coastguard Worker // its part, can't decide which to use (another mystery). Matching of
35*aed3e508SAndroid Build Coastguard Worker // template overloads: the final frontier.
36*aed3e508SAndroid Build Coastguard Worker #ifndef _MSC_VER
37*aed3e508SAndroid Build Coastguard Worker template <typename T, size_t N>
38*aed3e508SAndroid Build Coastguard Worker char (&ArraySizeHelper(const T (&array)[N]))[N];
39*aed3e508SAndroid Build Coastguard Worker #endif
40*aed3e508SAndroid Build Coastguard Worker 
41*aed3e508SAndroid Build Coastguard Worker #define arraysize(array) (sizeof(ArraySizeHelper(array)))
42*aed3e508SAndroid Build Coastguard Worker 
43*aed3e508SAndroid Build Coastguard Worker #endif  // GESTURES_MACROS_H_
44