|
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)
|
@@ -856,20 +876,21 @@ auto as( std::variant<Ts...> const& x ) {
|
856 | 876 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<17>(x)), T >) { if (x.index() == 17) return operator_as<7>(x); }
|
857 | 877 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<18>(x)), T >) { if (x.index() == 18) return operator_as<8>(x); }
|
858 | 878 | if constexpr (std::is_same_v< CPP2_TYPEOF(operator_as<19>(x)), T >) { if (x.index() == 19) return operator_as<9>(x); }
|
859 |
| - throw std::bad_variant_access(); |
| 879 | + CPP2_THROW("std::bad_variant_access", std::bad_variant_access()); |
860 | 880 | }
|
861 | 881 |
|
862 | 882 |
|
863 | 883 | //-------------------------------------------------------------------------------------------------------------
|
864 | 884 | // std::any is and as
|
865 | 885 | //
|
866 |
| - |
| 886 | +#ifdef CPP2_RTTI |
867 | 887 | // is Type
|
868 | 888 | //
|
869 | 889 | template<typename T, typename X>
|
870 | 890 | requires (std::is_same_v<X,std::any> && !std::is_same_v<T,std::any> && !std::is_same_v<T,empty>)
|
871 | 891 | constexpr auto is( X const& x ) -> bool
|
872 | 892 | { return x.type() == typeid(T); }
|
| 893 | +#endif |
873 | 894 |
|
874 | 895 | template<typename T, typename X>
|
875 | 896 | requires (std::is_same_v<X,std::any> && std::is_same_v<T,empty>)
|
@@ -1137,7 +1158,7 @@ inline auto fopen( const char* filename, const char* mode ) {
|
1137 | 1158 | #endif
|
1138 | 1159 |
|
1139 | 1160 | if (!x) {
|
1140 |
| - throw std::make_error_condition(std::errc::no_such_file_or_directory); |
| 1161 | + CPP2_THROW("std::errc::no_such_file_or_directory", std::make_error_condition(std::errc::no_such_file_or_directory)); |
1141 | 1162 | }
|
1142 | 1163 | return c_raii( x, &fclose );
|
1143 | 1164 | }
|
|
0 commit comments