Debian Codegraph @

src/mpt/base/constexpr_throw.hpp

raw
1 /* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
2
3 #ifndef MPT_BASE_CONSTEXPR_THROW_HPP
4 #define MPT_BASE_CONSTEXPR_THROW_HPP
5
6
7
8 #include "mpt/base/detect.hpp"
9 #include "mpt/base/namespace.hpp"
10
11 #include <utility>
12
13
14
15 namespace mpt {
16 inline namespace MPT_INLINE_NS {
17
18
19 // Work-around for the requirement of at least 1 non-throwing function argument combination in C++ (17,2a).
20
21 template <typename Exception>
22 constexpr bool constexpr_throw_helper(Exception && e, bool really = true) {
23 //return !really ? really : throw std::forward<Exception>(e);
24 if (really) {
25 throw std::forward<Exception>(e);
26 }
27 // cppcheck-suppress identicalConditionAfterEarlyExit
28 return really;
29 }
30
31 template <typename Exception>
32 constexpr bool constexpr_throw(Exception && e) {
33 return mpt::constexpr_throw_helper(std::forward<Exception>(e));
34 }
35
36 template <typename T, typename Exception>
37 constexpr T constexpr_throw_helper(Exception && e, bool really = true) {
38 //return !really ? really : throw std::forward<Exception>(e);
39 if (really) {
40 throw std::forward<Exception>(e);
41 }
42 return T{};
43 }
44
45 template <typename T, typename Exception>
46 constexpr T constexpr_throw(Exception && e) {
47 return mpt::constexpr_throw_helper<T>(std::forward<Exception>(e));
48 }
49
50
51 } // namespace MPT_INLINE_NS
52 } // namespace mpt
53
54
55
56 #endif // MPT_BASE_CONSTEXPR_THROW_HPP