-
Notifications
You must be signed in to change notification settings - Fork 152
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 support for proxy_view
and complementary infrastructure
#218
Conversation
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.
Thanks for the implementation!
In general, this is what I expected.
I think there can be some additional tests on the behaviors about const:
- const view from const proxy
const pro::proxy<TestFacade> p1 = ...;
pro::proxy_view<const TestFacade> p2 = p1;
- const view from non const view
pro::proxy_view<TestFacade> p1 = ...;
pro::proxy_view<const TestFacade> p2 = p1;
- const view from const raw
const int a = 0;
pro::proxy_view<const TestFacade> p = &a;
A small question: what is the consideration that the view needs to be explicitly added for each facade? Reducing compilation time and binary size? Avoiding misuses?
@Shuenhoy Thank you for the comments. I added another 2 cases to cover the independent use of However, I am hesitant to implement conversion from a non-const view to a const view. Consider the following case: #include <cstdio>
#include "proxy.h"
PRO_DEF_MEM_DISPATCH(MemFoo, Foo);
struct FooFacade : pro::facade_builder
::add_convention<MemFoo, void(), void() const>
::add_view<FooFacade>
::add_view<const FooFacade>
::build {};
struct MyFoo {
void Foo() {}
};
int main() {
MyFoo foo;
pro::proxy<FooFacade> p1 = &foo; // OK
pro::proxy_view<FooFacade> p2 = p1; // OK, equivalent to p2 = &foo
pro::proxy_view<const FooFacade> p3 = std::as_const(p1); // OK, equivalent to p3 = &foo
// If p3 = p2 is defined to be equivalent to the following line of code, it won't compile.
// Therefore, I prefer not to define the conversion from proxy_view<F> proxy_view<const F>.
// p3 = &std::as_const(foo);
} Requiring explicit |
Thanks for the clarification.
My understanding is that the root issue stems from that |
Suggest adding benchmark cases to see the perf of |
@tian-lt I added benchmarks for |
I think the gap here is that for a raw pointer
In general, I do not think there is a very good way to define the conversion from |
Changes
observer_facade<F>
for observing aproxy<F>
via a raw pointer.proxy_view<F> = proxy<observer_facade<F>>
.add_view<F>
inbasic_facade_builder
to allow implicit conversion fromproxy<F>
toproxy_view<F>
orproxy_view<const F>
.