Skip to content

Commit 0185b10

Browse files
authored
feat: return message as a string view (#95)
* feat: modify `Error::message` to return `std::string_view` * build: set `CMAKE_CXX_STANDARD` to `17`
1 parent 973a39b commit 0185b10

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
66
set(NOT_SUBPROJECT TRUE)
77
endif()
88

9+
set(CMAKE_CXX_STANDARD 17)
10+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
912
# Initialize CPM.cmake
1013
include(cmake/CPM.cmake)
1114

include/errors/error.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <memory>
44
#include <ostream>
55
#include <string>
6+
#include <string_view>
67
#include <utility>
78

89
namespace errors {
@@ -27,7 +28,7 @@ class Error {
2728
* std::cout << err << std::endl;
2829
* @endcode
2930
*/
30-
std::string message() const;
31+
std::string_view message() const;
3132

3233
friend Error make(const std::string& msg);
3334

src/error.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace errors {
44

55
Error::Error(const std::shared_ptr<const std::string>& message_ptr) : message_ptr(message_ptr) {}
66

7-
std::string Error::message() const {
7+
std::string_view Error::message() const {
88
if (!message_ptr) return "no error";
99
return *message_ptr;
1010
}

0 commit comments

Comments
 (0)