I have a code in which at the end of the function I need to drop from int to double all the elements of the array in order to be able to do the final push_back before exiting the function. The code I have now is:
template <class T, size_t dims> class A {
typedef typename std::array<int, dims> ArrayInt;
typedef typename std::array<double, dims> ArrayDouble;
typedef typename std::vector <ArrayDouble> VectorDouble;
foo() {
ArrayInt myArrayInt;
ArrayDouble myArrayDouble;
VectorDouble myVectorDouble;
for (int i = 0; i < dims; ++i)
myArrayDouble[i] = static_cast<double>(myArrayInt[i]);
myVectorDouble.push_back(myArrayDouble);
}
}
It works correctly, but I don't feel comfortable with the strings:
for (int i = 0; i < dims; ++i)
myArrayDouble[i] = static_cast<double>(myArrayInt[i]);
Is there a better way to do this?
Thanks.
source
share