Skip to content

Commit

Permalink
Fix constness of the formatter's parse function.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Dec 12, 2023
1 parent 8c120b4 commit 288eeb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/mp++/detail/fmt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct to_string_formatter {
}

template <typename T, typename FormatContext>
auto format(const T &x, FormatContext &ctx) -> decltype(ctx.out())
auto format(const T &x, FormatContext &ctx) const -> decltype(ctx.out())
{
return fmt::format_to(ctx.out(), "{}", x.to_string());
}
Expand Down
5 changes: 5 additions & 0 deletions test/real_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#include <string>
#include <tuple>
#include <type_traits>
#include <vector>

#if defined(MPPP_WITH_FMT)

#include <fmt/core.h>
#include <fmt/ranges.h>

#endif

Expand Down Expand Up @@ -467,6 +469,9 @@ TEST_CASE("fmt test")
// Check that the format string is ignored.
REQUIRE(fmt::format("foo {:<30} bar", -1.1_r512) == "foo " + (-1.1_r512).to_string() + " bar");
REQUIRE(fmt::format("foo {:} bar", -1.1_r512) == "foo " + (-1.1_r512).to_string() + " bar");

// Check range printing.
REQUIRE_NOTHROW(fmt::format("{}", std::vector{-1.1_r512, -1.2_r512}));
}

#endif

0 comments on commit 288eeb4

Please sign in to comment.