|
|
|
|
|
by AlexanderDhoore
1040 days ago
|
|
In Rust each crate can be compiled with a different edition. If we had this in C++ you could compile one file/module with C++11 and another with C++20. The compiler defaults could change for new code, but be kept the same for old code. Nothing breaks. You opt-in to the new standard one file/module at the time. |
|
I'm not 100% confident but I think you can do this already*. What you can't do, is compile each file with a different compiler or stdlib release.
There's just no reason to do it because C++11 and C++20 are forwards and backwards compatible, so you might as well compile everything with C++20 if you're already going to compile it all from source.
* An exception is omnibus libraries like abseil that take it upon themselves to backport stdlib features to older language versions. For example, abseil uses typedefs to define e.g. absl::optional as std::optional on newer versions or a custom implementation on older versions. If you compile abseil with C++11 and your client code with C++20, then you may end up with scary runtime errors (not compiletime, because templates are compiled in every translation unit, and not linktime, because the linker ignores types).