srctree

Robin Linden parent 3fdc2817 17e0a390
all: Constexpr functions using std::string/std::vector

This is possible now that we no longer support gcc 11.

inlinesplit
gfx/canvas_command_saver.h added: 9, removed: 11, total 0
@@ -136,7 +136,7 @@ public:
canvas_.draw_rect(cmd.rect, cmd.color, cmd.borders, cmd.corners);
}
 
void operator()(DrawTextWithFontOptionsCmd const &cmd) {
constexpr void operator()(DrawTextWithFontOptionsCmd const &cmd) {
std::vector<gfx::Font> fonts;
std::ranges::transform(
cmd.font_options, std::back_inserter(fonts), [](auto const &font) { return gfx::Font{font}; });
@@ -151,7 +151,7 @@ private:
ICanvas &canvas_;
};
 
inline void replay_commands(ICanvas &canvas, std::vector<CanvasCommand> const &commands) {
constexpr void replay_commands(ICanvas &canvas, std::vector<CanvasCommand> const &commands) {
CanvasCommandVisitor visitor{canvas};
for (auto const &command : commands) {
std::visit(visitor, command);
 
util/string.h added: 9, removed: 11, total 0
@@ -73,7 +73,7 @@ constexpr char lowercased(char c) {
return c + ('a' - 'A');
}
 
[[nodiscard]] inline std::string lowercased(std::string s) {
[[nodiscard]] constexpr std::string lowercased(std::string s) {
std::ranges::for_each(s, [](char &c) { c = lowercased(c); });
return s;
}
@@ -82,7 +82,7 @@ constexpr bool no_case_compare(std::string_view a, std::string_view b) {
return std::ranges::equal(a, b, [](auto c1, auto c2) { return lowercased(c1) == lowercased(c2); });
}
 
inline std::vector<std::string_view> split(std::string_view str, std::string_view sep) {
constexpr std::vector<std::string_view> split(std::string_view str, std::string_view sep) {
std::vector<std::string_view> result{};
for (auto p = str.find(sep); p != str.npos; p = str.find(sep)) {
result.push_back(str.substr(0, p));
@@ -124,9 +124,8 @@ constexpr std::string_view trim(std::string_view s) {
return s;
}
 
// To-Do(zero-one): specify constexpr when we drop gcc-11 support
// https://url.spec.whatwg.org/#concept-ipv4-serializer
inline std::string ipv4_serialize(std::uint32_t addr) {
constexpr std::string ipv4_serialize(std::uint32_t addr) {
std::string out = "";
std::uint32_t n = addr;
 
@@ -143,7 +142,6 @@ inline std::string ipv4_serialize(std::uint32_t addr) {
return out;
}
 
// To-Do(zero-one): specify constexpr when we drop gcc-11 support
// https://url.spec.whatwg.org/#concept-ipv6-serializer
inline std::string ipv6_serialize(std::span<std::uint16_t, 8> addr) {
std::stringstream out;
 
util/unicode.h added: 9, removed: 11, total 0
@@ -34,7 +34,7 @@ constexpr int unicode_utf8_byte_count(std::uint32_t code_point) {
return 0;
}
 
inline std::string unicode_to_utf8(std::uint32_t code_point) {
constexpr std::string unicode_to_utf8(std::uint32_t code_point) {
switch (unicode_utf8_byte_count(code_point)) {
case 1:
return {static_cast<char>(code_point & 0x7F)};