{"id":264375,"date":"2015-08-27T10:11:02","date_gmt":"2015-08-27T06:11:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=264375"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=264375","title":{"rendered":"\u0414\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440"},"content":{"rendered":"<p>     \t\u041d\u0435 \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u0434 \u0440\u0443\u043a\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 HowTo. \u0412 \u044d\u0442\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u0445 \u0442\u0438\u043f\u0430 std::copy, std::find. \u041a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u043d\u0443\u0436\u043d\u044b \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0446\u0438\u043a\u043b\u0430\u0445 for \u0438\u0437 c++11 \u0438 BOOST_FOREACH.<\/p>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h1>\u041a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440<\/h1>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0438\u043f\u044b iterator \u0438 const_iterator (\u0442\u0438\u043f\u044b \u043d\u0443\u0436\u043d\u044b \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430, \u0430 \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445 \u0431\u0435\u0437 \u043d\u0438\u0445 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0431\u0445\u043e\u0434 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 BOOST_FOREACH), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u0435\u0442\u043e\u0434\u044b begin \u0438 end (\u0442\u0443\u0442 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0435 const_iterator):<br \/>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.  <\/p>\n<pre><code class=\"cpp\">class OwnContainer { public:     typedef OwnIterator&lt;int&gt; iterator;     typedef OwnIterator&lt;const int&gt; const_iterator;      OwnContainer(std::initializer_list&lt;int&gt; values);      iterator begin();     iterator end();      const_iterator begin() const;     const_iterator end() const; private:     const size_t size;     std::unique_ptr&lt;int[]&gt; data; }; <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 OwnContainer<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">OwnContainer::OwnContainer(std::initializer_list&lt;int&gt; values) :     size(values.size()),     data(new int[size]) {     std::copy(values.begin(), values.end(), data.get()); }  OwnContainer::iterator OwnContainer::begin() {     return iterator(data.get()); }  OwnContainer::iterator OwnContainer::end() {     return iterator(data.get() + size); }  OwnContainer::const_iterator OwnContainer::begin() const {     return const_iterator(data.get()); }  OwnContainer::const_iterator OwnContainer::end() const {     return const_iterator(data.get() + size); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0438\u0447\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c iterator \u0438 const_iterator \u043a\u0430\u043a \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u0442\u0438\u043f\u0430.<\/p>\n<h1>\u0418\u0442\u0435\u0440\u0430\u0442\u043e\u0440<\/h1>\n<p>  \u0418\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 std::iterator. \u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043d\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0442\u0438\u043f\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u0445.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">std::iterator<\/b><\/p>\n<div class=\"spoiler_text\">\u041a\u0430\u043a \u043e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435 \u0432 g++ 4.9  <\/p>\n<pre><code class=\"cpp\">  template&lt;typename _Category, typename _Tp, typename _Distance = ptrdiff_t,            typename _Pointer = _Tp*, typename _Reference = _Tp&&gt;     struct iterator     {       \/\/\/ One of the @link iterator_tags tag types@endlink.       typedef _Category  iterator_category;       \/\/\/ The type &quot;pointed to&quot; by the iterator.       typedef _Tp        value_type;       \/\/\/ Distance between iterators is represented as this type.       typedef _Distance  difference_type;       \/\/\/ This type represents a pointer-to-value_type.       typedef _Pointer   pointer;       \/\/\/ This type represents a reference-to-value_type.       typedef _Reference reference;     }; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u042d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u2014 \u0442\u0438\u043f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439, \u0442\u043e \u0442\u0438\u043f \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432: input_iterator_tag, output_iterator_tag, forward_iterator_tag, bidirectional_iterator_tag, random_access_iterator_tag. \u0412\u0442\u043e\u0440\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0442\u0438\u043f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438 * \u0438 -&gt;, \u0442\u0435\u0440\u0435\u0442\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2014 \u0442\u0438\u043f \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438, \u0447\u0435\u0442\u0432\u0440\u0442\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2014 \u0442\u0438\u043f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043f\u044f\u0442\u044b\u0439 \u2014 \u0442\u0438\u043f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.<\/p>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e InputIterator (input_iterator_tag), \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0430, \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 !=, \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440* \u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 -&gt; (\u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u0438\u043f\u0430 int, \u0438 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 operator-&gt; \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u0435\u043d). \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043a\u0440\u043e\u043c\u0435, \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 begin \u0438 end \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c, \u0430 \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u043a\u0430\u043a \u0434\u0440\u0443\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439. \u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 ==, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445 \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 != \u0438 == \u0432\u043c\u0435\u0441\u0442\u0435, \u0430 \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445 \u0431\u0435\u0437 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c BOOST_FOREACH.<\/p>\n<p>  const_iterator \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 iterator, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u044a\u044f\u0432\u0438\u043c iterator \u043a\u0430\u043a \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u2014 \u0442\u0438\u043f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 * \u0438 -&gt;.<\/p>\n<p>  \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439\u0441\u044f \u0432 OwnContainer.<\/p>\n<pre><code class=\"cpp\">template&lt;typename ValueType&gt; class OwnIterator: public std::iterator&lt;std::input_iterator_tag, ValueType&gt; {     friend class OwnContainer; private:     OwnIterator(ValueType* p); public:     OwnIterator(const OwnIterator &it);      bool operator!=(OwnIterator const& other) const;     bool operator==(OwnIterator const& other) const; \/\/need for BOOST_FOREACH     typename OwnIterator::reference operator*() const;     OwnIterator& operator++(); private:     ValueType* p; }; <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 OwnIerator<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">template&lt;typename ValueType&gt; OwnIterator&lt;ValueType&gt;::OwnIterator(ValueType *p) :     p(p) {  }  template&lt;typename ValueType&gt; OwnIterator&lt;ValueType&gt;::OwnIterator(const OwnIterator& it) :     p(it.p) {  }  template&lt;typename ValueType&gt; bool OwnIterator&lt;ValueType&gt;::operator!=(OwnIterator const& other) const {     return p != other.p; }  template&lt;typename ValueType&gt; bool OwnIterator&lt;ValueType&gt;::operator==(OwnIterator const& other) const {     return p == other.p; }  template&lt;typename ValueType&gt; typename OwnIterator&lt;ValueType&gt;::reference OwnIterator&lt;ValueType&gt;::operator*() const {     return *p; }  template&lt;typename ValueType&gt; OwnIterator&lt;ValueType&gt; &OwnIterator&lt;ValueType&gt;::operator++() {     ++p;     return *this; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f, \u043d\u043e \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 boost \u0435\u0441\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u0438 \u043e \u043d\u0435\u043c \u0442\u043e \u0436\u0435 \u0445\u043e\u0447\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u0441\u043b\u043e\u0432.<\/p>\n<h1>\u0418\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 boost::iterator_facade<\/h1>\n<p>  \u041a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u0430\u043c\u0438 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f iterator \u0438 const_iterator:  <\/p>\n<pre><code class=\"cpp\">class OwnContainerBBI { public:     typedef OwnIteratorBB&lt;int&gt; iterator;     typedef OwnIteratorBB&lt;const int&gt; const_iterator;      OwnContainerBBI(std::initializer_list&lt;int&gt; values);      iterator begin();     iterator end();      const_iterator begin() const;     const_iterator end() const; private:     const size_t size;     std::unique_ptr&lt;int[]&gt; data; }; <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 OwnContainerBBI<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">OwnContainerBBI::OwnContainerBBI(std::initializer_list&lt;int&gt; values) :     size(values.size()),     data(new int[size]) {     std::copy(values.begin(), values.end(), data.get()); }  OwnContainerBBI::iterator OwnContainerBBI::begin() {     return iterator(data.get()); }  OwnContainerBBI::iterator OwnContainerBBI::end() {     return iterator(data.get() + size); }  OwnContainerBBI::const_iterator OwnContainerBBI::begin() const {     return const_iterator(data.get()); }  OwnContainerBBI::const_iterator OwnContainerBBI::end() const {     return const_iterator(data.get() + size); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 boost::iterator_facade. \u042d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2014 \u0442\u0438\u043f \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430, \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0438\u043f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u0440\u0435\u0442\u0438\u0439 \u0442\u0438\u043f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0442\u0438\u043f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 std::iterator, \u0442\u0430\u043a \u0438 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0434\u043b\u044f boost (\u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0442\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d \u043a\u0430\u043a old-style), \u044f \u0432\u043e\u0437\u044c\u043c\u0443 \u0442\u043e\u0442 \u0436\u0435 \u0442\u0438\u043f, \u0447\u0442\u043e \u0438 \u0434\u043b\u044f std::iterator. boost::iterator_facade \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b: operator*, operator++, operator-&gt; \u0438 \u0442.\u0434. \u041d\u043e \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0430\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0435, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e dereference, equal, increment, decrement, advance, distance. \u0412 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0435 (\u043a\u0430\u043a \u043d\u0430\u0448) \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e equal, increment \u0438 dereference. \u0422\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0435\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u0438\u0445 \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 privat, \u0430 \u043a\u043b\u0430\u0441\u0441 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 (boost::iterator_core_access) \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u0434\u0440\u0443\u0433\u043e\u043c.<\/p>\n<pre><code class=\"cpp\">template&lt;typename ValueType&gt; class OwnIteratorBB: public boost::iterator_facade&lt;         OwnIteratorBB&lt;ValueType&gt;,         ValueType,         boost::single_pass_traversal_tag         &gt; {     friend class OwnContainerBBI;     friend class boost::iterator_core_access; private:     OwnIteratorBB(ValueType* p); public:     OwnIteratorBB(const OwnIteratorBB& it); private:     bool equal(OwnIteratorBB const& it) const;     void increment();     typename OwnIteratorBB::reference dereference() const;      ValueType* p; }; <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 OwnIteratorBB<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">template&lt;typename ValueType&gt; OwnIteratorBB&lt;ValueType&gt;::OwnIteratorBB(ValueType *p) :     p(p) {  }  template&lt;typename ValueType&gt; OwnIteratorBB&lt;ValueType&gt;::OwnIteratorBB(const OwnIteratorBB &it) :     p(it.p) {  }  template&lt;typename ValueType&gt; bool OwnIteratorBB&lt;ValueType&gt;::equal(const OwnIteratorBB &it) const {     return p == it.p; }  template&lt;typename ValueType&gt; void OwnIteratorBB&lt;ValueType&gt;::increment() {     ++p; }  template&lt;typename ValueType&gt; typename OwnIteratorBB&lt;ValueType&gt;::reference OwnIteratorBB&lt;ValueType&gt;::dereference() const {     return *p; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h1>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h1>\n<p>  \u0418\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0432\u043e\u0432\u0441\u0435. \u0418\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0430\u043c\u0438 \u043d\u0430\u0434 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438 \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u0438\u043d. \u0418\u043b\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u043e\u043b\u0435\u0439. \u0418 \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u0436\u0435\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c, \u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0432\u0443\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u0440\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430. \u0415\u0449\u0435 \u0438\u0434\u0435\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0435\u0440\u043f\u043d\u0443\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"http:\/\/habrahabr.ru\/post\/122283\/\">\u041d\u0435\u0434\u043e\u043e\u0446\u0435\u043d\u0451\u043d\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/a> \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439  <a href=\"http:\/\/habrahabr.ru\/users\/k06a\/\" class=\"user_link\">k06a<\/a>.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 boost::iterator_facade \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 boost \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0442\u044f\u043d\u0443\u0442\u044c \u0435\u0451 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0434\u0438 iterator_facade \u0441\u043c\u044b\u0441\u043b\u0430 \u043d\u0435\u0442.<\/p>\n<h1>\u0421\u0441\u044b\u043b\u043a\u0438<\/h1>\n<p>  1. <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/iterator\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 Iterator library \u043d\u0430 cppreference,com<\/a>.<br \/>  2. <a href=\"http:\/\/www.boost.org\/doc\/libs\/1_59_0\/libs\/iterator\/doc\/iterator_facade.html\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 boost::iterator_facade<\/a><br \/>  3. <a href=\"https:\/\/github.com\/hokum2004\/OwnIterator\">\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043d\u0430 github<\/a>. \u041f\u0440\u043e\u0435\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Qt5 (\u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432), \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f boost, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f BOOST \u0441 \u043f\u0443\u0442\u0435\u043c \u043a \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0443 \u0441 boost.     \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/265491\/\"> http:\/\/habrahabr.ru\/post\/265491\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t\u041d\u0435 \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u0434 \u0440\u0443\u043a\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 HowTo. \u0412 \u044d\u0442\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u0445 \u0442\u0438\u043f\u0430 std::copy, std::find. \u041a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u043d\u0443\u0436\u043d\u044b \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0446\u0438\u043a\u043b\u0430\u0445 for \u0438\u0437 c++11 \u0438 BOOST_FOREACH.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-264375","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/264375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=264375"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/264375\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=264375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=264375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=264375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}