Skip to content

Commit

Permalink
update formatters (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
copperlight authored Nov 24, 2024
1 parent 9175290 commit 5761837
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
5 changes: 2 additions & 3 deletions spectator/id.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ template <> struct fmt::formatter<spectator::Tags>: formatter<std::string_view>
};

template <> struct fmt::formatter<spectator::Id>: formatter<std::string_view> {
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<std::string_view>::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());
}
};
16 changes: 4 additions & 12 deletions spectator/measurement.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,8 @@ struct Measurement {

} // namespace spectator

template <>
struct fmt::formatter<spectator::Measurement> {
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
template <> struct fmt::formatter<spectator::Measurement>: formatter<std::string_view> {
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 <typename FormatContext>
auto format(const spectator::Measurement& m, FormatContext& context) {
return fmt::format_to(context.out(), "Measurement({}, {})", *(m.id),
m.value);
}
};
};

0 comments on commit 5761837

Please sign in to comment.