1 // Copyright (C) 2019 T. Zachary Laine
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/stl_interfaces/iterator_interface.hpp>
13 //[ repeated_chars_iterator
14 struct repeated_chars_iterator
: boost::stl_interfaces::iterator_interface
<
15 repeated_chars_iterator
,
16 std::random_access_iterator_tag
,
20 constexpr repeated_chars_iterator() noexcept
:
25 constexpr repeated_chars_iterator(
26 char const * first
, difference_type size
, difference_type n
) noexcept
:
32 constexpr char operator*() const noexcept
{ return first_
[n_
% size_
]; }
33 constexpr repeated_chars_iterator
& operator+=(std::ptrdiff_t i
) noexcept
38 constexpr auto operator-(repeated_chars_iterator other
) const noexcept
45 difference_type size_
;
53 //[ repeated_chars_iterator_usage
54 repeated_chars_iterator
first("foo", 3, 0); // 3 is the length of "foo", 0 is this iterator's position.
55 repeated_chars_iterator
last("foo", 3, 7); // Same as above, but now the iterator's position is 7.
57 std::copy(first
, last
, std::back_inserter(result
));
58 assert(result
== "foofoof");