|
20 | 20 | #ifndef __CPP2_UTIL
|
21 | 21 | #define __CPP2_UTIL
|
22 | 22 |
|
| 23 | +#if __EXCEPTIONS |
| 24 | + #define CPP2_EXCEPTIONS |
| 25 | +#endif |
| 26 | + |
| 27 | +#ifdef __RTTI |
| 28 | + #define CPP2_RTTI |
| 29 | +#endif |
| 30 | + |
| 31 | +#if defined CPP2_EXCEPTIONS |
| 32 | + #if defined CPP2_THROW |
| 33 | + #error "Do not redefine CPP2_THROW when using cpp2 with exceptions enabled." |
| 34 | + #endif |
| 35 | + #define CPP2_THROW(DESC,EXCEPTION) throw EXCEPTION |
| 36 | +#else |
| 37 | + #if !defined CPP2_THROW |
| 38 | + // TODO: This should call a utility function that prints DESC and a backtrace. |
| 39 | + #define CPP2_THROW(DESC,EXCEPTION) std::terminate() |
| 40 | + #endif |
| 41 | +#endif |
| 42 | + |
23 | 43 | // If this implementation doesn't support source_location yet, disable it
|
24 | 44 | // TODO: technically this test should have <version> included first, but GEFN
|
25 | 45 | #if !defined(_MSC_VER) && !defined(__cpp_lib_source_location)
|
@@ -987,20 +1007,21 @@ auto as( std::variant<Ts...> const& x ) {
|
987 | 1007 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<17>(x)), T >) { if (x.index() == 17) return operator_as<7>(x); }
|
988 | 1008 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<18>(x)), T >) { if (x.index() == 18) return operator_as<8>(x); }
|
989 | 1009 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<19>(x)), T >) { if (x.index() == 19) return operator_as<9>(x); }
|
990 |
| - throw std::bad_variant_access(); |
| 1010 | + CPP2_THROW("std::bad_variant_access", std::bad_variant_access()); |
991 | 1011 | }
|
992 | 1012 |
|
993 | 1013 |
|
994 | 1014 | //-------------------------------------------------------------------------------------------------------------
|
995 | 1015 | // std::any is and as
|
996 | 1016 | //
|
997 |
| - |
| 1017 | +#ifdef CPP2_RTTI |
998 | 1018 | // is Type
|
999 | 1019 | //
|
1000 | 1020 | template<typename T, typename X>
|
1001 | 1021 | requires (std::is_same_v<X,std::any> && !std::is_same_v<T,std::any> && !std::is_same_v<T,empty>)
|
1002 | 1022 | constexpr auto is( X const& x ) -> bool
|
1003 | 1023 | { return x.type() == typeid(T); }
|
| 1024 | +#endif |
1004 | 1025 |
|
1005 | 1026 | template<typename T, typename X>
|
1006 | 1027 | requires (std::is_same_v<X,std::any> && std::is_same_v<T,empty>)
|
@@ -1273,7 +1294,7 @@ inline auto fopen( const char* filename, const char* mode ) {
|
1273 | 1294 | #endif
|
1274 | 1295 |
|
1275 | 1296 | if (!x) {
|
1276 |
| - throw std::make_error_condition(std::errc::no_such_file_or_directory); |
| 1297 | + CPP2_THROW("std::errc::no_such_file_or_directory", std::make_error_condition(std::errc::no_such_file_or_directory)); |
1277 | 1298 | }
|
1278 | 1299 | return c_raii( x, &fclose );
|
1279 | 1300 | }
|
|
0 commit comments