-
Notifications
You must be signed in to change notification settings - Fork 392
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
Iox #27 add typed client and server api [stacked PR #5] #1089
Conversation
526053c
to
9185db9
Compare
6c5053a
to
eec32b3
Compare
cafa071
to
23359fb
Compare
6eaf3c7
to
5510a8b
Compare
23359fb
to
f346fb0
Compare
5510a8b
to
b3202dd
Compare
f346fb0
to
1cbc765
Compare
b3202dd
to
877a24c
Compare
1cbc765
to
601edf6
Compare
c2d4ecc
to
19ee1af
Compare
891b47e
to
e74429c
Compare
edd8b95
to
08f6def
Compare
fe7160b
to
06ec79d
Compare
08f6def
to
43d6216
Compare
06ec79d
to
7d1265d
Compare
43d6216
to
b74bb56
Compare
template <typename Req, typename Res, typename BaseServerT = BaseServer<>> | ||
class ServerImpl : public BaseServerT, public RpcInterface<Response<Res>> | ||
{ | ||
static_assert(!std::is_void<Req>::value, "The type `Req` must not be void. Use the UntypedServer for void types."); |
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.
You have here and in ClientImpl
some code duplication. What about introducing a HeaderConcept
like:
template <typename T>
struct HeaderConcept {
static_assert(!std::is_void<T>::value, "Must not be void");
static_assert(!std::is_const<T>::value, "Must not be const");
static_assert(!std::is_reference<T>::value, "Must not be a reference");
static_assert(!std::is_pointer<T>::value, "Must not be a pointer");
using Evaluate = void; // required and has to be used with typename HeaderConcept<int>::Evaluate otherwise the compiler ignores the static_assert's
};
And use it like:
template <typename Req, typename Res, typename BaseServerT = int,
typename RequiresForRequest = typename HeaderConcept<Req>::Evaluate,
typename RequiresForResponse = typename HeaderConcept<Res>::Evaluate>
class ServerImpl {};
Then one would see that a header concept is required (looks a bit like C++20), if something changes we have only one piece of code we have to adjust and not 4 different pieces.
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.
@elfenpiff Looks interesting. Can be extended with checks for specific members etc. in the concept should this be needed (with SFINAE). I just do not like the need to introduce artificial template args for this (as with other meta-programming e.g. enable_if
) which are not really supposed to be used apart from the default values.
I think it is possible/better to transfer the aggregated condition value to some internal bool, i.e. basically create a type trait for headers. Then we can static_assert
on this as before, like
static_assert(HeaderConcept<MyHeader>::value, "concept not satisfied");
I leave out the details, but its basically a constexpr bool value = ...
on your conditions above.
Then we do not have artificial template args.
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.
@elfenpiff this might be tricky since the asserts have subtle variations
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.
@elfenpiff after a closer look, forget what I wrote
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.
@elfenpiff I agree with @MatthiasKillat to not add additional template args so I adjusted your proposal a bit.
f29ff6d
to
8a14544
Compare
04cde7d
to
128cb6f
Compare
8a14544
to
2afc558
Compare
078ac6a
to
b02a50f
Compare
static_assert(!std::is_const<H>::value, "The user-header `H` must not be const."); | ||
static_assert(!std::is_reference<H>::value, "The user-header `H` must not be a reference."); | ||
static_assert(!std::is_pointer<H>::value, "The user-header must `H` not be a pointer."); | ||
using DataTypeAssert = typename TypedPortApiTrait<T>::Assert; |
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.
This works too to avoid template args (and we keep the fine grained errors of the static asserts).
780d83b
to
a0310be
Compare
Codecov Report
@@ Coverage Diff @@
## master #1089 +/- ##
==========================================
+ Coverage 76.19% 76.21% +0.01%
==========================================
Files 346 346
Lines 13595 13595
Branches 1938 1938
==========================================
+ Hits 10359 10361 +2
+ Misses 2604 2602 -2
Partials 632 632
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Pre-Review Checklist for the PR Author
iox-#123-this-is-a-branch
)iox-#123 commit text
)git commit -s
)task-list-completed
)Notes for Reviewer
This PR adds the typed API. The functionality is complete.
Test will be added in PR #1140
Checklist for the PR Reviewer
Post-review Checklist for the PR Author
References