1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___ITERATOR_INSERT_ITERATOR_H 11 #define _LIBCPP___ITERATOR_INSERT_ITERATOR_H 12 13 #include <__config> 14 #include <__iterator/iterator.h> 15 #include <__iterator/iterator_traits.h> 16 #include <__memory/addressof.h> 17 #include <__utility/move.h> 18 #include <cstddef> 19 20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 21 #pragma GCC system_header 22 #endif 23 24 _LIBCPP_BEGIN_NAMESPACE_STD 25 26 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 27 template <class _Container> 28 class _LIBCPP_TEMPLATE_VIS insert_iterator 29 #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) 30 : public iterator<output_iterator_tag, void, void, void, void> 31 #endif 32 { 33 _LIBCPP_SUPPRESS_DEPRECATED_POP 34 protected: 35 _Container* container; 36 typename _Container::iterator iter; // FIXME: `ranges::iterator_t<Container>` in C++20 mode 37 public: 38 typedef output_iterator_tag iterator_category; 39 typedef void value_type; 40 #if _LIBCPP_STD_VER > 17 41 typedef ptrdiff_t difference_type; 42 #else 43 typedef void difference_type; 44 #endif 45 typedef void pointer; 46 typedef void reference; 47 typedef _Container container_type; 48 49 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i) 50 : container(_VSTD::addressof(__x)), iter(__i) {} 51 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_) 52 {iter = container->insert(iter, __value_); ++iter; return *this;} 53 #ifndef _LIBCPP_CXX03_LANG 54 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_) 55 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} 56 #endif // _LIBCPP_CXX03_LANG 57 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;} 58 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;} 59 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;} 60 }; 61 62 template <class _Container> 63 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 64 insert_iterator<_Container> 65 inserter(_Container& __x, typename _Container::iterator __i) 66 { 67 return insert_iterator<_Container>(__x, __i); 68 } 69 70 _LIBCPP_END_NAMESPACE_STD 71 72 #endif // _LIBCPP___ITERATOR_INSERT_ITERATOR_H 73