Skip to content

Commit

Permalink
Remove formatter for std::optional
Browse files Browse the repository at this point in the history
fmt now ships its own.
  • Loading branch information
frankosterfeld committed Apr 25, 2024
1 parent 77a8245 commit 1355889
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/core/include/URI.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#ifndef OPENCMW_CPP_URI_HPP
#define OPENCMW_CPP_URI_HPP
#include <algorithm>
#include <fmt/format.h>
#include <iomanip>
#include <ios>
#include <optional>
#include <sstream>
#include <string>
#include <string_view>
#include <unordered_map>

#include <cassert>

#include <fmt/format.h>
#include <fmt/std.h>

namespace opencmw {

struct URISyntaxException : public std::ios_base::failure {
Expand Down Expand Up @@ -476,25 +477,6 @@ struct std::hash<opencmw::URI<check>> {

// fmt::format and std::ostream helper output

// fmt::format and std::ostream helper output for std::optional
template<typename T> // TODO: move to utils class
struct fmt::formatter<std::optional<T>> {
template<typename ParseContext>
constexpr auto parse(ParseContext &ctx) {
return ctx.begin(); // not (yet) implemented
}

template<typename FormatContext>
auto format(std::optional<T> const &v, FormatContext &ctx) const {
return v ? fmt::format_to(ctx.out(), "'{}'", v.value()) : fmt::format_to(ctx.out(), "{{}}");
}
};

template<typename T>
inline std::ostream &operator<<(std::ostream &os, const std::optional<T> &v) {
return os << fmt::format("{}", v);
}

template<opencmw::uri_check check>
struct fmt::formatter<opencmw::URI<check>> {
template<typename ParseContext>
Expand Down

0 comments on commit 1355889

Please sign in to comment.