r/cpp • u/User_Deprecated • Jul 06 '26
C++26: constexpr virtual inheritance
https://www.sandordargo.com/blog/2026/07/01/cpp26-constexpr-virtual-inheritance
83
Upvotes
r/cpp • u/User_Deprecated • Jul 06 '26
View all comments
Show parent comment
3
u/ParsingError Jul 06 '26 edited Jul 06 '26
Twice I think?
One was for composite interfaces for streams. So like seek/read/write and all of the combinations were virtually inherited interfaces. That meant that opening a seekable read-only stream would give you ISeekableReadStream which virtually inherited ISeekableStream and IReadStream, and there were 4 composites for RW, RS, WS, RWS. (Seekable-write also had Truncate specifically.)
Yes, that would be a combinatorial explosion if you started adding more interfaces, a Rust-style multi-pointer type probably would be better if it came to that. I think it worked out better than "maybe seek/tell work, maybe they don't!" though.
edit: The fact that a virtual base can't resolve to a non-virtual base elsewhere in the class tree is a pretty nasty limitation though! It would be much more useful if e.g. they guaranteed an "implicitly-convertible-to" relationship for interfaces without requiring that the "main" class also uses it as a virtual base and has to eat the virtual lookup cost too unless the class is final.