fix ambiguous formatter lookup for flat_set (#3561)

This commit is contained in:
5chmidti
2023-07-31 18:26:33 +02:00
committed by GitHub
parent eacd51c249
commit 8a4bec5cf5
2 changed files with 35 additions and 2 deletions

View File

@@ -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;