rx/StaticString: do not throw exceptions

This commit is contained in:
DH 2025-10-04 16:47:06 +03:00
parent dbfa5002e5
commit b8e08c1470
4 changed files with 24 additions and 24 deletions

View file

@ -1,10 +1,10 @@
#pragma once #pragma once
#include "format-base.hpp" #include "format-base.hpp"
#include "rx/die.hpp"
#include <cassert> #include <cassert>
#include <compare> #include <compare>
#include <cstddef> #include <cstddef>
#include <cstring> #include <cstring>
#include <stdexcept>
#include <string_view> #include <string_view>
#include <type_traits> #include <type_traits>
@ -111,16 +111,12 @@ public:
} }
[[nodiscard]] char &at(std::size_t pos) { [[nodiscard]] char &at(std::size_t pos) {
if (pos >= m_size) { dieIf(pos >= m_size, "StaticString::at: index out of range");
throw std::out_of_range("StaticString::at: index out of range");
}
return m_data[pos]; return m_data[pos];
} }
[[nodiscard]] constexpr char &at(std::size_t pos) const { [[nodiscard]] constexpr char &at(std::size_t pos) const {
if (pos >= m_size) { dieIf(pos >= m_size, "StaticString::at: index out of range");
throw std::out_of_range("StaticString::at: index out of range");
}
return m_data[pos]; return m_data[pos];
} }

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "format.hpp" #include "format-base.hpp"
namespace rx { namespace rx {
namespace detail { namespace detail {

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <source_location>
#ifndef __has_include #ifndef __has_include
#define __has_include(x) 0 #define __has_include(x) 0
#endif #endif
@ -57,3 +59,21 @@ using fmt::vformat;
using fmt::vformat_to; using fmt::vformat_to;
} // namespace rx } // namespace rx
#endif #endif
namespace rx {
namespace detail {
template <typename... Args>
struct format_string_with_location_impl : format_string<Args...> {
std::source_location location;
template <typename T>
constexpr format_string_with_location_impl(
T message,
std::source_location location = std::source_location::current())
: format_string<Args...>(message), location(location) {}
};
} // namespace detail
template <typename... Args>
using format_string_with_location =
std::type_identity_t<detail::format_string_with_location_impl<Args...>>;
} // namespace rx

View file

@ -130,22 +130,6 @@ template <auto &&Variable> void registerVariable() {
auto &storage = detail::getVariableStorage(); auto &storage = detail::getVariableStorage();
storage.infos[&Variable] = rx::getNameOf<Variable>(); storage.infos[&Variable] = rx::getNameOf<Variable>();
} }
namespace detail {
template <typename... Args>
struct format_string_with_location_impl : format_string<Args...> {
std::source_location location;
template <typename T>
constexpr format_string_with_location_impl(
T message,
std::source_location location = std::source_location::current())
: format_string<Args...>(message), location(location) {}
};
} // namespace detail
template <typename... Args>
using format_string_with_location =
std::type_identity_t<detail::format_string_with_location_impl<Args...>>;
} // namespace rx } // namespace rx
template <typename T> template <typename T>