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