Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Provide overloads for {Unordered}RangeEquals taking a std::initializer_list #2919

Merged

Conversation

stk-ableton
Copy link

This allows writing something like

  const auto v = calculateSomeVectorOfInts();
  CHECK_THAT(v, RangeEquals({1, 2, 3}));

Fixes #2915.

Copy link

codecov bot commented Oct 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.99%. Comparing base (fa43b77) to head (ef2f8fb).
Report is 3 commits behind head on devel.

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #2919   +/-   ##
=======================================
  Coverage   90.99%   90.99%           
=======================================
  Files         198      198           
  Lines        8597     8597           
=======================================
  Hits         7822     7822           
  Misses        775      775           

template <typename T>
constexpr
UnorderedRangeEqualsMatcher<std::initializer_list<T>, std::equal_to<>>
UnorderedRangeEquals( std::initializer_list<T> range ) {
Copy link
Member

Choose a reason for hiding this comment

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

I see that this copies the old overloads, but I wonder why I went with overloads instead of defaulted comparison parameter back then.

Copy link
Author

Choose a reason for hiding this comment

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

I wondered the same, but was reluctant to change it. Now that you mention it, I added a commit (before mine) to clean this up: 5328f90. Sorry for force-pushing, but I didn't want to put a commit on top that changes it both for the existing code and the new overloads; the diffs are much cleaner this way.

Copy link
Member

@horenmar horenmar left a comment

Choose a reason for hiding this comment

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

I am going to look into the overload vs default argument a bit later, but the PR looks good.

Stefan Haller added 2 commits October 13, 2024 10:15
…ed}RangeEquals

Saves some code duplication.
…r_list

This allows writing something like

  const auto v = calculateSomeVectorOfInts();
  CHECK_THAT(v, RangeEquals({1, 2, 3}));

Fixes catchorg#2915.
@stk-ableton stk-ableton force-pushed the support-initializer-list-with-RangeEquals branch from 1c6a187 to ef2f8fb Compare October 13, 2024 08:21
@horenmar horenmar merged commit 69d62ab into catchorg:devel Oct 14, 2024
77 checks passed
@horenmar
Copy link
Member

The default args should be fine here. The usual arguments against should not apply to this use case.

Thanks for the change.

@horenmar horenmar added the Tweak label Oct 14, 2024
@stk-ableton stk-ableton deleted the support-initializer-list-with-RangeEquals branch January 22, 2025 16:44
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RangeEquals doesn't support literal std::initializer_list
2 participants