jeudi 25 janvier 2018

Use assignment operator with subscript operator to assign value to std::map

I have a Matrix class

template <typename T>
class Matrix
{
public:
  const size_t rows;
  const size_t cols;
  const std::map<std::array<int, 2>, T> data;

  Matrix(int a, int b) : rows(a), cols(b)
  {
  }
};

which is initialized like this:

Matrix<double> M(5,5);

creating a 5x5 matrix.

I want to assign values to the map like so:

M[{1,2}] = 1;

How would I go about doing that in the most readable way? I'm not sure how to get the subscript and assignment operator working together.

Aucun commentaire:

Enregistrer un commentaire