Skip to content
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

[locale.codecvt.virtuals] Improve wording #7347

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cpplearner
Copy link
Contributor

Pre-C++98 draft N1146 [lib.locale.codecvt.virtuals]/2 mentions:

[Note: If no translation is needed (returns noconv), sets to_next equal to argument to, and from_next equal to argument from. --end note]

LWG 19 proposes to "change the Note in paragraph 2 to normative text", but in doing so, it introduces a few problems:

This PR fixes the last two problems.

@tkoeppe tkoeppe requested a review from jwakely December 17, 2024 22:07
@jwakely
Copy link
Member

jwakely commented Dec 18, 2024

I think this whole function could do with better specification, at least p3 and the table. If the result is noconv then there is no converted sequence, so it doesn't really make sense to talk about "the converted sequence is identical to the input sequence [from, from_next)".

For the noconv case, the converted sequence is hypothetical, i.e. the converted sequence would be identical to the input sequence if an actual conversion was performed. But that doesn't happen, no conversion is done.

It always leaves the from_next and to_next pointers pointing one beyond the last element successfully converted.

If this was stated more precisely/clearly, we wouldn't need to say what happens to from_next and to_next in the noconv case.

The addition of "from_next is set equal to from" isn't clearly sequenced relative to the use of from_next earlier in the sentence when referring to "the input sequence [from, from_next)".

This now becomes is very non-editorial, but I'd prefer to get rid of the table and rewrite the effects, e.g. something like

If internT and externT are the same type and the converted sequence would be identical to the input sequence [from, from_next), then no elements are converted, the value of state is unchanged, there are no changes to the values in [to, to_end), and the result is noconv. Otherwise, if a character in [from,from_end) cannot be converted, conversion stops at that character and the result is error. Otherwise, if all input characters are successfully converted and placed in the output range, the result is ok. Otherwise, if the output range [to,to_end) is reached before converting all characters from the input sequence, the result is partial. In all cases, from_next is set to point to the first element of the input that was not converted, to_next is set to point to the first unchanged element in the output. [Note: When the result is noconv, from_next points to from and to_next points to to -- end note]

Returns: The result as described above.

This still has lots of room for improvement, but I think it would be better than what we have now, even with this PR.

@cpplearner
Copy link
Contributor Author

I suspect that "the input sequence [from, from_next)" should be "[from, from_end)". It doesn't make sense to use from_next since it's an out parameter.

Can we get Nathan Myers (@ncm) to comment on this issue?

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.

2 participants