Rust for C++

Dispatch

Static dispatch

Rust
fn log<T: Figure>(figure: &T) {
    figure.print();
}

Run

C++
template <typename T>
void log(const T &figure) {
    static_assert(std::is_base_of<Figure, T>::value, 
      "It has to be a Figure");

    figure.print();
}

Run

Dynamic dispatch

Rust
fn log(figure: &Figure) {
    figure.print();
}

Run

C++
void log(const Figure &figure) {
    figure.print();
}

Run