From a7137d330728aaf6603d12c47bb4ec9f393e6f45 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 25 Dec 2023 16:18:43 +0700 Subject: [PATCH] feat: modify `Error::message` to return `std::string_view` --- include/errors/error.hpp | 3 ++- src/error.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/errors/error.hpp b/include/errors/error.hpp index 8c158a9..ea42138 100644 --- a/include/errors/error.hpp +++ b/include/errors/error.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include namespace errors { @@ -27,7 +28,7 @@ class Error { * std::cout << err << std::endl; * @endcode */ - std::string message() const; + std::string_view message() const; friend Error make(const std::string& msg); diff --git a/src/error.cpp b/src/error.cpp index 6eb82c7..44d040f 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -4,7 +4,7 @@ namespace errors { Error::Error(const std::shared_ptr& message_ptr) : message_ptr(message_ptr) {} -std::string Error::message() const { +std::string_view Error::message() const { if (!message_ptr) return "no error"; return *message_ptr; }