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

Refactoring around tuple-like, pair-like, and subrange #4983

Merged

Conversation

frederick-vs-ja
Copy link
Contributor

@frederick-vs-ja frederick-vs-ja commented Sep 26, 2024

Effectively mirrors LLVM-85206.

In the current standard wording, the "pair-like but not subrange" pattern is used more often than plain pair-like. So it's probably worthwhile to carve out the _Pair_like_non_subrange concept. _Tuple_like_non_subrange seems less worthwhile, but it should be helpful in the constructors of tuple.

Moreover, with _Pair_like_non_subrange carved out, we can put the definitions of _Pair_like in C++20 & 23 modes together in <xutility>.

_Pair_like_non_subrange should be also helpful for extracting the key object from pair-like construction argument via
_In_place_key_extract_map (since C++23). I think this can be done in a future PR.

Other changes: Renaming the template parameter of subrange's conversion function to _PairLike, making the identifier _Pair_like in MSVC STL always mean the concept.

Effectively mirrors LLVM-85206.

In the current standard wording, the "_`pair-like`_ but not `subrange`"
pattern is used more often than plain _`pair-like`_. So it's probably
worthwhile to carve out the `_Pair_like_non_subrange` concept.
`_Tuple_like_non_subrange` seems less worthwhile, but it should be
helpful in the constructors of  `tuple`.

Moreover, with `_Pair_like_non_subrange` carved out, we can put the
definitions of `_Pair_like` in C++20 & 23 modes together in
`<xutility>`.

`_Pair_like_non_subrange` should be also helpful for extracting the key
object from pair-like construction argument via
`_In_place_key_extract_map` (since C++23). I think this can be done in
a future PR.

Other changes: Renaming the template parameter of `subrange`'s
conversion function to `_PairLike`, making the identifier `_Pair_like
 in MSVC STL always mean the concept.
@frederick-vs-ja frederick-vs-ja force-pushed the tuple-like-but-not-subrange branch from f40ce6f to 15e946c Compare September 26, 2024 07:05
@CaseyCarter CaseyCarter added the enhancement Something can be improved label Sep 26, 2024
@StephanTLavavej StephanTLavavej self-assigned this Sep 28, 2024
@StephanTLavavej
Copy link
Member

This is an awesome simplification, thank you! This makes the code easier to follow, and avoids the hazard of forgetting remove_cv_t with _Is_subrange_v. I especially can't believe we were shadowing _Pair_like - you know how much I loathe that! 😻

Question for potential followup, not in this PR - I observe that we have:

STL/stl/inc/xmemory

Lines 2295 to 2300 in faccf00

template <class _Ty>
concept _Usable_for_pair_like_overload =
#if _HAS_CXX23
_Pair_like<_Ty> ||
#endif // _HAS_CXX23
!_Is_deducible_as_pair<_Ty&>;

Now that _Pair_like is available in both C++20/23, can/should we use it unconditionally here? I tried to look up how uses_allocator_construction_args was specified in C++20 but the machinery is very complicated (even by my standards 😹) so I'm not entirely sure.

@StephanTLavavej StephanTLavavej removed their assignment Oct 3, 2024
@StephanTLavavej StephanTLavavej self-assigned this Oct 11, 2024
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit de79d09 into microsoft:main Oct 12, 2024
39 checks passed
@StephanTLavavej
Copy link
Member

🍐 🍐 🍐

@frederick-vs-ja frederick-vs-ja deleted the tuple-like-but-not-subrange branch October 12, 2024 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants