diff --git a/include/perfcpp/exception.hpp b/include/perfcpp/exception.hpp index 3a06e99..052eb5f 100644 --- a/include/perfcpp/exception.hpp +++ b/include/perfcpp/exception.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace perf { @@ -98,7 +99,7 @@ class CannotOpenCounterError final : public std::runtime_error * @param error_code Error code raised when calling perf_event_open. * @return Error message that can be thrown to inform the user. */ - [[nodiscard]] static std::string create_error_message_from_code(std::int64_t error_code); + [[nodiscard]] static std::string_view create_error_message_from_code(std::int64_t error_code); }; class CannotReadCounter final : public std::runtime_error @@ -134,7 +135,7 @@ class IoctlError : public std::runtime_error ~IoctlError() override = default; protected: - [[nodiscard]] static std::string create_error_message_from_code(std::int64_t error_code); + [[nodiscard]] static std::string_view create_error_message_from_code(std::int64_t error_code); }; class CannotEnableCounter final : public IoctlError diff --git a/src/exception.cpp b/src/exception.cpp index d0b782f..80cc85a 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -1,7 +1,7 @@ #include #include -std::string +std::string_view perf::CannotOpenCounterError::create_error_message_from_code(const std::int64_t error_code) { switch (error_code) { @@ -37,7 +37,7 @@ perf::CannotOpenCounterError::create_error_message_from_code(const std::int64_t } } -std::string +std::string_view perf::IoctlError::create_error_message_from_code(const std::int64_t error_code) { switch (error_code) {