Skip to content

Commit

Permalink
feat: modify Error::message to return std::string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Dec 25, 2023
1 parent 6780674 commit a7137d3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/errors/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <memory>
#include <ostream>
#include <string>
#include <string_view>
#include <utility>

namespace errors {
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace errors {

Error::Error(const std::shared_ptr<const std::string>& 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;
}
Expand Down

0 comments on commit a7137d3

Please # to comment.