Disable fallback_formatter for arrays

This commit is contained in:
Victor Zverovich 2021-09-03 08:35:13 -07:00
parent d58d19ba32
commit 20931baf1d
2 changed files with 10 additions and 2 deletions

View File

@ -70,8 +70,7 @@ void_t<> operator<<(std::basic_ostream<char, Traits>&, signed char);
template <typename Traits>
void_t<> operator<<(std::basic_ostream<char, Traits>&, unsigned char);
// Checks if T has a user-defined operator<< (e.g. not a member of
// std::ostream).
// Checks if T has a user-defined operator<< e.g. not a member of std::ostream.
template <typename T, typename Char> class is_streamable {
private:
template <typename U>
@ -90,6 +89,11 @@ template <typename T, typename Char> class is_streamable {
static const bool value = result::value;
};
// Formatting of arrays is intentionally disabled to prevent conflicts with
// standard (non-ostream) formatters.
template <typename T, size_t N, typename Char>
struct is_streamable<T[N], Char> : std::false_type {};
// Write the content of buf to os.
template <typename Char>
void write_buffer(std::basic_ostream<Char>& os, buffer<Char>& buf) {

View File

@ -1,7 +1,11 @@
// Header-only configuration test
#include "fmt/core.h"
#include "fmt/ostream.h"
#include "gtest/gtest.h"
#ifndef FMT_HEADER_ONLY
# error "Not in the header-only mode."
#endif
TEST(header_only_test, format) { EXPECT_EQ(fmt::format("foo"), "foo"); }