diff options
Diffstat (limited to 'server/src/util.cppm')
| -rw-r--r-- | server/src/util.cppm | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/server/src/util.cppm b/server/src/util.cppm index 2e20e8b..bdccf10 100644 --- a/server/src/util.cppm +++ b/server/src/util.cppm | |||
| @@ -14,9 +14,9 @@ struct overloaded : Ts... | |||
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| 16 | export constexpr auto parse_double( | 16 | export constexpr auto parse_double( |
| 17 | std::string_view s, | 17 | std::string_view s, |
| 18 | std::chars_format fmt = std::chars_format::general) noexcept | 18 | std::chars_format fmt = std::chars_format::general) noexcept |
| 19 | -> std::optional<double> | 19 | -> std::optional<double> |
| 20 | { | 20 | { |
| 21 | auto x = 0.0; | 21 | auto x = 0.0; |
| 22 | auto [_, ec] = std::from_chars(s.data(), s.data() + s.size(), x, fmt); | 22 | auto [_, ec] = std::from_chars(s.data(), s.data() + s.size(), x, fmt); |
| @@ -31,9 +31,9 @@ export constexpr auto parse_double( | |||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | export constexpr auto parse_float( | 33 | export constexpr auto parse_float( |
| 34 | std::string_view s, | 34 | std::string_view s, |
| 35 | std::chars_format fmt = std::chars_format::general) noexcept | 35 | std::chars_format fmt = std::chars_format::general) noexcept |
| 36 | -> std::optional<float> | 36 | -> std::optional<float> |
| 37 | { | 37 | { |
| 38 | auto x = 0.0; | 38 | auto x = 0.0; |
| 39 | auto [_, ec] = std::from_chars(s.data(), s.data() + s.size(), x, fmt); | 39 | auto [_, ec] = std::from_chars(s.data(), s.data() + s.size(), x, fmt); |
| @@ -62,7 +62,7 @@ public: | |||
| 62 | static auto nil() -> std::shared_ptr<aolist<T>> { return nullptr; } | 62 | static auto nil() -> std::shared_ptr<aolist<T>> { return nullptr; } |
| 63 | 63 | ||
| 64 | static auto cons(T v, std::shared_ptr<aolist<T> const> l) | 64 | static auto cons(T v, std::shared_ptr<aolist<T> const> l) |
| 65 | -> std::shared_ptr<aolist<T>> | 65 | -> std::shared_ptr<aolist<T>> |
| 66 | { | 66 | { |
| 67 | return std::shared_ptr<aolist<T>>{new aolist<T>{v, l}}; | 67 | return std::shared_ptr<aolist<T>>{new aolist<T>{v, l}}; |
| 68 | } | 68 | } |
| @@ -75,8 +75,8 @@ public: | |||
| 75 | export constexpr auto size_from_int(int x) -> std::optional<std::size_t> | 75 | export constexpr auto size_from_int(int x) -> std::optional<std::size_t> |
| 76 | { | 76 | { |
| 77 | static_assert( | 77 | static_assert( |
| 78 | sizeof(int) <= sizeof(std::size_t), | 78 | sizeof(int) <= sizeof(std::size_t), |
| 79 | "cannot cast int to smaller size_t type"); | 79 | "cannot cast int to smaller size_t type"); |
| 80 | if (x < 0) | 80 | if (x < 0) |
| 81 | return std::nullopt; | 81 | return std::nullopt; |
| 82 | return static_cast<std::size_t>(x); | 82 | return static_cast<std::size_t>(x); |
| @@ -155,7 +155,8 @@ public: | |||
| 155 | { | 155 | { |
| 156 | s_ = rhs.s_; | 156 | s_ = rhs.s_; |
| 157 | length_.store( | 157 | length_.store( |
| 158 | rhs.length_.load(std::memory_order_acquire), std::memory_order_release); | 158 | rhs.length_.load(std::memory_order_acquire), |
| 159 | std::memory_order_release); | ||
| 159 | } | 160 | } |
| 160 | return *this; | 161 | return *this; |
| 161 | } | 162 | } |
| @@ -202,7 +203,7 @@ public: | |||
| 202 | }; | 203 | }; |
| 203 | 204 | ||
| 204 | constexpr auto operator""_zsv(char const* s, std::size_t length) noexcept | 205 | constexpr auto operator""_zsv(char const* s, std::size_t length) noexcept |
| 205 | -> zstring_view | 206 | -> zstring_view |
| 206 | { | 207 | { |
| 207 | return zstring_view{s, length}; | 208 | return zstring_view{s, length}; |
| 208 | } | 209 | } |
| @@ -213,7 +214,7 @@ auto operator==(zstring_view lhs, zstring_view rhs) -> bool | |||
| 213 | } | 214 | } |
| 214 | 215 | ||
| 215 | export constexpr auto split_on(std::string_view s, char c) | 216 | export constexpr auto split_on(std::string_view s, char c) |
| 216 | -> std::pair<std::string_view, std::optional<std::string_view>> | 217 | -> std::pair<std::string_view, std::optional<std::string_view>> |
| 217 | { | 218 | { |
| 218 | if (auto i = s.find(c); i != std::string_view::npos) | 219 | if (auto i = s.find(c); i != std::string_view::npos) |
| 219 | return std::make_pair(s.substr(0, i), s.substr(i + 1)); | 220 | return std::make_pair(s.substr(0, i), s.substr(i + 1)); |