C++ Logo


Advanced search

Re: [std-proposals] Helper type

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Thu, 24 Nov 2022 07:31:02 +0200
On Thu, 24 Nov 2022 at 02:02, organicoman via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Hello gents,
> I would like to suggest the following helper type:
> "null_iter"
> It is of type iterator but convertible to the boolean value "false", much like the type: "nullptr"
> This value "null_iter" is returned by all container iterators types (vector::iterator, list::iterator, set::iterator...etc) to denote the end of the container when you apply the increment or decrement operators.
> For exple:
> --------- code snippet -------
> std::vector<int> v{1,2,3,4};
> auto iter = v.begin();
> while(++iter)
> {
> //
> }
> ------- end of snippet------
> When "iter" hits "v.end()", it will return "null_iter" which will be converted to "false" then the loop stops.
> What do you think?

I don't think it's possible for an iterator's operator++ to return
different types based on the run-time position
of the iterator.

Received on 2022-11-24 05:31:15