Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Don't lose array sizes in copyTo #94

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions matrix/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class Matrix
return (*this);
}

void copyTo(Type (&dst)[M*N]) const
void copyTo(Type dst [M*N]) const
{
memcpy(dst, _data, sizeof(dst));
memcpy(dst, _data, sizeof(Type)*M*N);
}

void copyToColumnMajor(Type (&dst)[M*N]) const
Expand Down
9 changes: 8 additions & 1 deletion test/copyto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

using namespace matrix;

namespace {
void doTheCopy(const Matrix<float, 2, 3>& A, float array_A[6])
{
A.copyTo(array_A);
}
}

int main()
{
float eps = 1e-6f;
Expand Down Expand Up @@ -32,7 +39,7 @@ int main()
A(1,1) = 5;
A(1,2) = 6;
float array_A[6] = {};
A.copyTo(array_A);
doTheCopy(A, array_A);
float array_row[6] = {1, 2, 3, 4, 5, 6};
for (size_t i = 0; i < 6; i++) {
TEST(fabs(array_A[i] - array_row[i]) < eps);
Expand Down