[vtk-developers] The bool constructor for vtkVariant

Jeff Baumes jeff.baumes at kitware.com
Thu May 20 10:10:59 EDT 2010


On Thu, May 13, 2010 at 1:00 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> Hi All,
>
> The bool constructor for vtkVariant has been causing me grief.  There
> are two problems with it:
> 1) the automatic creation of a "char" from the bool is unexpected and
> often confusing
> 2) "bool" is too permissive, I can even pass a void pointer and have
> it resolve to "bool", and then vtkVariant will counterintuitively
> store it as "char"
>
> I can see why having a bool constructor would make sense, but then why
> not store it as "bool" internally?

The bool constructor was added in the following commit:

commit 6d24580ac8fbcdf4465d3fa5bc2de00bdf54a60b
Author: Dave Partyka <dave.partyka at kitware.com>
Date:   Thu Jul 9 18:38:05 2009 -0400

    COMP: fix vtkVariant complaining about ambigious bool declaration on borland

Dave, are we still supporting this compiler? If not, let's just get
rid of this constructor.

> It would also be useful if vtkVariant supported vtkIdType.  Even
> though vtkIdType is just a typedef, it would still be possible for
> vtkVariant to recognize it as a distinct type.  In my own VTK, I have
> a vtkVariant constructor method that takes a VTK type constant as a
> second arg, and something like vtkVariant(10, VTK_ID_TYPE) could be
> used to construct an ID-type variant.

vtkVariant should still choose an appropriate constructor based on
what vtkIdType is typedef'd to, so should never lose precision. So I
don't think we need a new constructor. What may be nice is a
convenience method vtkVariant::ToIdType().

Jeff



More information about the vtk-developers mailing list