Require exact return-type matches in generated protocol concepts (1/20) - #101
Require exact return-type matches in generated protocol concepts (1/20)#101jbcoe wants to merge 1 commit into
Conversation
9ef84ae to
168aa68
Compare
|
I think whether or not this is the right direction depends on what double f() { return 1.5; }
int main() {
return std::function<int()>{f}(); // OK, returns 1
}But virtual functions do not. They do allow covariant returns, though: struct A {
virtual A& foo() = 0;
};
struct B : A {
B& foo() override; // OK
};Which might be analogous to: struct Interface {
protocol_view<Interface> foo();
};
struct S {
S& foo();
};What is the rationale here for |
|
For now I'm keen to implement what's in the DRAFT.md and this is one area that we've been explicit about: Relaxed structural subtyping We require a type to have exactly matching function signatures as With some suitably compelling motivation, conformance via implicit conversions could be The strongest argument for picking this option is that it's the one that lets us change our minds later without breaking code. This approach served us well for indirect and polymorphic. With suitable motivation, I'm happy to change this part of the design, but we should land the reflection implementation of DRAFT first. I raised #121 to track this. |
protocol.j2's generated concepts used std::convertible_to<R>, letting merely-convertible return types conform; switched to std::same_as<R> per DRAFT.md's exact-match design. CovariantBImpl no longer conforms to B and moves from a dispatch test to a negative static_assert.
168aa68 to
c851094
Compare
That makes a lot of sense, thank you! |
protocol.j2's generated concepts used std::convertible_to, letting
merely-convertible return types conform; switched to std::same_as
per DRAFT.md's exact-match design. CovariantBImpl no longer conforms
to B and moves from a dispatch test to a negative static_assert.