-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
matching a non-constable value #1553
Comments
This is one of the cases where However, you should be really careful with things that are mutated during matching, because they can easily break if you try to chain multiple matchers in a single assertion. As for the future, we will see what we can do about this -- there already is a problem with using |
Thanks. A reference_wrapper is a nice idea. It already compiles, I'm just working on making sure the output stays the same from the builtin matchers. |
Hard to say from that description alone, you might want to open up a PR that highlights the intended changes so you don't waste time if there are problems. Note that the Matchers interface is subject to the usual backward compatibility guarantees, so it would have to go into v3.0 either way. |
PR #1554 opened. Is there a time estimation for 3.0? |
Now that v3.0 is a thing, I've rebased the PR on dev-v3. Can you please review it now? |
Yeah, sorry for not returning to you sooner on the issue. I had some misgivings about the fact that your proposed PR is a breaking change to all already existing matchers. Meanwhile, back in October @melak47 offered an alternative design seen in #1843, that allows keeping the old matchers while forward extending them with templated ones. Would the design in #1843 work for what you want to do? |
It would work but the performance will be much worse because of virtual functions and type erasure in #1843 .
using @melak47 solution takes 3.57s and with mine 0.27s. The test
takes 8.54s using @melak47 's solution and 2.25s with mine. I'll try to change my PR to be non-breaking as I understand it's a big issue. |
Can you also try creating the composed matcher outside the loop? Right now it uses vector (which implies allocations) to avoid compiling differently sized arrays. |
The overhead in my PR does indeed seem to come from using vectors. The results for your heavier test case on my machine: I imagine the remaining difference comes from you actually storing matchers in a tuple, while I only store pointers to the matchers (like the existing MatchAllOf in master). |
It's a problem to store a pointer if the matcher is temporary. I stored
references at first but it had the same problem.
…On Mon, Feb 10, 2020, 02:20 melak47 ***@***.***> wrote:
The overhead in my PR does indeed seem to come from using vectors.
I tried using arrays instead, which did not have as much of an impact on
compile times as I expected (it actually seems to compile faster...).
The results for your heavier test case on my machine:
crtp: 2.51s, virtuals & vectors: 4.51s, virtuals & arrays: 1.48s
I imagine the remaining difference comes from you actually storing
matchers in a tuple, while I only store pointers to the matchers (like the
existing MatchAllOf in master).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1553?email_source=notifications&email_token=AB2ORDIE6QPZ6C7NVB52IQ3RCCMWJA5CNFSM4G2SXRKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELG4Z3A#issuecomment-583912684>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB2ORDNPMSSUKWRVF3NUQQDRCCMWJANCNFSM4G2SXRKA>
.
|
Well, storing by value isn't working for classes deriving from |
Storing around just references (well, pointers) in the composed matchers is intentional and I intend to keep it around. @melak47 Can you try to benchmark the differences in compilation times between using |
measured on windows: clang, msvc, gcc, |
Actually, those measurements were release builds, so maybe not entirely fair comparing compile times. This time just debug builds:
These are the sources used for this test, run time was measured for test case "b" (although they are all over the place, maybe not fair to compare debug builds' run times): https://gist.github.com/melak47/8d8429c102fda933ce98dca31cb400fc |
So, to sum it up, there are currently 3 options for the new Matchers:
As far as I can see, they can be summed as CRTPs
vectors
arrays
Given that the vector backed approach is only slightly faster to compile This leaves arrays and CRTPs, and given that the runtime advantage of CRTPs @dvirtz I am sorry your work will end up being thrown away, but I think |
The CRTP PR doesn't actually breaks compatibility anymore. I agree that compile time is not great though. |
This commit extends the Matchers feature with the ability to have type-independent (e.g. templated) matchers. This is done by adding a new base type that Matchers can extend, `MatcherGenericBase`, and overloads of operators `!`, `&&` and `||` that handle matchers extending `MatcherGenericBase` in a special manner. These new matchers can also take their arguments as values and non-const references. Closes #1307 Closes #1553 Closes #1554 Co-authored-by: Martin Hořeňovský <[email protected]>
Description
I'm trying to match a range-v3 view which cannot be const as it mutates its state during iteration. The problem is that matchers accept their input by const reference only.
Is it possible to add additional overload which will accept the parameter by value? Or do you have any other suggestion?
Additional context
Version 2.6.0
The text was updated successfully, but these errors were encountered: