mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-29 18:27:40 +02:00
Fix ambiguity for types with dodgy conversions
This commit is contained in:
@ -246,7 +246,8 @@ template <typename T, typename Char> struct is_range {
|
|||||||
static FMT_CONSTEXPR_DECL const bool value =
|
static FMT_CONSTEXPR_DECL const bool value =
|
||||||
internal::is_range_<T>::value &&
|
internal::is_range_<T>::value &&
|
||||||
!internal::is_like_std_string<T>::value &&
|
!internal::is_like_std_string<T>::value &&
|
||||||
!std::is_convertible<T, std::basic_string<Char>>::value;
|
!std::is_convertible<T, std::basic_string<Char>>::value &&
|
||||||
|
!std::is_constructible<internal::std_string_view<Char>, T>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename RangeT, typename Char>
|
template <typename RangeT, typename Char>
|
||||||
|
@ -9,13 +9,13 @@
|
|||||||
// All Rights Reserved
|
// All Rights Reserved
|
||||||
// {fmt} support for ranges, containers and types tuple interface.
|
// {fmt} support for ranges, containers and types tuple interface.
|
||||||
|
|
||||||
/// Check if 'if constexpr' is supported.
|
#include "fmt/ranges.h"
|
||||||
|
#include "gtest.h"
|
||||||
|
|
||||||
|
// Check if 'if constexpr' is supported.
|
||||||
#if (__cplusplus > 201402L) || \
|
#if (__cplusplus > 201402L) || \
|
||||||
(defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
|
(defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
|
||||||
|
|
||||||
# include "fmt/ranges.h"
|
|
||||||
# include "gtest.h"
|
|
||||||
|
|
||||||
# include <array>
|
# include <array>
|
||||||
# include <map>
|
# include <map>
|
||||||
# include <string>
|
# include <string>
|
||||||
@ -119,3 +119,16 @@ TEST(RangesTest, PathLike) {
|
|||||||
|
|
||||||
#endif // (__cplusplus > 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >
|
#endif // (__cplusplus > 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >
|
||||||
// 201402L && _MSC_VER >= 1910)
|
// 201402L && _MSC_VER >= 1910)
|
||||||
|
|
||||||
|
#ifdef FMT_USE_STRING_VIEW
|
||||||
|
struct string_like {
|
||||||
|
const char* begin();
|
||||||
|
const char* end();
|
||||||
|
explicit operator fmt::string_view() const { return "foo"; }
|
||||||
|
explicit operator std::string_view() const { return "foo"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(RangesTest, FormatStringLike) {
|
||||||
|
EXPECT_EQ("foo", fmt::format("{}", string_like()));
|
||||||
|
}
|
||||||
|
#endif // FMT_USE_STRING_VIEW
|
||||||
|
Reference in New Issue
Block a user