-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
P0202R3 constexpr For <algorithm> And exchange() #6
Comments
I'm starting this and hope to get the |
Should we turn on the feature test macro for this even though some algorithms will break due to DevCom-883631 ? |
(e.g. so far some calls to is_permutation will trigger it) |
Yes, I believe we should. I wouldn't say that we don't support |
p0202r3, those in bold have libc++ tests already present we can use:
|
Resolves microsoftGH-6, microsoftGH-38, and drive-by fixes microsoftGH-414. Constexprizes the following algorithms and enables all relevant libc++ tests: * adjacent_find * all_of * any_of * binary_search * copy * copy_backward * copy_if * copy_n * count * count_if * equal * equal_range * exchange * fill * fill_n * find * find_end * find_first_of * find_if * find_if_not * for_each * for_each_n * generate * generate_n * includes * is_heap * is_heap * is_heap_until * is_partitioned * is_permutation * is_sorted * is_sorted_until * iter_swap * lexicographical_compare * lower_bound * make_heap * merge * mismatch * move * move_backward * next_permutation * none_of * nth_element * partial_sort * partial_sort_copy * partition * partition_copy * partition_point * pop_heap * prev_permutation * push_heap * remove * remove_copy * remove_copy_if * remove_if * replace * replace_copy * replace_copy_if * replace_if * reverse_copy * revese * rotate * rotate_copy * search * search_n * set_difference * set_intersection * set_symmetric_difference * set_union * sort * sort_heap * swap * swap_ranges * transform * unique * unique_copy * upper_bound This commit also contains the contents of microsoft#423 to workaround DevCom-883631, it will be rebased and that content removed once that is merged (the other one needs to be merged first). Specific notes: `<xutility>`: * The `_Ptr_copy_cat` family are moved down next to std::copy as that is their first consumer. * The core language loop for `copy_n` is fairly long and so it was extracted into its own function, `_Copy_n_core` (note similar name schema to `_Copy_memmove`) * `reverse` was changed to use early-returns for its optimization passes; this removes the nice thing of having if constexpr not instantiate the loop. However, this form allows the loop to not be duplicated.
I asked libc++ folks how they would like submitted tests for this since they would fail, and didn't get a reasonable answer, so I'm going to go ahead and do an internal-only test for the missing algorithms, as well as the ones that needed explicit is_constant_evaluated tests. |
Resolves microsoftGH-6 ( P0202R3 ), microsoftGH-38 ( P0879R0 ), and drive-by fixes microsoftGH-414. Everywhere: Add constexpr, _CONSTEXPR20, and _CONSTEXPR20_ICE to things. skipped_tests.txt: Turn on all tests previously blocked by missing constexpr algorithms (and exchange and swap). Mark those algorithms that cannot be turned on that we have outstanding PRs for with their associated PRs. yvals_core.h: Turn on feature test macros. xutility: * Move the _Ptr_cat family down to copy, and fix associated SHOUTY comments to indicate that this is really an implementation detail of copy, not something the rest of the standard library intends to use directly. Removed and clarified some of the comments as requested by Casey Carter. * Extract _Copy_n_core which implements copy_n using only the core language (rather than memcpy-as-an-intrinsic). Note that we cannot use __builtin_memcpy or similar to avoid the is_constant_evaluated check here; builtin_memcpy only works in constexpr contexts when the inputs are of type char. numeric: Refactor as suggested by microsoftGH-414.
* Implement constexpr algorithms. Resolves GH-6 ( P0202R3 ), resolves GH-38 ( P0879R0 ), and drive-by fixes GH-414. Everywhere: Add constexpr, _CONSTEXPR20, and _CONSTEXPR20_ICE to things. skipped_tests.txt: Turn on all tests previously blocked by missing constexpr algorithms (and exchange and swap). Mark those algorithms that cannot be turned on that we have outstanding PRs for with their associated PRs. yvals_core.h: Turn on feature test macros. xutility: * Move the _Ptr_cat family down to copy, and fix associated SHOUTY comments to indicate that this is really an implementation detail of copy, not something the rest of the standard library intends to use directly. Removed and clarified some of the comments as requested by Casey Carter. * Extract _Copy_n_core which implements copy_n using only the core language (rather than memcpy-as-an-intrinsic). Note that we cannot use __builtin_memcpy or similar to avoid the is_constant_evaluated check here; builtin_memcpy only works in constexpr contexts when the inputs are of type char. numeric: Refactor as suggested by GH-414. * Attempt alternate fix of GH-414 suggested by Stephan. * Stephan product code PR comments: * _Swap_ranges_unchecked => _CONSTEXPR20 * _Idl_dist_add => _NODISCARD (and remove comments) * is_permutation => _NODISCARD * Add yvals_core.h comments. * Delete unused _Copy_n_core and TRANSITION, DevCom-889321 comment. * Put the comments in the right place and remove phantom braces.
P0202R3
constexpr
For<algorithm>
Andexchange()
LWG-3256 Feature testing macro for
constexpr
algorithmsThis needs #156is_constant_evaluated()
.Feature-test macro as of WG21-N4842:
#define __cpp_lib_constexpr_algorithms 201703L
#define __cpp_lib_constexpr_algorithms 201806L
The text was updated successfully, but these errors were encountered: