4 ms·
In situations where the output's shape changes based on the operation this can be helpful. auto accumulate = ...; auto a = ... auto b = ... aut
by gravypod 5y ago
In situations where the output's shape changes based on the operation this can be helpful.
auto accumulate = ...;
auto a = ...
auto b = ...
auto result = a*b;
for (int row = 0; row < a.rows) {
accumulate += result[row]
}
This expression might be entirely valid when a and b are both 2x2 but then becomes incorrect when there's a different shape in b.
- CyberDildonics 5y agoDo you mean type instead of shape? I also don't know what you mean by incorrect. C will also create casts when using two different number types in a math operation.
- gravypod 5y agoFor matrix and quaternions multiplication does not output the same type as the input. For example: int a = 1; a + a = 2; (int) a * 2 = 2; (int) auto ma = matrix<2, 4>(); auto mb = matrix<4, 1>(); ma * a is matrix<2, 4> ma * ma is not possible ma * mb is matrix<2, 1> Compilers used to be very bad at telling you what was going on here if you, for example, changed `<2, 4>` to `<3, 4>` or something. g++ now handles it pretty well: https://hastebin.com/idemopikag https://hastebin.com/idemopikag
- CyberDildonics 5y agoYour original comment was about something being incorrect, now you are talking about error messages, but I don't think either has to do with operator overloading.