Skip to content

Commit

Permalink
Add specialization test
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Apr 20, 2019
1 parent 946498c commit 5efb24d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ struct fallback_formatter<

// Disable conversion to int if T has an overloaded operator<< which is a free
// function (not a member of std::ostream).
template <typename T, typename Char> struct convert_to_int<T, Char, void> {
static const bool value = convert_to_int<T, Char, int>::value &&
!internal::is_streamable<T, Char>::value;
template <typename T, typename Char>
struct convert_to_int<
T, Char,
typename std::enable_if<internal::is_streamable<T, Char>::value>::type> {
static const bool value = false;
};

template <typename Char>
Expand Down
15 changes: 15 additions & 0 deletions test/ostream-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
// For the license information refer to format.h.

#define FMT_STRING_ALIAS 1
#include "fmt/format.h"

struct test {};

// Test that there is no issues with specializations when fmt/ostream.h is
// included after fmt/format.h.
namespace fmt {
template <> struct formatter<test> : formatter<int> {
template <typename FormatContext>
typename FormatContext::iterator format(const test&, FormatContext& ctx) {
return formatter<int>::format(42, ctx);
}
};
} // namespace fmt

#include "fmt/ostream.h"

#include <sstream>
Expand Down

0 comments on commit 5efb24d

Please sign in to comment.