VCCC  2024.05
VisualCamp Common C++ library
back_emplace.hpp
Go to the documentation of this file.
1 # /*
2 # Created by YongGyu Lee on 2020/12/08.
3 # */
4 #
5 # ifndef VCCC_TYPE_SUPPORT_BACK_EMPLACE_HPP
6 # define VCCC_TYPE_SUPPORT_BACK_EMPLACE_HPP
7 #
8 # include <iterator>
9 #
10 # ifdef _MSC_VER
11 # pragma warning( push )
12 # pragma warning( disable : 4996)
13 # endif
14 
15 namespace vccc {
16 
17 namespace internal {
18 
19 # if __cplusplus >= 201703L
20 struct back_emplace_iterator_base {
21  using iterator_category = std::output_iterator_tag;
22 
23  using value_type = void;
24 # if __cplusplus >= 202002L
25  using difference_type = std::ptrdiff_t;
26 # else
27  using difference_type = void;
28 # endif
29  using pointer = void;
30  using reference = void;
31 };
32 # else
33 using back_emplace_iterator_base =
34  std::iterator<std::output_iterator_tag,
35  void,
36  void,
37  void,
38  void>;
39 # endif
40 
41 } // namespace internal
42 
45 
46 template <class Container>
48  : public internal::back_emplace_iterator_base
49 {
50  protected:
51  Container* container;
52  public:
53  using container_type = Container;
54 
55  explicit back_emplace_iterator(Container& x) : container(std::addressof(x)) {}
56  back_emplace_iterator& operator=(const typename Container::value_type& value)
57  {container->emplace_back(value); return *this;}
58  back_emplace_iterator& operator=(typename Container::value_type&& value)
59  {container->emplace_back(std::move(value)); return *this;}
60  back_emplace_iterator& operator*() {return *this;}
61  back_emplace_iterator& operator++() {return *this;}
62  back_emplace_iterator operator++(int) {return *this;}
63 };
64 
70 template<typename Container>
71 back_emplace_iterator<Container>
72 back_emplacer(Container& container)
73 {
74  return back_emplace_iterator<Container>(container);
75 }
76 
78 
79 } // namespace vccc
80 
81 # ifdef _MSC_VER
82 # pragma warning( pop )
83 # endif
84 
85 # endif // VCCC_TYPE_SUPPORT_BACK_EMPLACE_HPP
Definition: back_emplace.hpp:49
back_emplace_iterator operator++(int)
Definition: back_emplace.hpp:62
back_emplace_iterator(Container &x)
Definition: back_emplace.hpp:55
back_emplace_iterator & operator=(typename Container::value_type &&value)
Definition: back_emplace.hpp:58
Container container_type
Definition: back_emplace.hpp:53
back_emplace_iterator & operator++()
Definition: back_emplace.hpp:61
Container * container
Definition: back_emplace.hpp:51
back_emplace_iterator & operator=(const typename Container::value_type &value)
Definition: back_emplace.hpp:56
back_emplace_iterator & operator*()
Definition: back_emplace.hpp:60
std::output_iterator_tag output_iterator_tag
Definition: iterator_tag.hpp:16
std::enable_if_t< std::is_object< T >::value, T * > addressof(T &t) noexcept
Definition: addressof.hpp:33
back_emplace_iterator< Container > back_emplacer(Container &container)
make back_emplace_iterator
Definition: back_emplace.hpp:72
Definition: matrix.hpp:495
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35