mirror of
https://github.com/fmtlib/fmt.git
synced 2025-04-15 20:42:27 +00:00
Don't convert scoped enums to integers
This commit is contained in:
parent
c652f8243a
commit
fd62fba985
@ -8,6 +8,7 @@
|
|||||||
#ifndef FMT_CORE_H_
|
#ifndef FMT_CORE_H_
|
||||||
#define FMT_CORE_H_
|
#define FMT_CORE_H_
|
||||||
|
|
||||||
|
#include <cstddef> // std::byte
|
||||||
#include <cstdio> // std::FILE
|
#include <cstdio> // std::FILE
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
@ -367,6 +368,12 @@ FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cpp_lib_byte
|
||||||
|
using byte = std::byte;
|
||||||
|
#else
|
||||||
|
enum class byte : unsigned char {};
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(FMT_USE_STRING_VIEW)
|
#if defined(FMT_USE_STRING_VIEW)
|
||||||
template <typename Char> using std_string_view = std::basic_string_view<Char>;
|
template <typename Char> using std_string_view = std::basic_string_view<Char>;
|
||||||
#elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW)
|
#elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW)
|
||||||
@ -1403,6 +1410,9 @@ template <typename Context> struct arg_mapper {
|
|||||||
|
|
||||||
template <typename T,
|
template <typename T,
|
||||||
FMT_ENABLE_IF(std::is_enum<T>::value &&
|
FMT_ENABLE_IF(std::is_enum<T>::value &&
|
||||||
|
(std::is_convertible<T, int>::value
|
||||||
|
|| std::is_same<T, detail::byte>::value
|
||||||
|
) &&
|
||||||
!has_formatter<T, Context>::value &&
|
!has_formatter<T, Context>::value &&
|
||||||
!has_fallback_formatter<T, char_type>::value)>
|
!has_fallback_formatter<T, char_type>::value)>
|
||||||
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
|
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
|
||||||
|
@ -2606,6 +2606,7 @@ FMT_FORMAT_AS(unsigned long, unsigned long long);
|
|||||||
FMT_FORMAT_AS(Char*, const Char*);
|
FMT_FORMAT_AS(Char*, const Char*);
|
||||||
FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>);
|
FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>);
|
||||||
FMT_FORMAT_AS(std::nullptr_t, const void*);
|
FMT_FORMAT_AS(std::nullptr_t, const void*);
|
||||||
|
FMT_FORMAT_AS(detail::byte, unsigned char);
|
||||||
FMT_FORMAT_AS(detail::std_string_view<Char>, basic_string_view<Char>);
|
FMT_FORMAT_AS(detail::std_string_view<Char>, basic_string_view<Char>);
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
|
@ -737,6 +737,8 @@ struct convertible_to_pointer {
|
|||||||
operator const int*() const { return nullptr; }
|
operator const int*() const { return nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class test_scoped_enum {};
|
||||||
|
|
||||||
TEST(core_test, is_formattable) {
|
TEST(core_test, is_formattable) {
|
||||||
static_assert(fmt::is_formattable<signed char*>::value, "");
|
static_assert(fmt::is_formattable<signed char*>::value, "");
|
||||||
static_assert(fmt::is_formattable<unsigned char*>::value, "");
|
static_assert(fmt::is_formattable<unsigned char*>::value, "");
|
||||||
@ -777,6 +779,7 @@ TEST(core_test, is_formattable) {
|
|||||||
|
|
||||||
static_assert(!fmt::is_formattable<int(s::*)>::value, "");
|
static_assert(!fmt::is_formattable<int(s::*)>::value, "");
|
||||||
static_assert(!fmt::is_formattable<int (s::*)()>::value, "");
|
static_assert(!fmt::is_formattable<int (s::*)()>::value, "");
|
||||||
|
static_assert(!fmt::is_formattable<test_scoped_enum>::value, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(core_test, format) { EXPECT_EQ(fmt::format("{}", 42), "42"); }
|
TEST(core_test, format) { EXPECT_EQ(fmt::format("{}", 42), "42"); }
|
||||||
|
@ -190,7 +190,7 @@ TEST(ranges_test, range) {
|
|||||||
EXPECT_EQ(fmt::format("{}", z), "[0, 0, 0]");
|
EXPECT_EQ(fmt::format("{}", z), "[0, 0, 0]");
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class test_enum { foo };
|
enum test_enum { foo };
|
||||||
|
|
||||||
TEST(ranges_test, enum_range) {
|
TEST(ranges_test, enum_range) {
|
||||||
auto v = std::vector<test_enum>{test_enum::foo};
|
auto v = std::vector<test_enum>{test_enum::foo};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user