ALib C++ Library
Library Version: 2402 R1
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
11#if !defined(HPP_ALIB) && !defined(ALIB_DOX)
12# include "alib/alib.hpp"
13#endif
14
16
17#if !defined(HPP_ALIB_LANG_TMP) && !defined(ALIB_DOX)
18# include "alib/lang/tmp.hpp"
19#endif
20
21
22#define ALIB_ENUMS_UNDERLYING_TYPE(TEnum) typename std::underlying_type<TEnum>::type
23
24namespace alib {
25
26// For documentation, all operators and enum related template functions are faked into namespace
27// alib
28#if defined(ALIB_DOX)
29 namespace enums {
30#endif
31
32#if defined(ALIB_DOX)
33/**
34 * Simple alias to nested statment <c>static_cast</c> and type traits <c>std::underlying_type</c>,
35 * which
36 * - is selected by the compiler only if template parameter \p{TEnum} represents an enum type, and
37 * - is probably better readable.
38 *
39 * \note
40 * While documented in namespace <c>%alib::enums</c> in fact this function resides in
41 * namespace #alib.
42 *
43 * \see
44 * Class \alib{boxing;Enum} introduced with module \alib_boxing.
45 *
46 * @tparam TEnum Enumeration type. Deduced by the compiler.
47 * @param element The enumeration element.
48 * @return \c true if all bits of \p{testFor} are set in \p{tested}.
49 */
50template<typename TEnum>
51constexpr
52typename std::underlying_type<TEnum>::type UnderlyingIntegral(TEnum element) noexcept(true);
53#else
54template<typename TEnum>
55constexpr
56ATMP_T_IF(ALIB_ENUMS_UNDERLYING_TYPE(TEnum), std::is_enum<TEnum>::value)
57UnderlyingIntegral(TEnum element) noexcept(true)
58{
59 return static_cast<typename std::underlying_type<TEnum>::type>( element );
60}
61#endif
62
63// Reset documentation fake
64#if defined(ALIB_DOX)
65} // namespace alib[::enums]
66#endif
67
68} // namespace [alib]
69
70#endif // HPP_ALIB_ENUMS_UNDERLYING_INTEGRAL
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:190
#define ALIB_ENUMS_UNDERLYING_TYPE(TEnum)
#define ATMP_T_IF(T, Cond)
Definition tmp.hpp:53
constexpr std::underlying_type< TEnum >::type UnderlyingIntegral(TEnum element) noexcept(true)
Definition alib.cpp:57