1

Old c-style static arrays can be quite bothersome when passed as arguments, or returned as value. For that, the new std::array is quite convenient.

However for multi-array, there is nothing in std:: and the boost::multi_array isn't just statically allocated.

Of course, I could do, say,

std::array<std::array<int,3>,2> my_array;

but I find sligthly long and it corresponds to the inverted built-in declaration

int my_array[2][3];

I am just wondering if there is already some "library" coding such a concept (bi-dimensional or any-dimensional)

(which for the latter, if I am correct, must use some variadic template for typing e.g.

multi_array<int,3,4> A;
multi_array<int,3,5,8> B;
multi_array<int,4,7,8,9,8,3> C; //this one being quite rare though

)

EDIT : sorry about the first post, I didn't test

2
  • "but then my_array[1][2] is not the same as in (...)" What do you mean? It is the same. Commented Sep 8, 2012 at 16:36
  • Yes I am sorry about that, I just was absolutely sure but didn't test (I know, I know..., it's bad) Commented Sep 8, 2012 at 16:58

1 Answer 1

0

It might be overkill for your application, but I have worked with the Eigen library and think it's family of Matrix template classes might work for you. An example:

Eigen::Matrix<float, 3, 2> a;
a(1,0) = 1.1;
a(0,1) = 17.5;

EDIT 1: Oops, I don't know for sure if it supports N-dimensional matrices. But for 2-dimensional ones I know it is good.

I think you can use typedefs, either with Eigen or with std::array, to make your types more readable.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I also think it's also too much for just an array without particular mathematical meaning. I am also doing linear algebra so this library could be useful however

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.