Allow users to provide a templated overload of PrintTo #3682
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's currently not possible to provide an overload of
PrintTo
for all the types supporting a specific conceptbecause this is as constrained as the fallback implementation defined in gtest, so the compiler considers them ambiguous.
With this change, gtest doesn't define a fallback implementation of
PrintTo()
, but instead checks if one is callable, and if it doesn't uses the fallback behaviour.This change addresses #3674 and it's largely backward compatible.
These are the situations in which this is not backward compatible
T
, there is aPrintTo
for typeQ
,T
is convertible toQ
.Before: fallback behaviours, After:
PrintTo(Q)
There is a way to be fully backward compatible, but the implementation is more complicated (it involves simulating the old behaviour to detect whether the fallback or PrintTo would have been called), so I'm proposing this change first