Skip to main content
deleted 207 characters in body
Source Link
Incomputable
  • 9.6k
  • 3
  • 33
  • 72

pow is not constexpr

pow is not constexpr, and the current behavior relies on particular compiler. You'll need constexpr function to calculate the power.

Weird interface

I'd suggest implementing plain operator[] that will return some inner type which will represent a slice of next dimension. Iterators might be ambiguous here in terms of concepts.

Potentially dangerous implementation

Users of the class will need to store the MultiArray on free store to ensure they don't overflow the stack (I know some compilers extend it during runtime, but it is still non-standard). I recommend using vector instead.

Interface

When using std::vector, need for templated size arguments disappears. It would be possible to templatize on allocator instead, defaulting to std::allocator<T>. The sizes could be passed on constructor call.

Subscript operator

That's going to be an issue, but it is easily solvable. Just make it

T& operator[](const std::initializer_list<std::size_t> indices)
{
    //use math to calculate the index
}

You'll also need const version. Input type may be different, but it should also check if the number of elements inside match the dimension count. You could templatize sizes still, so that this one can be replaced with const std::array<std::size_t, DimensionCount>&.

pow is not constexpr

pow is not constexpr, and the current behavior relies on particular compiler. You'll need constexpr function to calculate the power.

Weird interface

I'd suggest implementing plain operator[] that will return some inner type which will represent a slice of next dimension. Iterators might be ambiguous here in terms of concepts.

Potentially dangerous implementation

Users of the class will need to store the MultiArray on free store to ensure they don't overflow the stack (I know some compilers extend it during runtime, but it is still non-standard). I recommend using vector instead.

Interface

When using std::vector, need for templated size arguments disappears. It would be possible to templatize on allocator instead, defaulting to std::allocator<T>. The sizes could be passed on constructor call.

Subscript operator

That's going to be an issue, but it is easily solvable. Just make it

T& operator[](const std::initializer_list<std::size_t> indices)
{
    //use math to calculate the index
}

You'll also need const version. Input type may be different, but it should also check if the number of elements inside match the dimension count. You could templatize sizes still, so that this one can be replaced with const std::array<std::size_t, DimensionCount>&.

pow is not constexpr

pow is not constexpr, and the current behavior relies on particular compiler. You'll need constexpr function to calculate the power.

Potentially dangerous implementation

Users of the class will need to store the MultiArray on free store to ensure they don't overflow the stack (I know some compilers extend it during runtime, but it is still non-standard). I recommend using vector instead.

Interface

When using std::vector, need for templated size arguments disappears. It would be possible to templatize on allocator instead, defaulting to std::allocator<T>. The sizes could be passed on constructor call.

Subscript operator

That's going to be an issue, but it is easily solvable. Just make it

T& operator[](const std::initializer_list<std::size_t> indices)
{
    //use math to calculate the index
}

You'll also need const version. Input type may be different, but it should also check if the number of elements inside match the dimension count. You could templatize sizes still, so that this one can be replaced with const std::array<std::size_t, DimensionCount>&.

Source Link
Incomputable
  • 9.6k
  • 3
  • 33
  • 72

pow is not constexpr

pow is not constexpr, and the current behavior relies on particular compiler. You'll need constexpr function to calculate the power.

Weird interface

I'd suggest implementing plain operator[] that will return some inner type which will represent a slice of next dimension. Iterators might be ambiguous here in terms of concepts.

Potentially dangerous implementation

Users of the class will need to store the MultiArray on free store to ensure they don't overflow the stack (I know some compilers extend it during runtime, but it is still non-standard). I recommend using vector instead.

Interface

When using std::vector, need for templated size arguments disappears. It would be possible to templatize on allocator instead, defaulting to std::allocator<T>. The sizes could be passed on constructor call.

Subscript operator

That's going to be an issue, but it is easily solvable. Just make it

T& operator[](const std::initializer_list<std::size_t> indices)
{
    //use math to calculate the index
}

You'll also need const version. Input type may be different, but it should also check if the number of elements inside match the dimension count. You could templatize sizes still, so that this one can be replaced with const std::array<std::size_t, DimensionCount>&.