Boost.Geometry.Index
 All Classes Functions Typedefs Groups
inserter.hpp
1 // Boost.Geometry Index
2 //
3 // Insert iterator
4 //
5 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
6 //
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 #ifndef BOOST_GEOMETRY_INDEX_INSERTER_HPP
12 #define BOOST_GEOMETRY_INDEX_INSERTER_HPP
13 
14 #include <iterator>
15 
20 namespace boost { namespace geometry { namespace index {
21 
22 template <class Container>
23 class insert_iterator :
24  public std::iterator<std::output_iterator_tag, void, void, void, void>
25 {
26 public:
27  typedef Container container_type;
28 
29  inline explicit insert_iterator(Container & c)
30  : container(&c)
31  {}
32 
33  insert_iterator & operator=(typename Container::value_type const& value)
34  {
35  container->insert(value);
36  return *this;
37  }
38 
39  insert_iterator & operator* ()
40  {
41  return *this;
42  }
43 
44  insert_iterator & operator++ ()
45  {
46  return *this;
47  }
48 
49  insert_iterator operator++(int)
50  {
51  return *this;
52  }
53 
54 private:
55  Container * container;
56 };
57 
70 template <typename Container>
71 insert_iterator<Container> inserter(Container & c)
72 {
73  return insert_iterator<Container>(c);
74 }
75 
76 }}} // namespace boost::geometry::index
77 
78 #endif // BOOST_GEOMETRY_INDEX_INSERTER_HPP
insert_iterator< Container > inserter(Container &c)
Insert iterator generator.
Definition: inserter.hpp:71