Skip to content

[inplace.vector] Use T*, not pointer, for some return types #7322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

Quuxplusone
Copy link
Contributor

This is editorial for now. But P3160 "allocator-aware inplace_vector" might change the definition of pointer (that's still up in the air), and if so, we definitely want try_emplace_back to continue returning a raw pointer, not some kind of fancy pointer. Make that change now, so that we don't have to worry about it during the discussion of P3160.

Marking as "draft" until @phalpern confirms that this is desirable (or at least not harmful) from his POV too.

This is editorial for now. But P3160 "allocator-aware `inplace_vector`"
*might* change the definition of `pointer` (that's still up in the air),
and if so, we definitely want `try_emplace_back` to continue returning
a raw pointer, not some kind of fancy pointer. Make that change now,
so that we don't have to worry about it during the discussion of P3160.
@Quuxplusone Quuxplusone marked this pull request as draft October 18, 2024 17:36
@jensmaurer
Copy link
Member

At the present stage, this change feels undermotivated to me (as an editorial change). The paper changing the pointer typedef should make a case why the three try_ functions should always return a raw pointer. And the diff for these just three functions seems small enough not to cause excessive clutter.

@phalpern
Copy link

If pointer and const_pointer are changed to be related to the allocator, then I'm unclear whether the try_emplace function should return a raw pointer or a pointer, since it's unclear what the pointer and const_pointer types are supposed to indicate. If they indicate a pointer type that can address any element of the container, then perhaps try_emplace should be left alone, since it returns a (nullable) pointer to an element. I'm in favor of deprecating pointer and const_pointer for all containers, since their purpose is unclear. If that happens, then changing try_emplace (and any other function that might return pointer) makes obvious sense. I am neutral about making the change to try_emplace in isolation, with no change to pointer or const_pointer.

@frederick-vs-ja
Copy link
Contributor

I'm in favor of deprecating pointer and const_pointer for all containers, since their purpose is unclear.

I'm also for deprecation. As of C++23, the pointer member typedef can make some containers automatically "usable" with out_ptr_t/inout_ptr_t, which is extremely accidental to me.

@tkoeppe
Copy link
Contributor

tkoeppe commented Jun 18, 2025

In the current working paper, pointer is T*, so I take it we don't need this?

@frederick-vs-ja
Copy link
Contributor

In the current working paper, pointer is T*, so I take it we don't need this?

Yeah. But I think the intent is making the return types of try_* functions robust to potential change of pointer. The changes are still editorial currently, but will be possibly not so in the future.

@jensmaurer
Copy link
Member

Let's have such changes when/if LWG / LEWG does decide to change the definition of "pointer". Then it's intentional what the try_ functions should return, by adapting this then.

@jwakely , is there some LWG-level motivation to have this changed editorially?

@Quuxplusone
Copy link
Contributor Author

In the current working paper, pointer is T*, so I take it we don't need this?

This has always been editorial, so yeah, we "don't need" any editorial change, by definition. The original motivation here was to front-load this editorial change in order to minimize P3160's diff (exactly the motivation @jensmaurer just gave, except, front-loading the intentionality: we commit up front that we really do want the current behavior, T*, here, rather than leaving that up in the air until later: force an explicit change here if someone wants to change that behavior).

That said, P3160 is abandoned/rejected at this point, so unless it comes back as a result of NB comment, the only motivation to prefer T* over pointer here is simplicity of specification.

@jensmaurer
Copy link
Member

jensmaurer commented Jun 18, 2025

There are likely a lot of places where we could replace a use of a local typedef with a template parameter, and it would be editorial, so if the answer to "why do it here" is "because that's the intention of future paper X", then the right approach is to have future paper X do it, to explicitly surface that intentionality in the wording diff (even though that makes the diff slightly larger).

@jensmaurer jensmaurer closed this Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants