Skip to content

Commit

Permalink
chore: add noexcept to fixedstring
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Oct 11, 2024
1 parent a26ce38 commit 204312a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
32 changes: 17 additions & 15 deletions src/ll/api/base/FixedString.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ template <size_t N>
struct FixedString {
char buf[N + 1]{};

consteval FixedString() = default;
consteval FixedString(std::string_view s) { std::copy_n(s.data(), s.size(), buf); }
consteval FixedString(char const* s) { std::copy_n(s, N, buf); }
consteval FixedString() noexcept = default;
consteval FixedString(std::string_view s) noexcept { std::copy_n(s.data(), s.size(), buf); }
consteval FixedString(char const* s) noexcept { std::copy_n(s, N, buf); }

consteval operator std::string_view() const { return buf; }
constexpr operator std::string_view() const noexcept { return buf; }

consteval char const* c_str() const { return buf; }
consteval std::string_view sv() const { return buf; }
constexpr std::string str() const { return buf; }
constexpr char const* c_str() const noexcept { return buf; }
constexpr std::string_view sv() const noexcept { return buf; }
constexpr std::string str() const noexcept { return buf; }

[[nodiscard]] constexpr char const& operator[](size_t idx) const { return buf[idx]; }
[[nodiscard]] constexpr char& operator[](size_t idx) { return buf[idx]; }
[[nodiscard]] constexpr char const& operator[](size_t idx) const noexcept { return buf[idx]; }
[[nodiscard]] constexpr char& operator[](size_t idx) noexcept { return buf[idx]; }

template <size_t Ny>
consteval auto operator+(const FixedString<Ny>& other) {
consteval auto operator+(const FixedString<Ny>& other) noexcept {
FixedString<N + Ny> res{};
std::copy_n(buf, N, res.buf);
std::copy_n(other.buf, Ny, N + res.buf);
Expand All @@ -35,14 +35,16 @@ struct FixedString {

template <size_t N>
struct FixedStrWithLoc : FixedString<N> {
SourceLocation loc;
SourceLocation location;

consteval FixedStrWithLoc(std::string_view s, SourceLocation const& loc = SourceLocation::current())
consteval FixedStrWithLoc(std::string_view s, SourceLocation const& loc = SourceLocation::current()) noexcept
: FixedString<N>(s),
loc(loc) {}
consteval FixedStrWithLoc(char const* s, SourceLocation const& loc = SourceLocation::current())
location(loc) {}
consteval FixedStrWithLoc(char const* s, SourceLocation const& loc = SourceLocation::current()) noexcept
: FixedString<N>(s),
loc(loc) {}
location(loc) {}

constexpr SourceLocation const& loc() const noexcept { return location; }
};

template <size_t N>
Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/i18n/I18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct TrStrOut;
template <LL_I18N_STRING_LITERAL_TYPE str>
struct TrStrOut {
static inline int _ = [] {
fmt::print("\"{0}\": \"{0}\", // at {1}\n", str.sv(), str.loc.toString());
fmt::print("\"{0}\": \"{0}\", // at {1}\n", str.sv(), str.loc().toString());
return 0;
}();
};
Expand Down
2 changes: 1 addition & 1 deletion tooth.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.13.5",
"info": {
"name": "LeviLamina",
"description": "A lightweight, modular and versatile mod loader for Minecraft Bedrock Server BDS, formerly known as LiteLoaderBDS",
"description": "A lightweight, modular and versatile mod loader for Minecraft Bedrock Edition.",
"author": "LiteLDev",
"tags": []
},
Expand Down

0 comments on commit 204312a

Please sign in to comment.