[eigen] Pass POD by reference or by pointer?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Many C++ books say pass by reference whenever possible. However, I find the
code below misleading.

### unsupported/Eigen/src/MatrixFunctions/MatrixPower.h

 81 template<typename Derived, typename ResultType>
 82 void apply(const Derived&, ResultType&, bool&);

209 apply(b, res, init);

###

At line 209, it looks as if init would never be written. This is also why Qt
prefers pointers to references.

I think there is nothing wrong to pass a reference to a non-POD, but passing a
reference to a POD is functionally safe but syntactically misleading. Even if
we want the functional safety of a reference, we can pass a pointer-const
instead, but the constness seems unnecessary.

If passing a pointer is better, feel free to alter the code. ;)

Thanks,
Chen-Pang



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/