From ce8c17f6610ba93b520178c412d0f1e7a0b087ad Mon Sep 17 00:00:00 2001
From: Fabian Kosmale <fabian.kosmale@qt.io>
Date: Thu, 12 Mar 2020 16:25:31 +0100
Subject: [PATCH] WIP: QSequentialIterable: Treat sets as appendable

TODO refine SFINAE check a bit

Task-number: QTBUG-82743
Change-Id: I74fc7b1b856d9bcd38100b274ba2b69578ea8bbb
---

diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index 59ec8de..6b5f8aa 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -1014,6 +1014,17 @@
     { static_cast<Container *>(const_cast<void *>(container))->push_back(*static_cast<const typename Container::value_type *>(value)); }
 };
 
+template<typename Container>
+struct ContainerCapabilitiesImpl<Container, decltype(void(std::declval<Container>().insert(std::declval<typename Container::value_type>())), void(0))>
+{
+    enum {ContainerCapabilities = ContainerIsAppendable};
+
+    // The code below invokes undefined behavior if and only if the pointer passed into QSequentialIterableImpl
+    // pointed to a const object to begin with
+    static void appendImpl(const void *container, const void *value)
+    { static_cast<Container *>(const_cast<void *>(container))->insert(*static_cast<const typename Container::value_type *>(value)); }
+};
+
 template<typename T, typename Category = typename std::iterator_traits<typename T::const_iterator>::iterator_category>
 struct CapabilitiesImpl;
 
