Browse Source

Various compilation fixes.

wip/core-clipp
Sam Hocevar 4 years ago
parent
commit
7a309a53d1
2 changed files with 41 additions and 9 deletions
  1. +40
    -8
      include/lol/base/string.h
  2. +1
    -1
      include/lol/math/polynomial.h

+ 40
- 8
include/lol/base/string.h View File

@@ -67,6 +67,14 @@ std::vector<std::basic_string<T>> split(std::basic_string<T> const &s,

}

// Helper for template deduction
template<typename T>
std::vector<std::basic_string<T>> split(std::basic_string<T> const &s,
T const *seps)
{
return split(s, std::basic_string<T>(seps));
}

// Check whether a string starts or ends with a given substring
template<typename T>
bool starts_with(std::basic_string<T> const &s,
@@ -76,6 +84,12 @@ bool starts_with(std::basic_string<T> const &s,
s.compare(0, prefix.size(), prefix) == 0;
}

template<typename T>
bool starts_with(std::basic_string<T> const &s, T const *prefix)
{
return starts_with(s, std::basic_string<T>(prefix));
}

template<typename T>
bool ends_with(std::basic_string<T> const &s,
std::basic_string<T> const &suffix)
@@ -84,6 +98,12 @@ bool ends_with(std::basic_string<T> const &s,
s.compare(s.size() - suffix.size(), suffix.size(), suffix) == 0;
}

template<typename T>
bool ends_with(std::basic_string<T> const &s, T const *suffix)
{
return ends_with(s, std::basic_string<T>(suffix));
}

// Convert a string to lowercase or uppercase
template<typename T>
std::basic_string<T> tolower(std::basic_string<T> const &s)
@@ -94,6 +114,12 @@ std::basic_string<T> tolower(std::basic_string<T> const &s)
return ret;
}

template<typename T>
std::basic_string<T> tolower(T const *s)
{
return tolower(std::basic_string<T>(s));
}

template<typename T>
std::basic_string<T> toupper(std::basic_string<T> const &s)
{
@@ -103,17 +129,13 @@ std::basic_string<T> toupper(std::basic_string<T> const &s)
return ret;
}

// Format a string, printf-style
template<typename T = char> lol_attr_printf_format(1, 2)
std::basic_string<T> format(T const *format, ...)
template<typename T>
std::basic_string<T> 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<T>(s));
}

// Format a string, printf-style
template<typename T = char>
std::basic_string<T> vformat(char const *format, va_list ap)
{
@@ -141,5 +163,15 @@ std::basic_string<T> vformat(char const *format, va_list ap)
return ret;
}

template<typename T = char> lol_attr_printf_format(1, 2)
std::basic_string<T> format(T const *format, ...)
{
va_list ap;
va_start(ap, format);
std::string ret = vformat(format, ap);
va_end(ap);
return ret;
}

} /* namespace lol */


+ 1
- 1
include/lol/math/polynomial.h View File

@@ -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;


Loading…
Cancel
Save