-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Add MockFunction support for std::function #2277
Comments
I was just thinking today that it would be nice to have support for instantiating something like |
You can use the |
@sbenzaquen, I hoped this will be the first to change to make user-extensions easier! :) While consistency is important I think that adapting all cases at once is not practical and would be difficult to review. None the less - if that would be yes-or-no then I will try to adapt other cases as well. We can also skip documenting the Finally, I can adapt the change to cover While you are right that the Why not make it easier for the user? After all the |
Add tests checking that ::testing::MockFunction template argument can be deduced in a function call context. This is a property raised in the review, however, not checked before by any tests.
Add tests checking that ::testing::MockFunction template argument can be deduced in a function call context. This is a property raised in the review, however, not checked before by any tests.
Add tests checking that ::testing::MockFunction template argument can be deduced in a function call context. This is a property raised in the review, however, not checked before by any tests.
Add tests checking that ::testing::MockFunction template argument can be deduced in a function call context. This is a property raised in the review, however, not checked before by any tests.
Add tests checking that ::testing::MockFunction template argument can be deduced in a function call context. This is a property raised in the review, however, not checked before by any tests.
Add tests checking that ::testing::MockFunction template argument can be deduced in a function call context. This is a property raised in the review, however, not checked before by any tests.
Add tests checking that ::testing::MockFunction template argument can be deduced in a function call context. This is a property raised in the review, however, not checked before by any tests.
Looks like this is fixed by #2350. |
@akonradi, yes, it is. Thanks for the reminder, I'm closing this. |
MockFunction
requires function signatureR(Args...)
as its template argument. This makes it difficult to use it withstd::function
hidden under some type name.std::function
doesn't provide any member type to allow to (safely and easily) reflect its own arguments (the signature).The problem shows when we want to refer to
std::function
through its type name like:Now, we cannot do
::testing::MockFunction<my_callback>
. We have to do::testing::MockFunction<bool(int)>
, which is a maintenance issue requiring us to repeat the type definition.Below is my proposal to add the support:
The solution is based on the introduction of
SignatureOf
meta-function which translates types provided toMetaFunction
into function signature. This allows to supportstd::function
and could be later easily extended further, including user extending it with user-types. (boost::function
andfolly::Function
being good examples of extension candidates.)The meta-function based solution as compared to a more classic approach of specialization also avoids the choice between duplicating code or using inheritance, which then creates an issue of
virtual
destructor.The text was updated successfully, but these errors were encountered: