Boost logo

Boost :

Subject: Re: [boost] [iterator] generator_iterator vs. function_input_iterator
From: Michel Morin (mimomorin_at_[hidden])
Date: 2017-09-01 16:40:28


Robert Ramey wrote:
> Hmmmm - I'm thinking that silently changing the functionality
> of a component 12? years old to something "nearly" equivalent
> is a really bad idea. How can one know that this wouldn't
> break old code in a way that's just about impossible to track down.

Thanks for the comment.
I thought that if the following are all satisfied then it would be
worth the change. But as described below, some of them are not satisfied.

1. `old_xxxx` is unanimously better name than `new_xxxx`.
2. `new_xxxx` has better implementation and new users should use the `new_xxxx`.
3. If there is any behavioral change, that should not be silent (that should
result in compilation failures).
4. Easy to update old codes.

- It seems that 1 is not true for other than range enthusiasts.
- `generator_iterator` is easy to be misused. For example, this function
    void print_random_numbers(int n)
    {
        auto it = make_generator_iterator(std::random_device{});
        for (int i = 0; i < n; ++i) {
              cout << *it << endl;
        }
    }
  consumes n+1 random numbers (the last random number is thrown away).
  `function_input_iterator` avoids such behaviors and consumes just
  n random numbers. So I think 2 is satisfied.
- 3 is satisfied, but 4 is not satisfied unless we introduce
  `generator_iterator_v1` (that is, renamed old `generator_iterator`).

Regards,
Michel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk