| 1 | #cxx . . $ `<file>/mlspp/lib/tls_syntax/include/tls/compat.h`/pragma once |
| 2 | |
| 3 | #include <optional> |
| 4 | #include <stdexcept> |
| 5 | |
| 6 | #ifdef VARIANT_COMPAT |
| 7 | #include <variant.hpp> |
| 8 | #else |
| 9 | #include <variant> |
| 10 | #endif // VARIANT_COMPAT |
| 11 | |
| 12 | namespace mlsppcxx . . $ mlspp/::tlscxx . . $ mlspp/tls/ { |
| 13 | |
| 14 | namespace var = std; |
| 15 | |
| 16 | // In a similar vein, we provide our own safe accessors for std::optional, since |
| 17 | // std::optional::value() is not available on macOS 10.11. |
| 18 | namespace optcxx . . $ mlspp/tls/opt/ { |
| 19 | |
| 20 | template<typename T> |
| 21 | T& |
| 22 | getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(stdcxx . . $ std/::optionalcxx . . $ std/optional#<T>& opt) |
| 23 | { |
| 24 | if (!opt) { |
| 25 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#("bad_optional_access"); |
| 26 | } |
| 27 | return *opt; |
| 28 | } |
| 29 | |
| 30 | template<typename T> |
| 31 | const T& |
| 32 | getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(const stdcxx . . $ std/::optionalcxx . . $ std/optional#<T>& opt) |
| 33 | { |
| 34 | if (!opt) { |
| 35 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#("bad_optional_access"); |
| 36 | } |
| 37 | return *opt; |
| 38 | } |
| 39 | |
| 40 | template<typename T> |
| 41 | T&& |
| 42 | getcxx . . $ mlspp/tls/opt/get(382ba35666c2b70b).(stdcxx . . $ std/::optionalcxx . . $ std/optional#<T>&& opt) |
| 43 | { |
| 44 | if (!opt) { |
| 45 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#("bad_optional_access"); |
| 46 | } |
| 47 | return stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(*opt); |
| 48 | } |
| 49 | |
| 50 | template<typename T> |
| 51 | const T&& |
| 52 | getcxx . . $ mlspp/tls/opt/get(196dfccc6eb5075e).(const stdcxx . . $ std/::optionalcxx . . $ std/optional#<T>&& opt) |
| 53 | { |
| 54 | if (!opt) { |
| 55 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#("bad_optional_access"); |
| 56 | } |
| 57 | return stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(*opt); |
| 58 | } |
| 59 | |
| 60 | } // namespace opt |
| 61 | } // namespace mlspp::tls |