Revert "Resolving memory leak issue in Reply function of AppControl"
[platform/framework/web/crosswalk-tizen.git] / common / arraysize.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef XWALK_COMMON_ARRAYSIZE_H_
18 #define XWALK_COMMON_ARRAYSIZE_H_
19
20 // The ARRAYSIZE(arr) macro returns the # of elements in an array arr.
21 // The expression is a compile-time constant, and therefore can be
22 // used in defining new arrays, for example.  If you use arraysize on
23 // a pointer by mistake, you will get a compile-time error.
24 //
25 // One caveat is that ARRAYSIZE() doesn't accept any array of an
26 // anonymous type or a type defined inside a function.  In these rare
27 // cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below.  This is
28 // due to a limitation in C++'s template system.  The limitation might
29 // eventually be removed, but it hasn't happened yet.
30
31 // This template function declaration is used in defining arraysize.
32 // Note that the function doesn't need an implementation, as we only
33 // use its type.
34 template <typename T, size_t N>
35 char (&ArraySizeHelper(T (&array)[N]))[N];
36
37 #define ARRAYSIZE(array) (sizeof(ArraySizeHelper(array)))
38
39 #endif  // XWALK_COMMON_ARRAYSIZE_H_
40