Skip to content

Instantly share code, notes, and snippets.

@SiegeLord

SiegeLord/output

Last active Aug 29, 2015
Embed
What would you like to do?
C++ matrix moving
clone
move
move
100 200 300
#include <vector>
#include <iostream>
struct Matrix
{
std::vector<float> data;
Matrix()
{
}
Matrix(const Matrix& m) :
data(m.data)
{
std::cout << "clone" << std::endl;
}
Matrix(Matrix&& m) :
data(std::move(m.data))
{
std::cout << "move" << std::endl;
}
Matrix& operator= (Matrix&& m)
{
std::cout << "move" << std::endl;
data = std::move(m.data);
return *this;
}
};
Matrix operator* (const Matrix& m, float f)
{
Matrix m2(m);
for(auto& v: m2.data)
v *= f;
return m2;
}
Matrix operator* (Matrix&& m, float f)
{
Matrix m2(std::move(m));
for(auto& v: m2.data)
v *= f;
return m2;
}
int main()
{
Matrix m;
m.data = {1.0, 2.0, 3.0};
Matrix m2 = m * 2.0 * 5.0 * 10.0;
for(auto v: m2.data)
{
std::cout << v << " ";
}
std::cout << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.