[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
This commit is contained in:
Mark de Wever 2021-09-27 20:53:59 +02:00
parent 7277b00a29
commit 476047bf8e
2 changed files with 39 additions and 0 deletions

View File

@ -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 <class _Container>

View File

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