Daily bump.
[official-gcc.git] / gcc / array-traits.h
blobd3b216e50fd3b578d675d19dcaaf749dfacf207c
1 /* Descriptions of array-like objects.
2 Copyright (C) 2019-2021 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_ARRAY_TRAITS_H
21 #define GCC_ARRAY_TRAITS_H
23 /* Implementation for single integers (and similar types). */
24 template<typename T, T zero = T (0)>
25 struct scalar_array_traits
27 typedef T element_type;
28 static const bool has_constant_size = true;
29 static const size_t constant_size = 1;
30 static const T *base (const T &x) { return &x; }
31 static size_t size (const T &) { return 1; }
34 template<typename T>
35 struct array_traits : scalar_array_traits<T> {};
37 /* Implementation for arrays with a static size. */
38 template<typename T, size_t N>
39 struct array_traits<T[N]>
41 typedef T element_type;
42 static const bool has_constant_size = true;
43 static const size_t constant_size = N;
44 static const T *base (const T (&x)[N]) { return x; }
45 static size_t size (const T (&)[N]) { return N; }
48 #endif