From 1ef2f014eeb9defcfa9e9d5bce95b14d739947f0 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 8 May 2021 19:13:22 -0700 Subject: [PATCH] small std::find conversion Signed-off-by: Rosen Penev --- include/spdlog/common-inl.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/include/spdlog/common-inl.h b/include/spdlog/common-inl.h index 378efe60..d0c85c6b 100644 --- a/include/spdlog/common-inl.h +++ b/include/spdlog/common-inl.h @@ -7,6 +7,9 @@ #include #endif +#include +#include + namespace spdlog { namespace level { @@ -31,15 +34,10 @@ SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOE SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT { - int level = 0; - for (const auto &level_str : level_string_views) - { - if (level_str == name) - { - return static_cast(level); - } - level++; - } + auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name); + if (it != std::end(level_string_views)) + return static_cast(std::distance(std::begin(level_string_views), it)); + // check also for "warn" and "err" before giving up.. if (name == "warn") {