Co- and Contra-: Adding a Little Variance
summary
Claims that C++ lacks principled co/contravariance and that practical emulation is possible but brittle: shows language examples (C#, Scala, Java using out/in), demonstrates function_ref emulation and container adapters that convert vectors of cats to views of animals by computing subobject offsets and reinterpret_casts, and cites a real Thrust case where Thrust device_vector unified memory causes page faults and motivates smart references. Emulations compile and work but incur runtime cost, complex edge cases (multiple inheritance, mutability) and unsafe casts; true language support would simplify and make them safer.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 0:36Polymorphism
- 8:55Variants
- 12:57Other languages
- 14:37Java
- 15:10Mutability
- 16:05Contravariance
- 18:29Java Annotating
- 21:06Reference Types
- 23:00Implementation
- 26:20C
- 27:10Smart References
related talks
01h 01mFunctional C++
01h 00mType punning in modern C++
22mCompilers should get over themselves and respect semantic dependencies!
01h 16mPolymorphism, Cohesion, and Coupling in C++
01h 23mThis is C++ - How to Use the C++ Superpower to Write Better C++ Code
01h 02mOn the benefits of non-intrusiveness
01h 35mC++20 – My Favourite Code Examples
52mNon-conforming C++: the Secrets the Committee Is Hiding From You
