The enum is a fantastic feature of Rust. It is similar to a tagged union (just like std::variant<>
in C++), but Rust provides a lot of optimizations for enums.
In this project, I will try to implement Rust's enum in C++. I will implement my own variant
step by step and apply some optimizations. Of course, I can't apply all the optimizations Rust does to enum to my variant
, because some of them require help from the compiler.
My steps are as follows:
- Implement
std::variant<>
introduced in C++17, but without too many optimizations. - Optimize for fundamental types and reference types.
- Optimize for class types and tuple.
- Optimize for
variant<>
types. - Try implementing it with C++11 or C++14.
- ...