+/** Construct a matrix from an 2 dimensional initializer list.
+ * Throws an exception if some row has a different length than all the others.
+ */
+matrix::matrix(std::initializer_list<std::initializer_list<ex>> l)
+ : row(l.size()), col(l.begin()->size())
+{
+ setflag(status_flags::not_shareable);
+
+ m.reserve(row*col);
+ for (const auto & r : l) {
+ unsigned c = 0;
+ for (const auto & e : r) {
+ m.push_back(e);
+ ++c;
+ }
+ if (c != col)
+ throw std::invalid_argument("matrix::matrix{{}}: wrong dimension");
+ }
+}
+
+// protected
+
+/** Ctor from representation, for internal use only. */
+matrix::matrix(unsigned r, unsigned c, const exvector & m2)
+ : row(r), col(c), m(m2)
+{
+ setflag(status_flags::not_shareable);
+}
+matrix::matrix(unsigned r, unsigned c, exvector && m2)
+ : row(r), col(c), m(std::move(m2))
+{
+ setflag(status_flags::not_shareable);
+}
+