1af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// Use of this source code is governed by a BSD-style license that can be
3af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// found in the LICENSE file.
4af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
5af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#ifndef I18N_PHONENUMBERS_BASE_BASICTYPES_H_
6af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#define I18N_PHONENUMBERS_BASE_BASICTYPES_H_
7af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
8af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#include <limits.h>         // So we can set the bounds of our types
9af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#include <stddef.h>         // For size_t
10af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#include <string.h>         // for memcpy
11af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
12c636308f0ab6fb1af7589eaf0917103dc22fa61ephilip.liard@gmail.com#if !defined(_WIN32)
13af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// stdint.h is part of C99 but MSVC doesn't have it.
14af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#include <stdint.h>         // For intptr_t.
15af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#endif
16af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
17fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.comnamespace i18n {
18fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.comnamespace phonenumbers {
19fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com
20af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#ifdef INT64_MAX
21af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
22af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// INT64_MAX is defined if C99 stdint.h is included; use the
23af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// native types if available.
24af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef int8_t int8;
25af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef int16_t int16;
26af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef int32_t int32;
27af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef int64_t int64;
28af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef uint8_t uint8;
29af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef uint16_t uint16;
30af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef uint32_t uint32;
31af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef uint64_t uint64;
32af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
33af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst uint8  kuint8max  = UINT8_MAX;
34af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst uint16 kuint16max = UINT16_MAX;
35af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst uint32 kuint32max = UINT32_MAX;
36af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst uint64 kuint64max = UINT64_MAX;
37af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst  int8  kint8min   = INT8_MIN;
38af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst  int8  kint8max   = INT8_MAX;
39af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst  int16 kint16min  = INT16_MIN;
40af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst  int16 kint16max  = INT16_MAX;
41af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst  int32 kint32min  = INT32_MIN;
42af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst  int32 kint32max  = INT32_MAX;
43af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst  int64 kint64min  = INT64_MIN;
44af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comconst  int64 kint64max  = INT64_MAX;
45af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
46af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#else // !INT64_MAX
47af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
48af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef signed char         int8;
49af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef short               int16;
50af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// TODO: Remove these type guards.  These are to avoid conflicts with
51af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// obsolete/protypes.h in the Gecko SDK.
52af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#ifndef _INT32
53af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#define _INT32
54af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef int                 int32;
55af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#endif
56af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
57af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// The NSPR system headers define 64-bit as |long| when possible.  In order to
58af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// not have typedef mismatches, we do the same on LP64.
59af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#if __LP64__
60af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef long                int64;
61af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#else
62af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef long long           int64;
63af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#endif
64af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
65af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// NOTE: unsigned types are DANGEROUS in loops and other arithmetical
66af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// places.  Use the signed types unless your variable represents a bit
67af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// pattern (eg a hash value) or you really need the extra bit.  Do NOT
68af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// use 'unsigned' to express "this value should always be positive";
69af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// use assertions for this.
70af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
71af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef unsigned char      uint8;
72af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef unsigned short     uint16;
73af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// TODO: Remove these type guards.  These are to avoid conflicts with
74af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// obsolete/protypes.h in the Gecko SDK.
75af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#ifndef _UINT32
76af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#define _UINT32
77af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef unsigned int       uint32;
78af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#endif
79af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
80af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// See the comment above about NSPR and 64-bit.
81af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#if __LP64__
82af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef unsigned long uint64;
83af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#else
84af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef unsigned long long uint64;
85af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#endif
86af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
87af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#endif // !INT64_MAX
88af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
89af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef signed char         schar;
90af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
91af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// A type to represent a Unicode code-point value. As of Unicode 4.0,
92af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// such values require up to 21 bits.
93af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// (For type-checking on pointers, make this explicitly signed,
94af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// and it should always be the signed version of whatever int32 is.)
95af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtypedef signed int         char32;
96af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
97af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// A macro to disallow the copy constructor and operator= functions
98af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// This should be used in the private: declarations for a class
99fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com#if !defined(DISALLOW_COPY_AND_ASSIGN)
100af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
101af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com  TypeName(const TypeName&);               \
102af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com  void operator=(const TypeName&)
103fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com#endif
104af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
105af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// The arraysize(arr) macro returns the # of elements in an array arr.
106af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// The expression is a compile-time constant, and therefore can be
107af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// used in defining new arrays, for example.  If you use arraysize on
108af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// a pointer by mistake, you will get a compile-time error.
109af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
110af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// One caveat is that arraysize() doesn't accept any array of an
111af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// anonymous type or a type defined inside a function.  In these rare
112af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below.  This is
113af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// due to a limitation in C++'s template system.  The limitation might
114af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// eventually be removed, but it hasn't happened yet.
115af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
116af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// This template function declaration is used in defining arraysize.
117af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// Note that the function doesn't need an implementation, as we only
118af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// use its type.
119af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtemplate <typename T, size_t N>
120af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comchar (&ArraySizeHelper(T (&array)[N]))[N];
121af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
122af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// That gcc wants both of these prototypes seems mysterious. VC, for
123af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// its part, can't decide which to use (another mystery). Matching of
124af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// template overloads: the final frontier.
125af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#ifndef _MSC_VER
126af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtemplate <typename T, size_t N>
127af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comchar (&ArraySizeHelper(const T (&array)[N]))[N];
128af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#endif
129af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
130fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com#if !defined(arraysize)
131af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#define arraysize(array) (sizeof(ArraySizeHelper(array)))
132fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com#endif
133af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
134af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize,
135af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// but can be used on anonymous types or types defined inside
136af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// functions.  It's less safe than arraysize as it accepts some
137af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// (although not all) pointers.  Therefore, you should use arraysize
138af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// whenever possible.
139af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
140af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// The expression ARRAYSIZE_UNSAFE(a) is a compile-time constant of type
141af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// size_t.
142af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
143af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// ARRAYSIZE_UNSAFE catches a few type errors.  If you see a compiler error
144af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
145af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//   "warning: division by zero in ..."
146af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
147af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// when using ARRAYSIZE_UNSAFE, you are (wrongfully) giving it a pointer.
148af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// You should only use ARRAYSIZE_UNSAFE on statically allocated arrays.
149af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
150af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// The following comments are on the implementation details, and can
151af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// be ignored by the users.
152af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
153af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// ARRAYSIZE_UNSAFE(arr) works by inspecting sizeof(arr) (the # of bytes in
154af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// the array) and sizeof(*(arr)) (the # of bytes in one array
155af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// element).  If the former is divisible by the latter, perhaps arr is
156af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// indeed an array, in which case the division result is the # of
157af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// elements in the array.  Otherwise, arr cannot possibly be an array,
158af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// and we generate a compiler error to prevent the code from
159af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// compiling.
160af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
161af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// Since the size of bool is implementation-defined, we need to cast
162af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final
163af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// result has type size_t.
164af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
165af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// This macro is not perfect as it wrongfully accepts certain
166af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// pointers, namely where the pointer size is divisible by the pointee
167af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// size.  Since all our code has to go through a 32-bit compiler,
168af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// where a pointer is 4 bytes, this means all pointers to a type whose
169af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// size is 3 or greater than 4 will be (righteously) rejected.
170af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
171fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com#if !defined(ARRAYSIZE_UNSAFE)
172af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#define ARRAYSIZE_UNSAFE(a) \
173af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com  ((sizeof(a) / sizeof(*(a))) / \
174af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com   static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
175fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com#endif
176af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
177af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// The COMPILE_ASSERT macro can be used to verify that a compile time
178af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// expression is true. For example, you could use it to verify the
179af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// size of a static array:
180af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
181af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//   COMPILE_ASSERT(ARRAYSIZE_UNSAFE(content_type_names) == CONTENT_NUM_TYPES,
182af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//                  content_type_names_incorrect_size);
183af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
184af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// or to make sure a struct is smaller than a certain size:
185af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
186af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//   COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large);
187af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com//
188af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// The second argument to the macro is the name of the variable. If
189af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// the expression is false, most compilers will issue a warning/error
190af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com// containing the name of the variable.
191af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
192af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comtemplate <bool>
193af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.comstruct CompileAssert {
194af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com};
195af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
196fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com#if !defined(COMPILE_ASSERT)
197af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#define COMPILE_ASSERT(expr, msg) \
198af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com  typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
199fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com#endif
200af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
201fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com}  // namespace phonenumbers
202fa6ddeed736e42c266027a0d7b696909083d066bphilip.liard@gmail.com}  // namespace i18n
203af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com
204af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#endif  // I18N_PHONENUMBERS_BASE_BASICTYPES_H_
205