mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-12 22:20:05 +00:00
fix ambiguous formatter lookup for flat_set (#3561)
This commit is contained in:
parent
eacd51c249
commit
8a4bec5cf5
@ -668,8 +668,11 @@ template <typename Container> struct all {
|
||||
} // namespace detail
|
||||
|
||||
template <typename T, typename Char>
|
||||
struct formatter<T, Char,
|
||||
enable_if_t<detail::is_container_adaptor_like<T>::value>>
|
||||
struct formatter<
|
||||
T, Char,
|
||||
enable_if_t<conjunction<detail::is_container_adaptor_like<T>,
|
||||
bool_constant<range_format_kind<T, Char>::value ==
|
||||
range_format::disabled>>::value>>
|
||||
: formatter<detail::all<typename T::container_type>, Char> {
|
||||
using all = detail::all<typename T::container_type>;
|
||||
template <typename FormatContext>
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
@ -80,6 +81,35 @@ TEST(ranges_test, format_set) {
|
||||
"{\"one\", \"two\"}");
|
||||
}
|
||||
|
||||
// Models std::flat_set close enough to test if no ambiguous lookup of a
|
||||
// formatter happens due to the flat_set type matching is_set and
|
||||
// is_container_adaptor_like
|
||||
template <typename T> class flat_set {
|
||||
public:
|
||||
using key_type = T;
|
||||
using container_type = std::vector<T>;
|
||||
|
||||
using iterator = typename std::vector<T>::iterator;
|
||||
using const_iterator = typename std::vector<T>::const_iterator;
|
||||
|
||||
template <typename... Ts>
|
||||
explicit flat_set(Ts&&... args) : c{std::forward<Ts>(args)...} {}
|
||||
|
||||
iterator begin() { return c.begin(); }
|
||||
const_iterator begin() const { return c.begin(); }
|
||||
|
||||
iterator end() { return c.end(); }
|
||||
const_iterator end() const { return c.end(); }
|
||||
|
||||
private:
|
||||
std::vector<T> c;
|
||||
};
|
||||
|
||||
TEST(ranges_test, format_flat_set) {
|
||||
EXPECT_EQ(fmt::format("{}", flat_set<std::string>{"one", "two"}),
|
||||
"{\"one\", \"two\"}");
|
||||
}
|
||||
|
||||
namespace adl {
|
||||
struct box {
|
||||
int value;
|
||||
|
Loading…
Reference in New Issue
Block a user