Registered Member
|
I'm aware of the fact that matrices of differing types (but same size) can be assigned using the explicit cast<TargetType>() syntax.
Now assume TargetType is a non-trivial user type providing an implicit assignment operator taking a float, something like
If I understand correctly, using the cast syntax above would try to create objects of type MyClass first, then copy them to b. Is there a way to have this operation use the assign-from-float function in order to avoid creating the whole object first, then copy it? |
Moderator
|
B = A.cast<Type>()
is compiled as: for(i=...) B[i] = static_cast<Type>(A[i]); If your copy ctor can be inlined, then the compiler will easily optimize the temp for you, so no worry. You can verify by looking at the assembly. |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]