ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
underlyingintegral.inl
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of the module \alib_enumops of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8
9ALIB_EXPORT namespace alib {
10
11// For documentation, all operators and enum related template functions are faked into namespace
12// alib::enumops
13#if DOXYGEN
14 namespace enumops{
15#endif
16
17/// Simple alias to the nested statement <c>static_cast</c> and type trait
18/// <c>std::underlying_type</c>, which
19/// - is selected by the compiler only if template parameter \p{TEnum} represents an enum type, and
20/// - is probably better readable.
21///
22/// \alib uses this function only in templated code, where the destination type is not determined.
23/// In other cases, \alib chooses to convert enum values directly using function-style casts.
24///
25/// \note
26/// While documented in namespace <c>%alib::enumops</c> in fact this function resides in
27/// namespace #alib.
28///
29/// \see
30/// Class \alib{boxing;Enum} introduced with module \alib_boxing.
31///
32/// @tparam TEnum Enumeration type. Deduced by the compiler.
33/// @param element The enumeration element.
34/// @return \c true if all bits of \p{testFor} are set in \p{tested}.
35template<typename TEnum>
36requires std::is_enum_v<TEnum>
37std::underlying_type_t<TEnum> constexpr UnderlyingIntegral(TEnum element) noexcept
38{ return static_cast<typename std::underlying_type<TEnum>::type>( element ); }
39
40// Reset documentation fake
41#if DOXYGEN
42} // namespace alib[::enumops::]
43#endif
44
45} // namespace [alib]
46
#define ALIB_EXPORT
Definition alib.inl:488
std::underlying_type_t< TEnum > constexpr UnderlyingIntegral(TEnum element) noexcept