diff --git a/include/lol/base/string.h b/include/lol/base/string.h index 7a653974..94c6e632 100644 --- a/include/lol/base/string.h +++ b/include/lol/base/string.h @@ -67,6 +67,14 @@ std::vector> split(std::basic_string const &s, } +// Helper for template deduction +template +std::vector> split(std::basic_string const &s, + T const *seps) +{ + return split(s, std::basic_string(seps)); +} + // Check whether a string starts or ends with a given substring template bool starts_with(std::basic_string const &s, @@ -76,6 +84,12 @@ bool starts_with(std::basic_string const &s, s.compare(0, prefix.size(), prefix) == 0; } +template +bool starts_with(std::basic_string const &s, T const *prefix) +{ + return starts_with(s, std::basic_string(prefix)); +} + template bool ends_with(std::basic_string const &s, std::basic_string const &suffix) @@ -84,6 +98,12 @@ bool ends_with(std::basic_string const &s, s.compare(s.size() - suffix.size(), suffix.size(), suffix) == 0; } +template +bool ends_with(std::basic_string const &s, T const *suffix) +{ + return ends_with(s, std::basic_string(suffix)); +} + // Convert a string to lowercase or uppercase template std::basic_string tolower(std::basic_string const &s) @@ -94,6 +114,12 @@ std::basic_string tolower(std::basic_string const &s) return ret; } +template +std::basic_string tolower(T const *s) +{ + return tolower(std::basic_string(s)); +} + template std::basic_string toupper(std::basic_string const &s) { @@ -103,17 +129,13 @@ std::basic_string toupper(std::basic_string const &s) return ret; } -// Format a string, printf-style -template lol_attr_printf_format(1, 2) -std::basic_string format(T const *format, ...) +template +std::basic_string toupper(T const *s) { - va_list ap; - va_start(ap, format); - std::string ret = vformat(format, ap); - va_end(ap); - return ret; + return toupper(std::basic_string(s)); } +// Format a string, printf-style template std::basic_string vformat(char const *format, va_list ap) { @@ -141,5 +163,15 @@ std::basic_string vformat(char const *format, va_list ap) return ret; } +template lol_attr_printf_format(1, 2) +std::basic_string format(T const *format, ...) +{ + va_list ap; + va_start(ap, format); + std::string ret = vformat(format, ap); + va_end(ap); + return ret; +} + } /* namespace lol */ diff --git a/include/lol/math/polynomial.h b/include/lol/math/polynomial.h index 73c25be9..deee1ee4 100644 --- a/include/lol/math/polynomial.h +++ b/include/lol/math/polynomial.h @@ -405,7 +405,7 @@ struct lol_attr_nodiscard polynomial quotient.set(n, remainder.leading()); for (int i = 0; i < p.degree(); ++i) remainder.m_coefficients[n + i] -= remainder.leading() * p[i]; - (void)remainder.m_coefficients.pop(); + (void)remainder.m_coefficients.pop_back(); } return ret;