1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
base / types / cxx23_to_underlying.h [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_TYPES_CXX23_TO_UNDERLYING_H_
#define BASE_TYPES_CXX23_TO_UNDERLYING_H_
#include <type_traits>
namespace base {
// Implementation of C++23's std::to_underlying.
//
// Reference: https://en.cppreference.com/w/cpp/utility/to_underlying
template <typename EnumT>
requires(std::is_enum_v<EnumT>)
constexpr std::underlying_type_t<EnumT> to_underlying(EnumT e) noexcept {
return static_cast<std::underlying_type_t<EnumT>>(e);
}
} // namespace base
#endif // BASE_TYPES_CXX23_TO_UNDERLYING_H_