For example, the following snippet compiles in VC++ 2010:
template<int Rows, int Columns = Rows>
struct Matrix { };
Matrix<4> m;
Note that the default argument for Columns depends on the argument value for Rows.
But is this standard behaviour in C++11 (or earlier) that I can rely on everywhere?
Yes. And as a matter of fact, it’s how tons of STL codes work.
the
std::vectorhas a definition like:so that you don’t need to specify the
allocatoreach time every time. If such is invalid, we won’t be able to write:And you would write
std::mapas:which is far less desirable than: