[Insight-users] Borland 6 Build error

Luis Ibanez luis.ibanez@kitware.com
Sat, 23 Nov 2002 18:56:38 -0500


Hi John,

Well, at least we know that enums will
compile but not be correctly evaluated.

VC++ was also unwilling to evaluate enums
in some circumstances. This is the reason
why the GetImageDimension helper class was
introduced in it itkImageBase.h line 39,
like:

---------------------------------------
template <typename TImage>
struct GetImageDimension
{
   itkStaticConstMacro(ImageDimension, unsigned int, 
TImage::ImageDimension);
};
---------------------------------------

And the StaticConstMacro is defined in itkMacro.h line 94

---------------------------------------
#ifdef ITK_NO_INCLASS_MEMBER_INITIALIZATION
#   define itkStaticConstMacro(name,type,value) enum { name = value }
#else
#   define itkStaticConstMacro(name,type,value)
                    static const type name = value
#endif
---------------------------------------

If we insist in trying the enums in Borland 6, it
could be useful to have a similar helper class,
like:


-------------------------------------------
template<typename TClass>
struct GetDimension
{
    enum { Dimension = TClass::Dimension }
};
-------------------------------------------

and then use it, for example, in the
declaration of the SliceRegion type:

-------------------------------------------
typedef ImageRegion Self;
typedef ImageRegion< GetDimension<Self>::Dimension - 1 > SliceRegion;
-------------------------------------------


Now that,...

looking closer to the ImageRegion class, maybe the
problem is simple here since the dimension is not
obtained from a class in the template parameters.
The dimension is the parameter itself.

It is then much simpler to define SliceRegion just as:


   typedef ImageRegion< VImageDimension-1 > SliceRegion


Could you please try this definition in
line 85 of itkImageRegion.h ?

and let us know how Borland 6 feels about it ?

It may be necessary to add an explicit instantiation
of the ImageRegion<1>  as in the example of the
Factorial.


Thanks,


    Luis



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



 >
John Biddiscombe wrote:

> With #define ENUMWORKS I get
> 
> Factorial of 5 = 120 // I added the factorial code too
> Region 5
> Region 0
> Region 0
> 
> but with #undef ENUMWORKS
> 
> Factorial of 5 = 120
> Region 5
> Region 4
> Region 4
> 
> Which is interesting. It looks like enums are dodgy alright, but only when
> you recurse at least once...
> 
> JB
> 
> ---------------------code below
> 
> #include <iostream>
> 
> #define ENUMWORKS
> #undef ENUMWORKS
> 
> template<int N>
> class Factorial {
> public:
> #ifndef ENUMWORKS
>      static const unsigned int value = N * Factorial<N-1>::value;
> #else
>      enum { value = N * Factorial<N-1>::value };
> #endif
>      Factorial()
>      {
>        std::cout << "Factorial of " << N << " = " << value << std::endl;
>      }
> };
> 
> class Factorial<1> {
> public:
> #ifndef ENUMWORKS
>      static const unsigned int value = 1;
> #else
>      enum { value = 1 };
> #endif
> };
> 
> template<int N>
> class ImageRegion {
> public:
> 
>      typedef ImageRegion<N> Self;
> #ifndef ENUMWORKS
>      static const unsigned int  Dimension = N;
>      static const unsigned int  SliceDimension = N-1;
>      typedef ImageRegion< N-1 > SliceRegion;
> #else
>      enum { Dimension = N };
>      enum { SliceDimension = N-1 };
>      typedef ImageRegion< SliceDimension > SliceRegion;
> #endif
>      SliceRegion Slice() { return SliceRegion(); }
>      ImageRegion() { std::cout << "Region " << N << std::endl; }
> };
> 
> #pragma argsused
> main()
> {
>    Factorial<5> f;
> 
>    typedef ImageRegion<5> RegionType;
>    RegionType region;
>    RegionType::SliceRegion sliceRegion;
>    sliceRegion = region.Slice();
> 
>    char ch;
>    std::cin >> ch;
> 
>    return 0;
> }
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
> 
>