diff --git a/rx/include/rx/StaticString.hpp b/rx/include/rx/StaticString.hpp index 708375c2d..58474803f 100644 --- a/rx/include/rx/StaticString.hpp +++ b/rx/include/rx/StaticString.hpp @@ -1,10 +1,10 @@ #pragma once #include "format-base.hpp" +#include "rx/die.hpp" #include #include #include #include -#include #include #include @@ -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]; } diff --git a/rx/include/rx/die.hpp b/rx/include/rx/die.hpp index 833001e47..56e6c6bc1 100644 --- a/rx/include/rx/die.hpp +++ b/rx/include/rx/die.hpp @@ -1,6 +1,6 @@ #pragma once -#include "format.hpp" +#include "format-base.hpp" namespace rx { namespace detail { diff --git a/rx/include/rx/format-base.hpp b/rx/include/rx/format-base.hpp index 4baa2c96d..57d5029c8 100644 --- a/rx/include/rx/format-base.hpp +++ b/rx/include/rx/format-base.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #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 +struct format_string_with_location_impl : format_string { + std::source_location location; + + template + constexpr format_string_with_location_impl( + T message, + std::source_location location = std::source_location::current()) + : format_string(message), location(location) {} +}; +} // namespace detail +template +using format_string_with_location = + std::type_identity_t>; +} // namespace rx diff --git a/rx/include/rx/format.hpp b/rx/include/rx/format.hpp index c5449aade..7beffe405 100644 --- a/rx/include/rx/format.hpp +++ b/rx/include/rx/format.hpp @@ -130,22 +130,6 @@ template void registerVariable() { auto &storage = detail::getVariableStorage(); storage.infos[&Variable] = rx::getNameOf(); } - -namespace detail { -template -struct format_string_with_location_impl : format_string { - std::source_location location; - - template - constexpr format_string_with_location_impl( - T message, - std::source_location location = std::source_location::current()) - : format_string(message), location(location) {} -}; -} // namespace detail -template -using format_string_with_location = - std::type_identity_t>; } // namespace rx template