[vtk-developers] Problems with vtkSparseArray/DenseArray bool specialization

David Gobbi david.gobbi at gmail.com
Sat May 28 11:33:59 EDT 2011


Hi Tim,

When wrapping the array classes, I see the following warnings:

vtkSparseArray.txx: In member function ‘const T&
vtkSparseArray<T>::GetValue(vtkIdType) [with T = bool]’:
vtkSparseArray.txx:101: warning: returning reference to temporary
vtkSparseArray.txx: In member function ‘const T&
vtkSparseArray<T>::GetValue(vtkIdType, vtkIdType) [with T = bool]’:
vtkSparseArray.txx:125: warning: returning reference to temporary
vtkSparseArray.txx: In member function ‘const T&
vtkSparseArray<T>::GetValue(vtkIdType, vtkIdType, vtkIdType) [with T =
bool]’:
vtkSparseArray.txx:152: warning: returning reference to temporary
vtkSparseArray.txx: In member function ‘const T&
vtkSparseArray<T>::GetValueN(vtkTypeUInt64) [with T = bool]’:
vtkSparseArray.txx:186: warning: returning reference to temporary

These only occur for the "bool" specialization.  It took a bit of
searching to find out why they occur, but the reason is the following:

The std::vector<bool> class is actually a bit array.  When you
index it with [ ], it creates and returns a bool value, since it cannot
return a const reference to a bit, but then GetValue() stores that
bool value as a temporary, and subsequently returns a reference to it.

Can you take a look?

Thanks,

- David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20110528/72e83f32/attachment.html>


More information about the vtk-developers mailing list