mimic++ v9.2.1
Loading...
Searching...
No Matches
C++23Backports.hpp
Go to the documentation of this file.
1// Copyright Dominic (DNKpp) Koepke 2024 - 2025.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef MIMICPP_UTILITIES_CXX23_BACKPORTS_HPP
7#define MIMICPP_UTILITIES_CXX23_BACKPORTS_HPP
8
9#pragma once
10
12
13#ifndef MIMICPP_DETAIL_IS_MODULE
14 #include <type_traits>
15 #include <version>
16#endif
17
18// GCOVR_EXCL_START
19#ifdef __cpp_lib_unreachable
20
21 #ifndef MIMICPP_DETAIL_IS_MODULE
22 #include <utility>
23 #endif
24
26{
27 using std::unreachable;
28}
29
30#else
31
33{
39 [[noreturn]]
40 inline void unreachable()
41 {
42 MIMICPP_ASSERT(false, "Reached the unreachable.");
43
44 // Uses compiler specific extensions if possible.
45 // Even if no extension is used, undefined behavior is still raised by
46 // an empty function body and the noreturn attribute.
47 #if MIMICPP_DETAIL_IS_MSVC // MSVC
48 __assume(false);
49 #else // GCC, Clang
50 __builtin_unreachable();
51 #endif
52 }
53}
54#endif
55// GCOVR_EXCL_STOP
56
58{
59 template <typename T>
60 requires std::is_enum_v<T>
61 [[nodiscard]]
62 constexpr std::underlying_type_t<T> to_underlying(T const value) noexcept
63 {
64 return static_cast<std::underlying_type_t<T>>(value);
65 }
66}
67
68#endif
#define MIMICPP_ASSERT(condition, msg)
Definition Config.hpp:51
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition Config.hpp:19
Definition Fwd.hpp:445
constexpr std::underlying_type_t< T > to_underlying(T const value) noexcept
Definition C++23Backports.hpp:62
void unreachable()
Invokes undefined behavior.
Definition C++23Backports.hpp:40