Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's true, although Rust provides for sound enforcement (so if you try to alias the equivalent of two restrict pointers the compiler will catch it at compile time).

(It's also not technically in C++, although in practice it can be achieved through extensions.)



C++'s standard library has valarray, which is supposed to avoid aliasing effects, and is allowed to use expression templates and other tricks. Something like:

    float dot(std::valarray<float> const& x)
    {
        return (x*x).sum();
        // Alternative: inner_product(begin(x), end(x), begin(x), 0.0f);
    }
should, in theory, achieve the same kind of performance as the C version (but none of this is guaranteed, sadly). A smart implementation would actually end up calling BLAS routines, which is what libraries like Eigen do.

Which reminds me: does Rust have infrastructure that would allow something like expression templates to exist?


I believe you can use Rust traits to the same effect, although I haven't tried so you might hit stuff.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: