2021-06-11 13:55:11 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP___ITERATOR_INSERT_ITERATOR_H
|
|
|
|
#define _LIBCPP___ITERATOR_INSERT_ITERATOR_H
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <__iterator/iterator.h>
|
2021-06-29 02:32:59 +00:00
|
|
|
#include <__iterator/iterator_traits.h>
|
2021-06-11 13:55:11 +00:00
|
|
|
#include <__memory/addressof.h>
|
2021-08-26 14:55:18 +00:00
|
|
|
#include <__ranges/access.h>
|
2021-06-29 02:32:59 +00:00
|
|
|
#include <__utility/move.h>
|
2021-06-11 13:55:11 +00:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 01:16:40 +00:00
|
|
|
# pragma GCC system_header
|
2021-06-11 13:55:11 +00:00
|
|
|
#endif
|
|
|
|
|
2023-07-06 17:12:05 +00:00
|
|
|
_LIBCPP_PUSH_MACROS
|
|
|
|
#include <__undef_macros>
|
|
|
|
|
2021-06-11 13:55:11 +00:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2023-02-13 23:56:09 +00:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
2021-08-26 14:55:18 +00:00
|
|
|
template <class _Container>
|
|
|
|
using __insert_iterator_iter_t = ranges::iterator_t<_Container>;
|
|
|
|
#else
|
|
|
|
template <class _Container>
|
|
|
|
using __insert_iterator_iter_t = typename _Container::iterator;
|
|
|
|
#endif
|
|
|
|
|
2021-06-11 13:55:11 +00:00
|
|
|
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
|
|
|
|
template <class _Container>
|
|
|
|
class _LIBCPP_TEMPLATE_VIS insert_iterator
|
|
|
|
#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
|
|
|
|
: public iterator<output_iterator_tag, void, void, void, void>
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
_LIBCPP_SUPPRESS_DEPRECATED_POP
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2021-06-11 13:55:11 +00:00
|
|
|
protected:
|
|
|
|
_Container* container;
|
2021-08-26 14:55:18 +00:00
|
|
|
__insert_iterator_iter_t<_Container> iter;
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2021-06-11 13:55:11 +00:00
|
|
|
public:
|
|
|
|
typedef output_iterator_tag iterator_category;
|
|
|
|
typedef void value_type;
|
2023-02-13 23:56:09 +00:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
2021-06-11 13:55:11 +00:00
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
#else
|
|
|
|
typedef void difference_type;
|
|
|
|
#endif
|
|
|
|
typedef void pointer;
|
|
|
|
typedef void reference;
|
|
|
|
typedef _Container container_type;
|
|
|
|
|
2022-08-19 11:08:01 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
|
|
|
|
insert_iterator(_Container& __x, __insert_iterator_iter_t<_Container> __i)
|
2021-06-11 13:55:11 +00:00
|
|
|
: container(std::addressof(__x)), iter(__i) {}
|
2022-08-19 11:08:01 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator&
|
|
|
|
operator=(const typename _Container::value_type& __value) {
|
2022-07-08 16:17:26 +00:00
|
|
|
iter = container->insert(iter, __value);
|
|
|
|
++iter;
|
|
|
|
return *this;
|
|
|
|
}
|
2021-06-11 13:55:11 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2022-08-19 11:08:01 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator&
|
|
|
|
operator=(typename _Container::value_type&& __value) {
|
2022-07-08 16:17:26 +00:00
|
|
|
iter = container->insert(iter, std::move(__value));
|
|
|
|
++iter;
|
|
|
|
return *this;
|
|
|
|
}
|
2021-06-11 13:55:11 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2022-08-19 11:08:01 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator*() { return *this; }
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator++() { return *this; }
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator& operator++(int) { return *this; }
|
2021-06-11 13:55:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Container>
|
2022-08-19 11:08:01 +00:00
|
|
|
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert_iterator<_Container>
|
2021-08-26 14:55:18 +00:00
|
|
|
inserter(_Container& __x, __insert_iterator_iter_t<_Container> __i) {
|
2021-06-11 13:55:11 +00:00
|
|
|
return insert_iterator<_Container>(__x, __i);
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2023-07-06 17:12:05 +00:00
|
|
|
_LIBCPP_POP_MACROS
|
|
|
|
|
2021-06-11 13:55:11 +00:00
|
|
|
#endif // _LIBCPP___ITERATOR_INSERT_ITERATOR_H
|