Flexible Array Member for 2D-Array

109 Views Asked by At

I am currently working on a big project involving repast_hpc and mpi. I wanted to implement a two dimensional shared (across processes) array, because repast_hpc itself does not seem to come with that. For that I need an array member of a class. However I do not know the size of the array at compile time. I need to be able to access and change the values in constant time. The code given below is my current header file, where the problem is located. How can I get a array member like the values in array in c++11?

template <typename Value>
class SharedValueField {
    private:
        Value[][] values;
        std::queue<ValueChangePackage<Value>> changes;
    public:
        void initializeValueChange(int x, int y, Value value);
        Value getValue(int x, int y);
        void update();
};

All help appreciated. Thanks! Tritos

I already tried using std::array. That has the same problems. I cant use std::vector, because they dont allow for constnt-time random element value manipulation.

1

There are 1 best solutions below

0
Tritos On

Using ‚std::vector‘ works after all. As explained by many people in the comments, only changing the size of the vector has time-complexity in O(n). I only need to reassign elements, which works fine.