-
Notifications
You must be signed in to change notification settings - Fork 370
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 compile-time checks w.r.t. is_primary
or existence of get_secondary_event()
#3027
base: master
Are you sure you want to change the base?
Conversation
25352a8
to
e217e3c
Compare
is_primary
or existance of get_secondary_event()
constexpr bool has_get_secondary_event = has_get_secondary_event_t< ConnectionT >::value; | ||
static_assert( | ||
is_primary xor has_get_secondary_event, "Non-primary connections have to provide get_secondary_event()" ); | ||
if constexpr ( ( not is_primary ) and has_get_secondary_event ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be sufficient to only check one of the conditions after the assert
Edit: if this was accidentally called on a primary event synapse, would it be possible to reach the nullptr? Would it be safer to provide an error message there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be sufficient, but also doesn't hurt to check for both at compile time, right?
is_primary
or existance of get_secondary_event()
is_primary
or existence of get_secondary_event()
constexpr bool has_get_secondary_event = has_get_secondary_event_t< ConnectionT >::value; | ||
static_assert( | ||
is_primary xor has_get_secondary_event, "Non-primary connections have to provide get_secondary_event()" ); | ||
if constexpr ( ( not is_primary ) and has_get_secondary_event ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be sufficient, but also doesn't hurt to check for both at compile time, right?
else | ||
{ | ||
// unreachable code | ||
return nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nullptr; | |
UnsupportedEvent( "Using secondary events on primary connections is not possible. Secondary connections must implement get_secondary_event!" ); |
@muffgaga Could you respond to the remarks in the code review? Also, could you merge master into your branch and fix the conflicts that have arisen since you created this PR? |
That is not a polished commit, but rather just a draft showing that some more compile-time checking of the interfaces is possible without any restructuring. (Cf. discussion in PR #2988).
IS_PRIMARY
property, we now can dropConnection::get_secondary_event()
, which could only be reached by illegal code.not IS_PRIMARY
and the existence of the derived Connection'sget_secondary_event
— and it provides a compile-time error message in cases where this isn't the case.