forked from fmtlib/fmt
fix ambiguous formatter lookup for flat_set (#3561)
This commit is contained in:
@ -668,8 +668,11 @@ template <typename Container> struct all {
|
|||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T, typename Char>
|
template <typename T, typename Char>
|
||||||
struct formatter<T, Char,
|
struct formatter<
|
||||||
enable_if_t<detail::is_container_adaptor_like<T>::value>>
|
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> {
|
: formatter<detail::all<typename T::container_type>, Char> {
|
||||||
using all = detail::all<typename T::container_type>;
|
using all = detail::all<typename T::container_type>;
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
@ -80,6 +81,35 @@ TEST(ranges_test, format_set) {
|
|||||||
"{\"one\", \"two\"}");
|
"{\"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 {
|
namespace adl {
|
||||||
struct box {
|
struct box {
|
||||||
int value;
|
int value;
|
||||||
|
Reference in New Issue
Block a user