Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions include/Semver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <cstddef>
#include <cstdint>
#include <fmt/ostream.h>
#include <format>
#include <ostream>
#include <rs/result.hpp>
#include <string>
Expand Down Expand Up @@ -86,8 +86,6 @@ bool operator<(const Version& lhs, const Version& rhs) noexcept;
bool operator>(const Version& lhs, const Version& rhs) noexcept;
bool operator<=(const Version& lhs, const Version& rhs) noexcept;
bool operator>=(const Version& lhs, const Version& rhs) noexcept;
template <>
struct fmt::formatter<Version> : ostream_formatter {};

struct VersionLexer {
std::string_view s;
Expand Down Expand Up @@ -120,3 +118,24 @@ struct VersionParser {
rs::Result<BuildMetadata> parseBuild() noexcept;
rs::Result<VersionToken> parseIdent() noexcept;
};

namespace std {

template <>
struct formatter<Version> {
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }

template <class FormatContext>
auto format(const Version& ver, FormatContext& ctx) const {
return formatter<std::string_view>{}.format(ver.toString(), ctx);
}
};

} // namespace std

#if __has_include(<fmt/ostream.h>)
# include <fmt/ostream.h>

template <>
struct fmt::formatter<Version> : ostream_formatter {};
#endif
Loading