From 476047bf8e720f3dc359cf75d1241e13f8ba2350 Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Mon, 27 Sep 2021 20:53:59 +0200 Subject: [PATCH] [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 --- libcxx/include/__iterator/back_insert_iterator.h | 2 ++ .../back.insert.iter.ops/get_container.pass.cpp | 37 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 libcxx/test/libcxx/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/get_container.pass.cpp diff --git a/libcxx/include/__iterator/back_insert_iterator.h b/libcxx/include/__iterator/back_insert_iterator.h index 9a4b057..7bbf5b09 100644 --- a/libcxx/include/__iterator/back_insert_iterator.h +++ b/libcxx/include/__iterator/back_insert_iterator.h @@ -55,6 +55,8 @@ public: _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 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 0000000..9f45848 --- /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 +// +//===----------------------------------------------------------------------===// + +// + +// back_insert_iterator + +// _Container* __get_container(); // constexpr in C++20 + +#include +#include + +#include "test_macros.h" +#include "nasty_containers.h" +#include "test_constexpr_container.h" + +template +TEST_CONSTEXPR_CXX20 bool test(C c) { + const std::back_insert_iterator i(c); + assert(i.__get_container() == std::addressof(c)); + return true; +} + +int main(int, char**) { + test(std::vector()); + test(nasty_vector()); +#if TEST_STD_VER >= 20 + test(ConstexprFixedCapacityDeque()); + static_assert(test(ConstexprFixedCapacityDeque())); +#endif + return 0; +} -- 2.7.4