mirror of
https://github.com/shadps4-emu/ext-fmt.git
synced 2024-11-23 09:49:42 +00:00
Disable to_string_view ADL
This commit is contained in:
parent
466e0650ec
commit
02bf4d1c1c
@ -546,10 +546,10 @@ void to_string_view(...);
|
||||
// Specifies whether S is a string type convertible to fmt::basic_string_view.
|
||||
// It should be a constexpr function but MSVC 2017 fails to compile it in
|
||||
// enable_if and MSVC 2015 fails to compile it as an alias template.
|
||||
// ADL invocation of to_string_view is DEPRECATED!
|
||||
// ADL is intentionally disabled as to_string_view is not an extension point.
|
||||
template <typename S>
|
||||
struct is_string : std::is_class<decltype(to_string_view(std::declval<S>()))> {
|
||||
};
|
||||
struct is_string
|
||||
: std::is_class<decltype(detail::to_string_view(std::declval<S>()))> {};
|
||||
|
||||
template <typename S, typename = void> struct char_t_impl {};
|
||||
template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
|
||||
|
@ -88,25 +88,6 @@ TEST(string_view_test, compare) {
|
||||
check_op<std::greater_equal>();
|
||||
}
|
||||
|
||||
namespace test_ns {
|
||||
template <typename Char> class test_string {
|
||||
private:
|
||||
std::basic_string<Char> s_;
|
||||
|
||||
public:
|
||||
test_string(const Char* s) : s_(s) {}
|
||||
auto data() const -> const Char* { return s_.data(); }
|
||||
auto length() const -> size_t { return s_.size(); }
|
||||
operator const Char*() const { return s_.c_str(); }
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
auto to_string_view(const test_string<Char>& s)
|
||||
-> fmt::basic_string_view<Char> {
|
||||
return {s.data(), s.length()};
|
||||
}
|
||||
} // namespace test_ns
|
||||
|
||||
TEST(core_test, is_output_iterator) {
|
||||
EXPECT_TRUE((fmt::detail::is_output_iterator<char*, char>::value));
|
||||
EXPECT_FALSE((fmt::detail::is_output_iterator<const char*, char>::value));
|
||||
@ -769,15 +750,6 @@ TEST(core_test, adl_check) {
|
||||
EXPECT_EQ(fmt::format("{}", test_struct()), "test");
|
||||
}
|
||||
|
||||
TEST(core_test, to_string_view_foreign_strings) {
|
||||
using namespace test_ns;
|
||||
EXPECT_EQ(to_string_view(test_string<char>("42")), "42");
|
||||
fmt::detail::type type =
|
||||
fmt::detail::mapped_type_constant<test_string<char>,
|
||||
fmt::format_context>::value;
|
||||
EXPECT_EQ(type, fmt::detail::type::string_type);
|
||||
}
|
||||
|
||||
struct implicitly_convertible_to_string_view {
|
||||
operator fmt::string_view() const { return "foo"; }
|
||||
};
|
||||
|
@ -1866,9 +1866,6 @@ TEST(format_test, unpacked_args) {
|
||||
6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f', 'g'));
|
||||
}
|
||||
|
||||
struct string_like {};
|
||||
fmt::string_view to_string_view(string_like) { return "foo"; }
|
||||
|
||||
constexpr char with_null[3] = {'{', '}', '\0'};
|
||||
constexpr char no_null[2] = {'{', '}'};
|
||||
static constexpr const char static_with_null[3] = {'{', '}', '\0'};
|
||||
@ -1877,7 +1874,6 @@ static constexpr const char static_no_null[2] = {'{', '}'};
|
||||
TEST(format_test, compile_time_string) {
|
||||
EXPECT_EQ("foo", fmt::format(FMT_STRING("foo")));
|
||||
EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), 42));
|
||||
EXPECT_EQ("foo", fmt::format(FMT_STRING("{}"), string_like()));
|
||||
|
||||
#if FMT_USE_NONTYPE_TEMPLATE_ARGS
|
||||
using namespace fmt::literals;
|
||||
|
@ -30,25 +30,7 @@ using testing::Contains;
|
||||
# define FMT_HAS_C99_STRFTIME 1
|
||||
#endif
|
||||
|
||||
namespace test_ns {
|
||||
template <typename Char> class test_string {
|
||||
private:
|
||||
std::basic_string<Char> s_;
|
||||
|
||||
public:
|
||||
test_string(const Char* s) : s_(s) {}
|
||||
const Char* data() const { return s_.data(); }
|
||||
size_t length() const { return s_.size(); }
|
||||
operator const Char*() const { return s_.c_str(); }
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
fmt::basic_string_view<Char> to_string_view(const test_string<Char>& s) {
|
||||
return {s.data(), s.length()};
|
||||
}
|
||||
|
||||
struct non_string {};
|
||||
} // namespace test_ns
|
||||
|
||||
template <typename T> class is_string_test : public testing::Test {};
|
||||
|
||||
@ -70,8 +52,7 @@ TYPED_TEST(is_string_test, is_string) {
|
||||
using fmt_string_view = fmt::detail::std_string_view<TypeParam>;
|
||||
EXPECT_TRUE(std::is_empty<fmt_string_view>::value !=
|
||||
fmt::detail::is_string<fmt_string_view>::value);
|
||||
EXPECT_TRUE(fmt::detail::is_string<test_ns::test_string<TypeParam>>::value);
|
||||
EXPECT_FALSE(fmt::detail::is_string<test_ns::non_string>::value);
|
||||
EXPECT_FALSE(fmt::detail::is_string<non_string>::value);
|
||||
}
|
||||
|
||||
// std::is_constructible is broken in MSVC until version 2015.
|
||||
|
Loading…
Reference in New Issue
Block a user