1e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org/*
2e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org *
4e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org *  Use of this source code is governed by a BSD-style license
5e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org *  that can be found in the LICENSE file in the root of the source
6e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org *  tree. An additional intellectual property rights grant can be found
7e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org *  in the file PATENTS.  All contributing project authors may
8e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org *  be found in the AUTHORS file in the root of the source tree.
9e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org */
10e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org
11e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org#ifndef WEBRTC_BASE_ARRAYSIZE_H_
12e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org#define WEBRTC_BASE_ARRAYSIZE_H_
13e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org
14d7472b52d6c1c9fa2adca9974467349cb24ff894kwiberg@webrtc.org#include <stddef.h>
15d7472b52d6c1c9fa2adca9974467349cb24ff894kwiberg@webrtc.org
16e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org// This file defines the arraysize() macro and is derived from Chromium's
17e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org// base/macros.h.
18e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org
19e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org// The arraysize(arr) macro returns the # of elements in an array arr.
20e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org// The expression is a compile-time constant, and therefore can be
21e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org// used in defining new arrays, for example.  If you use arraysize on
22e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org// a pointer by mistake, you will get a compile-time error.
23e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org
24e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org// This template function declaration is used in defining arraysize.
25e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org// Note that the function doesn't need an implementation, as we only
26e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org// use its type.
273dfe5d3d41d7b2f7de594b383d23a328303f3436henrikgtemplate <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N];
28e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org
29e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org#define arraysize(array) (sizeof(ArraySizeHelper(array)))
30e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org
31e7a4a12f83b342f1c2c455366ce465f07a9330b1pkasting@chromium.org#endif  // WEBRTC_BASE_ARRAYSIZE_H_
32