tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
back_insert_iterator.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2#ifndef TETL_ITERATOR_BACK_INSERT_ITERATOR_HPP
3#define TETL_ITERATOR_BACK_INSERT_ITERATOR_HPP
4
9
10namespace etl {
11
17template <typename Container>
20 using value_type = void;
22 using pointer = void;
23 using reference = void;
24 using container_type = Container;
25
27 constexpr back_insert_iterator() noexcept = default;
28
31 constexpr explicit back_insert_iterator(Container& container)
32 : _container{etl::addressof(container)}
33 {
34 }
35
37 constexpr auto operator=(typename Container::value_type const& value) -> back_insert_iterator&
38 {
39 _container->push_back(value);
40 return *this;
41 }
42
44 constexpr auto operator=(typename Container::value_type&& value) -> back_insert_iterator&
45 {
46 _container->push_back(etl::move(value));
47 return *this;
48 }
49
54 constexpr auto operator*() -> back_insert_iterator& { return *this; }
55
60 constexpr auto operator++() -> back_insert_iterator& { return *this; }
61
66 constexpr auto operator++(int) -> back_insert_iterator { return *this; }
67
68private:
69 Container* _container = nullptr;
70};
71
75template <typename Container>
76[[nodiscard]] constexpr auto back_inserter(Container& container) -> back_insert_iterator<Container>
77{
78 return back_insert_iterator<Container>(container);
79}
80
81} // namespace etl
82
83#endif // TETL_ITERATOR_BACK_INSERT_ITERATOR_HPP
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
Definition adjacent_find.hpp:8
constexpr auto addressof(T &arg) noexcept -> T *
Obtains the actual address of the object or function arg, even in presence of overloaded operator&.
Definition addressof.hpp:15
TETL_BUILTIN_PTRDIFF ptrdiff_t
etl::ptrdiff_t is the signed integer type of the result of subtracting two pointers.
Definition ptrdiff_t.hpp:14
constexpr auto back_inserter(Container &container) -> back_insert_iterator< Container >
back_inserter is a convenience function template that constructs a back_insert_iterator for the conta...
Definition back_insert_iterator.hpp:76
etl::back_insert_iterator is a LegacyOutputIterator that appends to a container for which it was cons...
Definition back_insert_iterator.hpp:18
void pointer
Definition back_insert_iterator.hpp:22
constexpr auto operator*() -> back_insert_iterator &
Does nothing, this member function is provided to satisfy the requirements of LegacyOutputIterator....
Definition back_insert_iterator.hpp:54
constexpr back_insert_iterator() noexcept=default
Initializes the underlying pointer to container with nullptr.
constexpr auto operator=(typename Container::value_type const &value) -> back_insert_iterator &
Inserts the given value value to the container.
Definition back_insert_iterator.hpp:37
constexpr auto operator++(int) -> back_insert_iterator
Does nothing. These operator overloads are provided to satisfy the requirements of LegacyOutputIterat...
Definition back_insert_iterator.hpp:66
Container container_type
Definition back_insert_iterator.hpp:24
void reference
Definition back_insert_iterator.hpp:23
void value_type
Definition back_insert_iterator.hpp:20
constexpr auto operator++() -> back_insert_iterator &
Does nothing. These operator overloads are provided to satisfy the requirements of LegacyOutputIterat...
Definition back_insert_iterator.hpp:60
ptrdiff_t difference_type
Definition back_insert_iterator.hpp:21
output_iterator_tag iterator_category
Definition back_insert_iterator.hpp:19
constexpr auto operator=(typename Container::value_type &&value) -> back_insert_iterator &
Inserts the given value value to the container.
Definition back_insert_iterator.hpp:44
Defines the category of an iterator. Each tag is an empty type and corresponds to one of the five (un...
Definition tags.hpp:18