Boost logo

Boost :

From: Gavin Lambert (boost_at_[hidden])
Date: 2019-12-16 06:46:27

On 16/12/2019 17:46, Barrett Adair wrote:
>> STLInterfaces is a C++14 library targeting ISO standardization. The
>> following templates are provided, all C++20-friendly:
>> 1. iterator_interface - a modern version of the iterator_facade and
>> iterator_adaptor parts of Boost.Iterator
>> 2. view_interface - a pre-C++20 implementation of C++20's eponymous feature
>> 3. container_interface - a tool to eliminate boilerplate when writing new
>> containers

I'm not sure the example in the Introduction is a great one to lead off

The repeated_chars_iterator could be written like this in C++20, for

     generator<char> repeated_chars(char const *first, size_t size,
size_t n)
         while (true)
             co_yield first[n++ % size];

(Or for more safety it could take a std::string_view. Though both
implementations have a bug if iterated long enough that n overflows; I
just used a similar implementation as the example, although with
different types such that the repeated_chars_iterator produces UB and
possibly crashes and this merely skips some characters and otherwise
continues working. Fixing that is left as an exercise for the reader.)

Granted, this is forward-only rather than random-access, and a generator
is not quite the same as an iterator (and has worse performance in
current implementations), but it better fits the stated goal.

There probably should also be some more discussion on how it interacts
with ranges, since AFAIK much of the need for custom iterators goes away
when you have arbitrarily filterable ranges.

I'm probably not going to have time to do a proper review, however --
it's already Christmas season. [But I would like to see something like
this in general to be accepted. We're still a long way from a C++20 world.]

Boost list run by bdawes at, gregod at, cpdaniel at, john at