xref: /netbsd-src/external/gpl3/gdb/dist/gdbsupport/underlying.h (revision 5ba1f45f2a09259cc846f20c7c5501604d633c90)
1*5ba1f45fSchristos /* Copyright (C) 2017-2024 Free Software Foundation, Inc.
28dffb485Schristos 
38dffb485Schristos    This file is part of GDB.
48dffb485Schristos 
58dffb485Schristos    This program is free software; you can redistribute it and/or modify
68dffb485Schristos    it under the terms of the GNU General Public License as published by
78dffb485Schristos    the Free Software Foundation; either version 3 of the License, or
88dffb485Schristos    (at your option) any later version.
98dffb485Schristos 
108dffb485Schristos    This program is distributed in the hope that it will be useful,
118dffb485Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
128dffb485Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
138dffb485Schristos    GNU General Public License for more details.
148dffb485Schristos 
158dffb485Schristos    You should have received a copy of the GNU General Public License
168dffb485Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
178dffb485Schristos 
188dffb485Schristos #ifndef COMMON_UNDERLYING_H
198dffb485Schristos #define COMMON_UNDERLYING_H
208dffb485Schristos 
218dffb485Schristos #include <type_traits>
228dffb485Schristos 
238dffb485Schristos /* Convert an enum to its underlying value.  */
248dffb485Schristos 
258dffb485Schristos template<typename E>
268dffb485Schristos constexpr typename std::underlying_type<E>::type
278dffb485Schristos to_underlying (E val) noexcept
288dffb485Schristos {
298dffb485Schristos   return static_cast<typename std::underlying_type<E>::type> (val);
308dffb485Schristos }
318dffb485Schristos 
328dffb485Schristos #endif
33