[eigen] operator overloading vs expression templates, and the need to return references |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] operator overloading vs expression templates, and the need to return references
- From: Rohit Garg <rpg.314@xxxxxxxxx>
- Date: Fri, 11 Sep 2009 21:50:07 +0530
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=M1FerRvpHoUr5OOoPOuMruzvzNcAxP5SWHmrNIgRNrk=; b=Up3lsUycvmmBkK4uJulfN7kylO/t4SaThPVVSscYVtF+3Mnyou51ASkUJnXU70HTfx vRQjA/QIZjfXpiPN0nWj8n0pSfGGCW2wJwl7ZN1UbnWNvyRrLP0r2/loFE5aeynsdwv2 CePcgHtPWbavVo1mbManFm967JihYCt6M7Jfs=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=mtSinGFDdVcXcWp4wLLu2ARrDc+9IIELiqiG8IO9uZ8NgZheeLZIaq5bkt1SIKu7x6 A1zW3tekYWL/VSJCI+uk23Jzk3MEYKYBteME4dU+8L4shaNwLdmT+45PJN4kgXj6sWzD NRAvgm/sKz87chjUfJsUW8YJj84nKnf2ITbww=
Hi all,
I made a simple class wrapping vector8s (for shorts) and overloaded
the arithmetic and overloaded operators. All was fine until my
expressions involving operator overloads got a bit too big and gcc
started spewing random crap. It may not be random crap, but I can
barely decipher it, so... :(
I resorted to simplifying my expressions, and the code quickly
exploded in verbosity with temporaries, but it compiled OK. Then I
made all the overloads return a reference like this,
inline vector8s& operator+(vector8s &other)
{
vector8s temp;
temp.data=_mm_add_epi16(data,other.data);
return temp;
}
and it complies, but it throws warnings at each of these overloaded
functions that I am returning references to temporaries. The
overloaded functions are pretty small, hence inlined, so I think it
should not be a problem, but it is obviously not nice.
This naturally raises the question how expression templates avoid this
problem, or how eigen suppresses these warnings, if indeed those
warnings are in the safe-to-ignore category. If indeed the
reference-to-temporary warnings can be safely ignored, then can anyone
explain to me how to do it?
This mail is not related to eigen's development per se, but is more
towards figuring out eigen's internals and how to make c++ work
nicely.
Any help will be appreciated a lot,
--
Rohit Garg
http://rpg-314.blogspot.com/
Senior Undergraduate
Department of Physics
Indian Institute of Technology
Bombay