From fb8d3a8fba1167adc34cd4a9f1b4194b7ada1dc8 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Wed, 21 May 2025 12:18:18 -0400 Subject: [PATCH] c++20 standard --- CMakeLists.txt | 2 +- spectator/id.h | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86063cd..7ae3e8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.23) project(spectator-cpp) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) diff --git a/spectator/id.h b/spectator/id.h index 0087e42..e766874 100644 --- a/spectator/id.h +++ b/spectator/id.h @@ -74,11 +74,6 @@ class Tags { [[nodiscard]] table_t::const_iterator end() const { return entries_.end(); } }; -inline std::ostream& operator<<(std::ostream& os, const Tags& tags) { - os << fmt::format("{}", tags); - return os; -} - class Id { public: Id(absl::string_view name, Tags tags) noexcept @@ -131,11 +126,6 @@ class Id { } } - friend std::ostream& operator<<(std::ostream& os, const Id& id) { - os << fmt::format("{}", id); - return os; - } - friend struct std::hash; friend struct std::hash>; @@ -186,7 +176,7 @@ struct equal_to> { } // namespace std -template <> struct fmt::formatter: formatter { +template <> struct fmt::formatter: fmt::formatter { auto format(const spectator::Tags& tags, format_context& ctx) const -> format_context::iterator { std::string s; auto size = tags.size(); @@ -216,8 +206,18 @@ template <> struct fmt::formatter: formatter } }; -template <> struct fmt::formatter: formatter { +inline auto operator<<(std::ostream& os, const spectator::Tags& tags) -> std::ostream& { + os << fmt::format("{}", tags); + return os; +} + +template <> struct fmt::formatter: fmt::formatter { 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()); } }; + +inline auto operator<<(std::ostream& os, const spectator::Id& id) -> std::ostream& { + os << fmt::format("{}", id); + return os; +}