[libcxx-commits] [libcxx] 476047b - [libc++] Adds back_insert_iterator::__get_container.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Apr 8 08:13:56 PDT 2022
Author: Mark de Wever
Date: 2022-04-08T17:13:50+02:00
New Revision: 476047bf8e720f3dc359cf75d1241e13f8ba2350
URL: https://github.com/llvm/llvm-project/commit/476047bf8e720f3dc359cf75d1241e13f8ba2350
DIFF: https://github.com/llvm/llvm-project/commit/476047bf8e720f3dc359cf75d1241e13f8ba2350.diff
LOG: [libc++] Adds back_insert_iterator::__get_container.
Adds a `__get_container` member as suggested by @Quuxplusone in D110497.
Includes s/_LIBCPP_INLINE_VISIBILITY/_LIBCPP_HIDE_FROM_ABI/.
Reviewed By: Quuxplusone, #libc, ldionne
Differential Revision: https://reviews.llvm.org/D110573
Added:
libcxx/test/libcxx/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/get_container.pass.cpp
Modified:
libcxx/include/__iterator/back_insert_iterator.h
Removed:
################################################################################
diff --git a/libcxx/include/__iterator/back_insert_iterator.h b/libcxx/include/__iterator/back_insert_iterator.h
index 9a4b05703b3c3..7bbf5b09e0e54 100644
--- a/libcxx/include/__iterator/back_insert_iterator.h
+++ b/libcxx/include/__iterator/back_insert_iterator.h
@@ -55,6 +55,8 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _Container* __get_container() const { return container; }
};
template <class _Container>
diff --git a/libcxx/test/libcxx/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/get_container.pass.cpp b/libcxx/test/libcxx/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/get_container.pass.cpp
new file mode 100644
index 0000000000000..9f45848e9d3ff
--- /dev/null
+++ b/libcxx/test/libcxx/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/get_container.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <iterator>
+
+// back_insert_iterator
+
+// _Container* __get_container(); // constexpr in C++20
+
+#include <iterator>
+#include <vector>
+
+#include "test_macros.h"
+#include "nasty_containers.h"
+#include "test_constexpr_container.h"
+
+template <class C>
+TEST_CONSTEXPR_CXX20 bool test(C c) {
+ const std::back_insert_iterator<C> i(c);
+ assert(i.__get_container() == std::addressof(c));
+ return true;
+}
+
+int main(int, char**) {
+ test(std::vector<int>());
+ test(nasty_vector<int>());
+#if TEST_STD_VER >= 20
+ test(ConstexprFixedCapacityDeque<int, 10>());
+ static_assert(test(ConstexprFixedCapacityDeque<int, 10>()));
+#endif
+ return 0;
+}
More information about the libcxx-commits
mailing list