The title pretty much says it all. I would like to do:
std::pair<int,int> a(2,1), b(1,1), c(0,0);
c=a-b;
and get c=(1,0). If it involves defining a new class and doing operator overloading that's ok I suppose, I'd still be interested in seeing the most elegant way to do that, but it would be even better, imo, if there was a non-boost, non-new-class-definition solution. Thanks! -Mark
std::valarray is designed to support numerical computation on vectors (that is, ordered sequences of numbers).
std::valarray<int> a {2, 1}, b {1, 1}, c;
c = a - b;
You can access its elements like you would access those of std::vector
, i.e., with the subscripting operator []
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With