From d4c6063ea770db10c3266dc274fc504cf62d6795 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Sat, 23 Nov 2024 23:05:19 -0500 Subject: [PATCH] update formatters --- .github/workflows/build.yml | 18 ++++++++++++++++++ spectator/id.h | 5 ++--- spectator/measurement.h | 16 ++++------------ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9639b0a..01ef513 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,15 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Restore Conan Cache + id: conan-cache-restore + uses: actions/cache/restore@v4 + with: + path: | + /home/runner/.conan2 + /home/runner/work/spectator-cpp/spectator-cpp/cmake-build + key: ${{ runner.os }}-conan + - name: Install System Dependencies run: | sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test @@ -23,3 +32,12 @@ jobs: ./setup-venv.sh source venv/bin/activate ./build.sh + + - name: Save Conan Cache + id: conan-cache-save + uses: actions/cache/save@v4 + with: + path: | + /home/runner/.conan2 + /home/runner/work/spectator-cpp/spectator-cpp/cmake-build + key: ${{ steps.conan-cache-restore.outputs.cache-primary-key }} diff --git a/spectator/id.h b/spectator/id.h index 355f086..0087e42 100644 --- a/spectator/id.h +++ b/spectator/id.h @@ -217,8 +217,7 @@ template <> struct fmt::formatter: formatter }; template <> struct fmt::formatter: formatter { - auto format(const spectator::Id& id, format_context& ctx) const -> format_context::iterator { - auto s = fmt::format("Id(name={}, tags={})", id.Name(), id.GetTags()); - return fmt::formatter::format(s, ctx); + static auto format(const spectator::Id& id, format_context& ctx) -> format_context::iterator { + return fmt::format_to(ctx.out(), "Id(name={}, tags={})", id.Name(), id.GetTags()); } }; diff --git a/spectator/measurement.h b/spectator/measurement.h index 00e2b87..ad88200 100644 --- a/spectator/measurement.h +++ b/spectator/measurement.h @@ -18,16 +18,8 @@ struct Measurement { } // namespace spectator -template <> -struct fmt::formatter { - constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { - return ctx.begin(); +template <> struct fmt::formatter: formatter { + static auto format(const spectator::Measurement& m, format_context& ctx) -> format_context::iterator { + return fmt::format_to(ctx.out(), "Measurement({}, {})", *(m.id), m.value); } - - // formatter for Ids - template - auto format(const spectator::Measurement& m, FormatContext& context) { - return fmt::format_to(context.out(), "Measurement({}, {})", *(m.id), - m.value); - } -}; \ No newline at end of file +};