mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-29 05:11:05 +00:00
Move has_formatter into the public fmt namespace. (#1407)
* Move has_formatter into the public fmt namespace. This will allow users to do SFINAE-friendly checks for the formattability of a type. Fixes #1369
This commit is contained in:
parent
52ae134f84
commit
2145a7bdcc
@ -542,14 +542,14 @@ struct FMT_DEPRECATED convert_to_int
|
|||||||
: bool_constant<!std::is_arithmetic<T>::value &&
|
: bool_constant<!std::is_arithmetic<T>::value &&
|
||||||
std::is_convertible<T, int>::value> {};
|
std::is_convertible<T, int>::value> {};
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
// Specifies if T has an enabled formatter specialization. A type can be
|
// Specifies if T has an enabled formatter specialization. A type can be
|
||||||
// formattable even if it doesn't have a formatter e.g. via a conversion.
|
// formattable even if it doesn't have a formatter e.g. via a conversion.
|
||||||
template <typename T, typename Context>
|
template <typename T, typename Context>
|
||||||
using has_formatter =
|
using has_formatter =
|
||||||
std::is_constructible<typename Context::template formatter_type<T>>;
|
std::is_constructible<typename Context::template formatter_type<T>>;
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
/** A contiguous memory buffer with an optional growing ability. */
|
/** A contiguous memory buffer with an optional growing ability. */
|
||||||
template <typename T> class buffer {
|
template <typename T> class buffer {
|
||||||
private:
|
private:
|
||||||
|
@ -453,11 +453,11 @@ template <> struct formatter<enabled_formatter> {
|
|||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
|
||||||
TEST(CoreTest, HasFormatter) {
|
TEST(CoreTest, HasFormatter) {
|
||||||
using fmt::internal::has_formatter;
|
using fmt::has_formatter;
|
||||||
using context = fmt::format_context;
|
using context = fmt::format_context;
|
||||||
EXPECT_TRUE((has_formatter<enabled_formatter, context>::value));
|
static_assert(has_formatter<enabled_formatter, context>::value, "");
|
||||||
EXPECT_FALSE((has_formatter<disabled_formatter, context>::value));
|
static_assert(!has_formatter<disabled_formatter, context>::value, "");
|
||||||
EXPECT_FALSE((has_formatter<disabled_formatter_convertible, context>::value));
|
static_assert(!has_formatter<disabled_formatter_convertible, context>::value, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct convertible_to_int {
|
struct convertible_to_int {
|
||||||
|
@ -1974,8 +1974,8 @@ enum TestEnum { A };
|
|||||||
TEST(FormatTest, Enum) { EXPECT_EQ("0", fmt::format("{}", A)); }
|
TEST(FormatTest, Enum) { EXPECT_EQ("0", fmt::format("{}", A)); }
|
||||||
|
|
||||||
TEST(FormatTest, FormatterNotSpecialized) {
|
TEST(FormatTest, FormatterNotSpecialized) {
|
||||||
EXPECT_FALSE((fmt::internal::has_formatter<fmt::formatter<TestEnum>,
|
static_assert(!fmt::has_formatter<fmt::formatter<TestEnum>,
|
||||||
fmt::format_context>::value));
|
fmt::format_context>::value, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FMT_HAS_FEATURE(cxx_strong_enums)
|
#if FMT_HAS_FEATURE(cxx_strong_enums)
|
||||||
|
Loading…
Reference in New Issue
Block a user