Re: Template question...

Ben Voigt wrote:
"Victor Bazarov" <v.Abazarov@xxxxxxxxxxxx> wrote in message
Andy wrote:
How would I go about making this happen?

template<int Count> struct ACollectionOfThings {
typedef char not_allowed[Count > 16];
not_allowed& foo(); // dummy member

template<int Count> struct ASmallCollectionOfThings {
typedef char not_allowed[Count <= 16];
not_allowed& foo(); // dummy member

This assumes that your compiler forbids arrays of size zero, which
isn't true of all compilers.

Why should anybody concern themselves with non-compliant compilers?

Better would be:

template<int Count> struct ACollectionOfThings {
~ACollectionOfThings() { // or any other member function that gets
used const bool toosmall = Count < 16;
switch { case toosmall: case true: break; }

How does that work? Shouldn't there be a parenthesised expression
after the 'switch'? What compiler compiles the code you posted?


int main()
ACollectionOfThings<123> c123; // OK
ACollectionOfThings<10> c10; // causes an error
ASmallCollectionOfThings<10> sc10; // OK
ASmallCollectionOfThings<123> sc123; // causes an error
return 0;

Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


Relevant Pages

  • Re: Template question...
    ... I don't know of any other compiler that even ... templatestruct ACollectionOfThings { ... used const bool toosmall = Count < 16; ... switch ...
  • Re: DPROD issues
    ... a switch like that typically ... makes a compiler nonstandard in that mode. ... treatment of specific intrinsics is one ... subroutine sub1a ...
  • Re: [OT] Funny
    ... >> the NAG compiler does have a switch to allow you to tell it ... or the compiler simply isn't conforming. ... more arithmetic in computing addresses of array elements -- dis- ...
  • Re: "static" explanation. What exactly does it mean?
    ... compiler you set the exception handler to use Underflow gives 0.0; ... determine if there is a switch to generate signaling NaN's so the program stops ... find unequivocal explanations of what the use of static variables in Fortran code actually ...
  • Re: inline power function replacement
    ... switch ) ... and the order of the cases should not matter if the compiler ... the absolutely least overhead for the vast majority of cases. ... roughly the same overhead as an indirect function call (calling through ...