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