[Insight-users] itkSTLContainerAdaptorTest - fix for Borland

Luis Ibanez luis.ibanez@kitware.com
Wed, 27 Nov 2002 12:25:53 -0500


Hi Dean, Ofri,


Dean, thanks for looking for a fix for Borland.


Unfortunately gcc doesn't like the proposed fix.

There are valid reasons though:

1) Casting to the actual STLContainer is actually
    creating a temporary instance of the container
    This is bad since the full content is copied

2) The reference to the temporary variable is
    returned. The temporary will be long gone by
    the time the user gets the reference.


I'm wondering how useful is to have the adaptor here.

We could equally change the private derivation
for public derivation and let all the STL methods
be available.

It seem that the basic difficulty comes from the
fact that the itk containers use double derivation.
Borland seems to have a hard time with it.


Another option is to do the casting on the
adaptor (not in the class itself) and maybe go
through the dark path of "friend".



What do you think ?



    Luis

===============================================

Dean Inglis wrote:

> Hi,
> 
> can you test (on other platforms) the following casting in
> Insight/Code/Common/itkVectorContainer.h: lines 103, 107
> 
>   /** Cast the container to a STL container type */
>   STLContainerType & CastToSTLContainer() {
>      return static_cast<STLContainerType
> &>(static_cast<STLContainerType>(*this)); }
> 
>   /** Cast the container to a const STL container type */
>   const STLContainerType & CastToSTLConstContainer() const {
>      return static_cast<const STLContainerType
> &>(static_cast<STLContainerType>(*this)); }
> 
> and
> Insight/Code/Common/itkMapContainer.h: lines 95, 99
> 
>   /** Cast the container to a STL container type */
>   STLContainerType & CastToSTLContainer() {
>      return static_cast<STLContainerType
> &>(static_cast<STLContainerType>(*this)); }
> 
>   /** Cast the container to a const STL container type */
>   const STLContainerType & CastToSTLConstContainer() const {
>      return static_cast<const STLContainerType
> &>(static_cast<STLContainerType>(*this)); }
> 
> 
> A ctest -R run of the test gives:
> 
> Changing directory into c:\Builder\itkRelease\Testing\Code\Common
> Testing itkSTLContainerAdaptorTest     Error, iteration on containers didn't
> finished simultaneously
> ***Failed
> Testing the VectorContainer ----- Testing non-const Adaptor
> VectorContainer (009852C8)
>   Reference Count: 1
>   Modified Time: 1
>   Debug: Off
>   Observers:
>     none
> 
> Testing assignment... Passed !
> Testing index access...
> 
> 
> 
> 0% tests passed, 1 tests failed out of 1
> 
> The following tests FAILED:
> 	itkSTLContainerAdaptorTest
> 
> 
> regards,
> Dean
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
> 
>