Skip to content

Commit 96db0b2

Browse files
authored
refactor: use ostream in the error formatter (#136)
* refactor: inherit `fmt::formatter<errors::Error>` from `ostream_formatter` * build: modify `errors_format` target to be interface library
1 parent 4181a2f commit 96db0b2

File tree

3 files changed

+6
-30
lines changed

3 files changed

+6
-30
lines changed

components/format/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
cpmaddpackage("gh:fmtlib/fmt#10.2.0")
22

3-
add_library(errors_format src/format.cpp)
3+
add_library(errors_format INTERFACE)
44
target_sources(
55
errors_format PUBLIC
66
FILE_SET HEADERS
77
BASE_DIRS include
88
FILES include/errors/format.hpp
99
)
10-
target_link_libraries(errors_format PUBLIC errors fmt)
10+
target_link_libraries(errors_format INTERFACE errors fmt)
1111

1212
if(NOT_SUBPROJECT)
1313
if (BUILD_TESTING)
1414
# Append the main library properties instead of linking the library.
15-
get_target_property(errors_format_SOURCES errors_format SOURCES)
1615
get_target_property(errors_format_HEADER_DIRS errors_format HEADER_DIRS)
17-
get_target_property(errors_format_LIBRARIES errors_format LINK_LIBRARIES)
16+
get_target_property(errors_format_LIBRARIES errors_format INTERFACE_LINK_LIBRARIES)
1817

1918
# Build tests for the main library
20-
add_executable(errors_format_test test/format_test.cpp ${errors_format_SOURCES})
19+
add_executable(errors_format_test test/format_test.cpp)
2120
target_include_directories(errors_format_test PRIVATE ${errors_format_HEADER_DIRS})
2221
target_link_libraries(errors_format_test PRIVATE Catch2::Catch2WithMain ${errors_format_LIBRARIES})
2322

components/format/include/errors/format.hpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <errors/error.hpp>
44
#include <fmt/core.h>
5+
#include <fmt/ostream.h>
56

67
namespace errors {
78

@@ -17,15 +18,6 @@ Error format(fmt::format_string<T...> fmt, T&&... args);
1718

1819
} // namespace errors
1920

20-
namespace fmt {
21-
22-
template <>
23-
struct formatter<errors::Error> {
24-
format_parse_context::iterator parse(format_parse_context& ctx) const;
25-
format_context::iterator format(const errors::Error& err,
26-
format_context& ctx) const;
27-
};
28-
29-
} // namespace fmt
21+
template <> struct fmt::formatter<errors::Error> : ostream_formatter {};
3022

3123
#include "format.ipp"

components/format/src/format.cpp

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)