ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
underlyingintegral.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header file is part of module \alib_enums of the \aliblong.
4///
5/// \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8#ifndef HPP_ALIB_ENUMS_UNDERLYING_INTEGRAL
9#define HPP_ALIB_ENUMS_UNDERLYING_INTEGRAL 1
10#pragma once
11#if !defined(DOXYGEN)
12# include "alib/alib.hpp"
13#endif
14
16
17#include "alib/lang/tmp.hpp"
18
19#define ALIB_ENUMS_UNDERLYING_TYPE(TEnum) typename std::underlying_type<TEnum>::type
20
21namespace alib {
22
23// For documentation, all operators and enum related template functions are faked into namespace
24// alib
25#if DOXYGEN
26 namespace enums {
27#endif
28
29#if DOXYGEN
30/// Simple alias to nested statment <c>static_cast</c> and type traits <c>std::underlying_type</c>,
31/// which
32/// - is selected by the compiler only if template parameter \p{TEnum} represents an enum type, and
33/// - is probably better readable.
34///
35/// \note
36/// While documented in namespace <c>%alib::enums</c> in fact this function resides in
37/// namespace #alib.
38///
39/// \see
40/// Class \alib{boxing;Enum} introduced with module \alib_boxing.
41///
42/// @tparam TEnum Enumeration type. Deduced by the compiler.
43/// @param element The enumeration element.
44/// @return \c true if all bits of \p{testFor} are set in \p{tested}.
45template<typename TEnum>
46constexpr
47typename std::underlying_type<TEnum>::type UnderlyingIntegral(TEnum element) noexcept;
48#else
49template<typename TEnum>
50constexpr
51ATMP_T_IF(ALIB_ENUMS_UNDERLYING_TYPE(TEnum), std::is_enum<TEnum>::value)
52UnderlyingIntegral(TEnum element) noexcept
53{
54 return static_cast<typename std::underlying_type<TEnum>::type>( element );
55}
56#endif
57
58// Reset documentation fake
59#if DOXYGEN
60} // namespace alib[::enums]
61#endif
62
63} // namespace [alib]
64
65#endif // HPP_ALIB_ENUMS_UNDERLYING_INTEGRAL
66
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:223
#define ALIB_ENUMS_UNDERLYING_TYPE(TEnum)
#define ATMP_T_IF(T, Cond)
Definition tmp.hpp:49
constexpr std::underlying_type< TEnum >::type UnderlyingIntegral(TEnum element) noexcept
Definition alib.cpp:69