What I want is a possiblility to generate a 5x5 matrix via a brace-enclosed initializer list. So that it may look later like:
enum class MyListType {
EMPTY,
A
};
auto matrix = {
{MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY},
{MyListType::A, MyListType::A, MyListType::A, MyListType::A, MyListType::A},
{MyListType::A, MyListType::A, MyListType::A, MyListType::A, MyListType::A},
{MyListType::A, MyListType::A, MyListType::A, MyListType::A, MyListType::A},
{MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY}
};
auto somthing = std::make_shared<Matrix5T>(matrix);
For that I have now my Matrix5T class, which works at the moment only for vectors:
class Matrix5T
{
public:
Matrix5T(std::initializer_list<MyListType> matrixIn)
: matrix(std::make_shared<std::vector<MyListType> >(matrixIn))
{}
virtual ~TileMatrix() = default;
private:
std::shared_ptr<std::vector<MyListType> > matrix;
}
So I can do the following:
auto matrix = {
MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY,
MyListType::A, MyListType::A, MyListType::A, MyListType::A, MyListType::A,
MyListType::A, MyListType::A, MyListType::A, MyListType::A, MyListType::A,
MyListType::A, MyListType::A, MyListType::A, MyListType::A, MyListType::A,
MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY, MyListType::EMPTY
};
auto somthing = std::make_shared<Matrix5T>(matrix);
At the moment I don't find a solution to have a multidimensional vector in my class initialized by a multidimensional brace-enclosed initializer list.
I tried for example the following, which results in errors:
class Matrix5T
{
public:
Matrix5T(std::initializer_list<std::initializer_list<MyListType> > matrixIn)
: matrix(std::make_shared<std::vector<std::vector<MyListType> > >(matrixIn))
{}
virtual ~TileMatrix() = default;
private:
std::shared_ptr<std::vector<std::vector<MyListType> > > matrix;
}
Error is saying that the conversion from the initializer list to the multidimensional vector does not work:
no known conversion for argument 1 from ‘std::initializer_list<std::initializer_list<MyListType> >’ to ‘const std::vector<std::vector<MyListType> >&’
So how can I fix this?
Aucun commentaire:
Enregistrer un commentaire