[Insight-developers] Convenience functions for Index, Offset,
Point, Vector, etc.
Brad King
brad.king@kitware.com
Wed, 12 Mar 2003 17:13:46 -0500 (EST)
Jim,
> MakeIndex is not terribly efficient since it must construct the Index,
> set the components, and return the index but it does make the notation
> "shorter".
This should be pretty fast:
inline Index<2> MakeIndex(Index<2>::IndexValueType i0,
Index<2>::IndexValueType i1)
{
Index<2> i = {{i0,i1}};
return i;
}
Most modern compilers have a "Named Return Value Optimization" (NVRO) that
will optimize the entire call away. The optimization was introduced to
help reduce the penalty of the common postfix-increment operator problem:
foo foo::operator++(int) { foo tmp(*this); ++*this; return tmp; }
-Brad