Debian Codegraph @

mlspp/lib/bytes/include/tls/compat.h

raw symbols SCIP
1 #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 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 opt {
19
20 template<typename T>
21 T&
22 get(std::optional<T>& opt)
23 {
24 if (!opt) {
25 throw std::runtime_error("bad_optional_access");
26 }
27 return *opt;
28 }
29
30 template<typename T>
31 const T&
32 get(const std::optional<T>& opt)
33 {
34 if (!opt) {
35 throw std::runtime_error("bad_optional_access");
36 }
37 return *opt;
38 }
39
40 template<typename T>
41 T&&
42 get(std::optional<T>&& opt)
43 {
44 if (!opt) {
45 throw std::runtime_error("bad_optional_access");
46 }
47 return std::move(*opt);
48 }
49
50 template<typename T>
51 const T&&
52 get(const std::optional<T>&& opt)
53 {
54 if (!opt) {
55 throw std::runtime_error("bad_optional_access");
56 }
57 return std::move(*opt);
58 }
59
60 } // namespace opt
61 } // namespace mlspp::tls