Support default implementation of a dispatch #79
Merged
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.
Changes
PRO_DEF_MEMBER_DISPATCH_WITH_DEFAULT
andPRO_DEF_FREE_DISPATCH_WITH_DEFAULT
to allow specifying an addition default implementation of a dispatch.PRO_DEF_COMBINED_DISPATCH
due to incompatibility of semantics.concept facade
andproxiable
: Before this change, implementation of a dispatch is required to provide overloads ofoperator()
, and a facade is required to be trivially default constructible. It is now required that a dispatchD
shall be trivially default constructible, and shall modeltypename D::template invoker<...>
.proxy
will try to instantiateinvoker
withtarget-type-of<P>
(implemented aspro::details::ptr_traits<P>::target_type
) and see if it is invocable in the context; otherwise,proxy
will try to fallback toinvoker<void>
without trying to dereference the pointer at runtime.ProxyInvocationTests.TestMemberDispatchDefault
andProxyInvocationTests.TestFreeDispatchDefault
(converted from previousProxyInvocationTests.TestCombinationWithIncompleteDispatch
) to cover this change.Validation
Except for the correctness of the two new macros that can be covered with unit tests, the ultimate goal of this change is to generate better code for default implementation of a dispatch. This has been verified by inspecting the generated code before and after this change.
We came up with the following test code:
It models a basic container that has a member function
size()
, while throw an exception if it is invoked on an unsupported type. Here is the generated code (link).We can see the code for the exception path was duplicated for every type that does not have member function
size()
. With this change, we can usePRO_DEF_MEMBER_DISPATCH_WITH_DEFAULT
instead, with simpler syntax and better code generation (link).Closes #78