Skip to content

Commit

Permalink
Fixed bug in range_is_permutation
Browse files Browse the repository at this point in the history
  • Loading branch information
rollbear committed Sep 29, 2024
1 parent df560a2 commit 58fa05e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions include/trompeloeil/matcher/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,27 @@ struct is_permutation_checker
{
return false;
}
using element_type = typename std::remove_reference<decltype(*it)>::type;
std::vector<element_type*> values;
values.reserve(size);
for (auto& element : range)
{
values.push_back(&element);
}
bool all_true = true;
const auto match = [&](const auto& compare)
{
return std::any_of(it, e, [&](const auto& v){
return trompeloeil::param_matches(compare, std::ref(v));
});
auto found = std::find_if(values.begin(), values.end(),
[&compare](const element_type* p){
return trompeloeil::param_matches(compare, std::ref(*p));
});
if (found != values.end())
{
*found = values.back();
values.pop_back();
return true;
}
return false;
};
trompeloeil::ignore(std::initializer_list<bool>{
(all_true = all_true && match(elements)) ...});
Expand Down

0 comments on commit 58fa05e

Please sign in to comment.