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

RangeEquals doesn't support literal std::initializer_list #2915

Closed
stk-ableton opened this issue Oct 8, 2024 · 2 comments · Fixed by #2919
Closed

RangeEquals doesn't support literal std::initializer_list #2915

stk-ableton opened this issue Oct 8, 2024 · 2 comments · Fixed by #2919

Comments

@stk-ableton
Copy link

It would often be useful to write something like this:

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

This doesn't compile. It can be made to compile by adding an overload to RangeEquals that takes a std::initializer_list. Would a PR adding such an overload have a chance of being accepted?

It's not a huge issue since there are workarounds, including any of these:

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

  CHECK_THAT(v, RangeEquals(std::vector{1, 2, 3}));

  CHECK_THAT(v, RangeEquals(std::initializer_list<int>{1, 2, 3}));

Still, the convenience of writing the initializer_list inline without extra qualification would be nice.

@horenmar
Copy link
Member

Sure, why not.

stefanhaller pushed a commit to stefanhaller/Catch2 that referenced this issue Oct 12, 2024
…r_list

This allows writing something like

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

Fixes catchorg#2915.
stefanhaller pushed a commit to stefanhaller/Catch2 that referenced this issue Oct 12, 2024
…r_list

This allows writing something like

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

Fixes catchorg#2915.
stk-ableton pushed a commit to stk-ableton/Catch2 that referenced this issue Oct 12, 2024
…r_list

This allows writing something like

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

Fixes catchorg#2915.
@stk-ableton
Copy link
Author

See #2919.

stk-ableton pushed a commit to stk-ableton/Catch2 that referenced this issue Oct 13, 2024
…r_list

This allows writing something like

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

Fixes catchorg#2915.
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants