[libcxx-commits] [libcxx] [libc++][ranges] LWG4016: container-insertable checks do not match what container-inserter does (PR #113103)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 21 13:16:28 PDT 2024


================
@@ -54,19 +52,26 @@ constexpr bool __reservable_container =
     };
 
 template <class _Container, class _Ref>
-constexpr bool __container_insertable = requires(_Container& __c, _Ref&& __ref) {
+constexpr bool __container_appendable = requires(_Container& __c, _Ref&& __ref) {
   requires(
+      requires { __c.emplace_back(std::forward<_Ref>(__ref)); } ||
       requires { __c.push_back(std::forward<_Ref>(__ref)); } ||
+      requires { __c.emplace(__c.end(), std::forward<_Ref>(__ref)); } ||
       requires { __c.insert(__c.end(), std::forward<_Ref>(__ref)); });
 };
 
-template <class _Ref, class _Container>
-_LIBCPP_HIDE_FROM_ABI constexpr auto __container_inserter(_Container& __c) {
-  if constexpr (requires { __c.push_back(std::declval<_Ref>()); }) {
-    return std::back_inserter(__c);
-  } else {
-    return std::inserter(__c, __c.end());
-  }
+template <class _Container>
+_LIBCPP_HIDE_FROM_ABI constexpr auto __container_append(_Container& __c) {
+  return [&__c]<class _Ref>(_Ref&& __ref) {
+    if constexpr (requires { __c.emplace_back(declval<_Ref>()); })
+      __c.emplace_back(std::forward<_Ref>(__ref));
+    else if constexpr (requires { __c.push_back(declval<_Ref>()); })
+      __c.push_back(std::forward<_Ref>(__ref));
+    else if constexpr (requires { __c.emplace(__c.end(), declval<_Ref>()); })
+      __c.emplace(__c.end(), std::forward<_Ref>(__ref));
+    else if constexpr (requires { __c.insert(__c.end(), declval<_Ref>()); })
----------------
ldionne wrote:

^ This might indeed be easier to read.

https://github.com/llvm/llvm-project/pull/113103


More information about the libcxx-commits mailing list