Apologies, I did not see your question in time. Note that valarray is just a standard API, an implementer can write it as they wish. That said, these kinds of optimizations were indeed a motivation for creating valarray. Standard libraries do use exactly these optimizations in valarray (with some SIMD vectorization thrown in as well). You can also take a look at pixelglow's implementation, he has a comment downstream. It is pity that no one in the standards committee took ownership of valarray and it was included in a semi broken state.