This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Assign values to matrix with nontrivial user type entries

Tags: None
(comma "," separated)
massen
Registered Member
Posts
1
Karma
0
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
Code: Select all
   
void operator =(const float& value) {
   _value = value;
}

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?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
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.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]