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

View file

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

View file

@ -1,5 +1,7 @@
#pragma once
#include <source_location>
#ifndef __has_include
#define __has_include(x) 0
#endif
@ -57,3 +59,21 @@ using fmt::vformat;
using fmt::vformat_to;
} // namespace rx
#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();
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
template <typename T>