1/* Descriptions of array-like objects.
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_ARRAY_TRAITS_H
21#define GCC_ARRAY_TRAITS_H
22
23/* Implementation for single integers (and similar types). */
24template<typename T, T zero = T (0)>
25struct scalar_array_traits
26{
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; }
32};
33
34template<typename T>
35struct array_traits : scalar_array_traits<T> {};
36
37/* Implementation for arrays with a static size. */
38template<typename T, size_t N>
39struct array_traits<T[N]>
40{
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; }
46};
47
48#endif
49

source code of gcc/array-traits.h