From 87d8a9c98626be491e87e4b9fad84b862d8aa0c9 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 15 Aug 2018 05:38:37 -0400 Subject: loader: Make ResultStatus directly compatible with fmt We can make the enum class type compatible with fmt by providing an overload of operator<<. While we're at it, perform proper bounds checking. If something exceeds the array, it should be a hard fail, because it's, without a doubt, a programmer error in this case. --- src/core/loader/loader.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/core/loader/loader.cpp') diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index b143f043c..5e07a3f10 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include "common/logging/log.h" #include "common/string_util.h" @@ -119,14 +120,9 @@ constexpr std::array RESULT_MESSAGES{ "There is no control data available.", }; -std::string GetMessageForResultStatus(ResultStatus status) { - return GetMessageForResultStatus(static_cast(status)); -} - -std::string GetMessageForResultStatus(u16 status) { - if (status >= 36) - return ""; - return RESULT_MESSAGES[status]; +std::ostream& operator<<(std::ostream& os, ResultStatus status) { + os << RESULT_MESSAGES.at(static_cast(status)); + return os; } /** -- cgit v1.2.3