Skip to content

Implement ranges::is_permutation - #892

Merged
Stephan T. Lavavej (StephanTLavavej) merged 14 commits into
microsoft:masterfrom
CaseyCarter:is_perm
Jun 24, 2020
Merged

Implement ranges::is_permutation#892
Stephan T. Lavavej (StephanTLavavej) merged 14 commits into
microsoft:masterfrom
CaseyCarter:is_perm

Conversation

@CaseyCarter

@CaseyCarter Casey Carter (CaseyCarter) commented Jun 11, 2020

Copy link
Copy Markdown
Contributor

Includes implementation of concepts indirect_equivalence_relation and indirect_strict_weak_order, and new <xutility> helper _Find_last_iterator(first, last, count) which - given [first, last) of length count - returns the iterator that corresponds to last.

Drive-by:

  • Move std::is_permutation from <xutility> into <algorithm>, leaving behind the _Check_match_counts helper which is used elsewhere in the STL.
  • Allow clang-format to handle the algorithm result types since they now have no requires-clauses.

Partially addresses #39.

Includes implementation of concepts `indirect_equivalence_relation` and `indirect_strict_weak_order`, and new `<xutility>` helper `_Find_last_iterator(first, last, count)` which - given `[first, last)` of length `count` - returns the iterator that corresponds to `last`.

Drive-by:
* Move `std::is_permutation` from `<xutility>` into `<algorithm>`, leaving behind the `_Check_match_counts` helper which is used elsewhere in the STL.
* Allow clang-format to handle the algorithm result types since they now have no requires-clauses.
@CaseyCarter Casey Carter (CaseyCarter) added the cxx20 C++20 feature label Jun 11, 2020
@CaseyCarter
Casey Carter (CaseyCarter) requested a review from a team as a code owner June 11, 2020 23:23
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever i see is_permutation i cringe about the cost involved. That said the code is great!

Comment thread stl/inc/algorithm
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/xutility Outdated
Comment thread tests/std/tests/P0896R4_ranges_alg_is_permutation/test.cpp Outdated
libc++ `unordered_meow` tests were assuming that `#include <unordered_meow>` makes `std::is_permutation` available.

Drive-by: Inline 4-argument `_Is_permutation_unchecked` into `is_permutation` since this `_unchecked` overload isn't used elsewhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked at the is_permutation algorithm before -- nifty 😄

Comment thread stl/inc/xutility Outdated
Comment thread stl/inc/xutility Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread tests/std/tests/P0896R4_ranges_alg_is_permutation/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_ranges_alg_is_permutation/test.cpp Outdated
Comment thread stl/inc/xutility Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm Outdated
Comment thread stl/inc/algorithm
Comment thread tests/std/tests/P0896R4_ranges_algorithm_machinery/test.cpp
Comment thread tests/std/tests/P0896R4_ranges_alg_is_permutation/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_ranges_alg_is_permutation/test.cpp
Comment thread stl/inc/algorithm Outdated
Comment thread tests/std/tests/P0896R4_ranges_alg_is_permutation/test.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test coverage looks great!

Comment thread stl/inc/algorithm
Comment thread tests/std/tests/P0896R4_ranges_alg_is_permutation/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_ranges_alg_is_permutation/test.cpp Outdated
Co-authored-by: mnatsuhara <46756417+mnatsuhara@users.noreply.github.com>
... with `_STL_INTERNAL_STATIC_ASSERT` when we don't want to pay the throughput cost of constraints.
Comment thread stl/inc/xutility
@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 70d23a1 into microsoft:master Jun 24, 2020
@StephanTLavavej

Copy link
Copy Markdown
Member

!ahknsT😸

@CaseyCarter
Casey Carter (CaseyCarter) deleted the is_perm branch June 24, 2020 13:30
ahanamuk pushed a commit to ahanamuk/STL that referenced this pull request Jul 1, 2020
Co-authored-by: mnatsuhara <46756417+mnatsuhara@users.noreply.github.com>
Co-authored-by: Stephan T. Lavavej <stl@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cxx20 C++20 feature ranges C++20/23 ranges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants