lib: fix clang compatibility / warnings
This commit is contained in:
@ -162,6 +162,16 @@ Command::get_int(const Parameters& params, const std::string& argname)
|
||||
return ::atoi(it->value().c_str());
|
||||
}
|
||||
|
||||
std::optional<unsigned>
|
||||
Command::get_unsigned(const Parameters& params, const std::string& argname)
|
||||
{
|
||||
if (auto val = get_int(params, argname); val && *val >= 0)
|
||||
return val;
|
||||
else
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
std::optional<bool>
|
||||
Command::get_bool(const Parameters& params, const std::string& argname)
|
||||
{
|
||||
|
||||
@ -63,6 +63,7 @@ using ArgMap = std::unordered_map<std::string, ArgInfo>;
|
||||
using Parameters = Sexp::Seq;
|
||||
|
||||
std::optional<int> get_int(const Parameters& parms, const std::string& argname);
|
||||
std::optional<unsigned> get_unsigned(const Parameters& parms, const std::string& argname);
|
||||
std::optional<bool> get_bool(const Parameters& parms, const std::string& argname);
|
||||
std::optional<std::string> get_string(const Parameters& parms, const std::string& argname);
|
||||
std::optional<std::string> get_symbol(const Parameters& parms, const std::string& argname);
|
||||
@ -76,6 +77,7 @@ static inline int
|
||||
get_int_or(const Parameters& parms, const std::string& arg, int alt = 0) {
|
||||
return get_int(parms, arg).value_or(alt);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
get_bool_or(const Parameters& parms, const std::string& arg, bool alt = false) {
|
||||
return get_bool(parms, arg).value_or(alt);
|
||||
|
||||
@ -103,7 +103,7 @@ struct Error final : public std::exception {
|
||||
* DTOR
|
||||
*
|
||||
*/
|
||||
virtual ~Error() = default;
|
||||
virtual ~Error() override = default;
|
||||
|
||||
/**
|
||||
* Get the descriptiove message.
|
||||
|
||||
@ -38,7 +38,9 @@ template <typename T> using Result = tl::expected<T, Error>;
|
||||
* @return a success Result<T>
|
||||
*/
|
||||
template <typename T>
|
||||
typename Result<T>::expected
|
||||
class Result<T>::expected
|
||||
// note: "class", not "typename";
|
||||
// https://stackoverflow.com/questions/46412754/class-name-injection-and-constructors
|
||||
Ok(T&& t)
|
||||
{
|
||||
return std::move(t);
|
||||
|
||||
@ -296,7 +296,7 @@ struct Sexp {
|
||||
return false;
|
||||
else
|
||||
return is_prop_list(list().begin() + 1, list().end());
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
Sexp(Type typearg, std::string&& valuearg) : type_{typearg}, value_{std::move(valuearg)}
|
||||
|
||||
@ -401,8 +401,8 @@ mu_util_get_hash (const char* str)
|
||||
bkdrseed = 1313;
|
||||
|
||||
for(unsigned u = 0U; str[u]; ++u) {
|
||||
djbhash = ((djbhash << 5) + djbhash) + str[u];
|
||||
bkdrhash = bkdrhash * bkdrseed + str[u];
|
||||
djbhash = ((djbhash << 5) + djbhash) + (unsigned)str[u];
|
||||
bkdrhash = bkdrhash * bkdrseed + (unsigned)str[u];
|
||||
}
|
||||
|
||||
hash = djbhash;
|
||||
|
||||
@ -191,13 +191,13 @@ struct StopWatch {
|
||||
StopWatch(const std::string name) : start_{Clock::now()}, name_{name} {}
|
||||
~StopWatch()
|
||||
{
|
||||
const auto us{to_us(Clock::now() - start_)};
|
||||
const auto us{static_cast<double>(to_us(Clock::now() - start_))};
|
||||
if (us > 2000000)
|
||||
g_debug("%s: finished after %0.1f s", name_.c_str(), us / 1000000.0);
|
||||
g_debug("%s: finished after %0.1f s", name_.c_str(), us / 1000000);
|
||||
else if (us > 2000)
|
||||
g_debug("%s: finished after %0.1f ms", name_.c_str(), us / 1000.0);
|
||||
g_debug("%s: finished after %0.1f ms", name_.c_str(), us / 1000);
|
||||
else
|
||||
g_debug("%s: finished after %" G_GINT64_FORMAT " us", name_.c_str(), us);
|
||||
g_debug("%s: finished after %g us", name_.c_str(), us);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -304,8 +304,8 @@ private:
|
||||
constexpr ET operator~(ET e) { return MU_TO_ENUM(ET, ~(MU_TO_NUM(ET, e))); } \
|
||||
constexpr bool any_of(ET e) { return MU_TO_NUM(ET, e) != 0; } \
|
||||
constexpr bool none_of(ET e) { return MU_TO_NUM(ET, e) == 0; } \
|
||||
constexpr ET& operator&=(ET& e1, ET e2) { return e1 = e1 & e2; } \
|
||||
constexpr ET& operator|=(ET& e1, ET e2) { return e1 = e1 | e2; }
|
||||
constexpr ET& operator&=(ET& e1, ET e2) { return e1 = e1 & e2; } \
|
||||
constexpr ET& operator|=(ET& e1, ET e2) { return e1 = e1 | e2; } \
|
||||
|
||||
/**
|
||||
* For unit tests, assert two std::string's are equal.
|
||||
|
||||
Reference in New Issue
Block a user