Is there some reason we can’t replace our basic views with
something like the following. I know we had some writable vector
views, but can those be put into a different class?
- Bob
// wrap (scalar OR std::vector OR Eigen vector OR Eigen row
// vector) to present sequence of scalars
template
struct ScalSeqView { };
template
struct ScalSeqView {
const T& x_;
explicit SeqView(const T& x) : x_(x) { }
const T& operator[](int n) const { return x_; }
};
template
struct ScalSeqView<std::vector > {
const vector& xs_;
explicit SeqView(const vector& xs) : xs_(xs) { }
const T& operator[](int n) const { return xs_[n]; }
};
template
struct ScalSeqView<Matrix<T, 1, -1> > {
const Matrix<T, 1, -1>& xs_;
explicit SeqView(const Matrix<T, 1, -1>& xs) : xs_(xs) { }
const T& operator[](int n) const { return xs_[n]; }
};
template
struct ScalSeqView<Matrix<T, -1, 1> > {
const Matrix<T, -1, 1>& xs_;
explicit SeqView(const Matrix<T, -1, 1>& xs) : xs_(xs) { }
const T& operator[](int n) const { return xs_[n]; }
};
// wrap Eigen vector or std::vector of Eigen vector
// to produce Eigen vector; also works for Eigen row vectors
// and Eigen matrices
template <typename S, R, C>
struct MatrixSeqView { };
template <typename T, R, C>
struct MatrixSeqView<Matrix<T, R, C> > {
const Matrix<T, R, C>& x_;
explicit MatrixSeqView(const Matrix<T, R, C>& x) { x_(x); }
const Matrix<T, R, C>& operator[](int n) const { return x_; }
};
template <typename T, R, C>
MatrixSeqView<vector<Matrix<T, R, C> >, R, C>> {
const vector<Matrix<T, R, C> >& xs_;
MatrixSeqView(const vector<Matrix<T, R, C> >& xs) { xs_(xs); }
const Matrix<T, -1, -1>& operator[](int n) const { return xs_[n]; }
};