C++ Logo

std-proposals

Advanced search

Re: [std-proposals] span<incomplete_type>

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Thu, 6 Jul 2023 12:37:07 -0400
Consider the following modification of your example:

class Element;
*struct* Storage {
  ...
  *const vector<Element>&* get_elements();
};
extern void process(span<Element>);
void do_something(Storage& storage) {
  process(storage.get_elements()); // ill-formed
}

Can I make a `span<Element>` out of a `const vector<Element>&`? Nope, I
can't.
Why not? Because `span<Element>`'s constructor requires a contiguous range
of Elements, and `vector<Element>` doesn't satisfy `contiguous_range`.
And why doesn't it? Because its iterator type is `Element*`, and that is
not a contiguous iterator.
Why not? Because it's not any kind of iterator. It's not even
weakly_incrementable. `Element *p; ++p;` is ill-formed (when `Element` is
incomplete).

This doesn't at all kill your proposal; but you must address it head-on in
your paper.
Particularly, you must try implementing this, and give an (empirically
tested) table of examples that Just Work after your patch, versus those
that Don't Work.
For example, presumably this would make `span<Element>` copy-constructible,
right?
But would it also make `span<Element, 42>` convertible to `span<Element>`?
or would that still Not Work, because of the logic above?
We know it would *not* make `vector<Element>` convertible to
`span<Element>`.

By seeing that table, readers could decide whether the benefit seems worth
the cost.

HTH,
Arthur


On Thu, Jul 6, 2023 at 12:27 PM Jason McKesson via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Thu, Jul 6, 2023 at 2:50 AM Andrey Davydov via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > Hello everyone!
> >
> > I'd like to propose a support span of elements of incomplete type.
> > The draft of the proposal (
> https://github.com/AndreyG/cpp-papers/blob/main/span-of-incomplete-element-type.md)
> contains motivation. What do you think about it?
>
> The proposal needs to investigate why the limitation exists at all. I
> didn't know about it until you brought it up. You should spend some
> time looking into older versions of `span` or asking the people who
> made those proposals why the type is required to be complete.
>
> There could be some good-yet-esoteric reason why this limitation is here.
>

Received on 2023-07-06 16:37:20