After reading this http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00123.html, it seems that using a valarray of valarrays is not guaranteed by the standard to be safe. But when I read the list of requirements (http://en.cppreference.com/w/cpp/numeric/valarray) for T in valarray, it seems that T=valarray<built-in type> satisfy all of them. Is valarray<valarray<built-in type> > safe?
No, it's not safe.
In particular, valarray can throw1 under some circumstances (e.g., see §26.6.1/6), but if the type you put into a valarray throws (ever), you get undefined behavior (§26.2/2).
It's mostly unnecessary anyway. valarray supports 2D addressing via slices.
1. Note: it's allowed to throw, but never directly required to do so. At the same time, many operations on non-const valarrays are required to return entire an entire new valarray, which involves dynamic allocation. If that fails, there seems to be little choice but to throw an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With