Re: Template question...
- From: "Victor Bazarov" <v.Abazarov@xxxxxxxxxxxx>
- Date: Mon, 12 Feb 2007 19:34:24 -0500
Ben Voigt wrote:
"Victor Bazarov" <v.Abazarov@xxxxxxxxxxxx> wrote in message
news:epnobc$q41$1@xxxxxxxxxxxxxxxxxx
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;
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.
- Follow-Ups:
- Re: Template question...
- From: Ben Voigt
- Re: Template question...
- References:
- Re: Template question...
- From: Ben Voigt
- Re: Template question...
- Prev by Date: Re: null (x00) verses zero (x30)
- Next by Date: Re: null (x00) verses zero (x30)
- Previous by thread: Re: Template question...
- Next by thread: Re: Template question...
- Index(es):
Relevant Pages
|