Board index » cppbuilder » Can I use a typename like this?

Can I use a typename like this?

Hi all...

My basic question is this:  is there a way to test for what kind of
typename has been passed in a template function (like testing for what T
is passed in a template function "Foo<T>(){...}") and execute a block of
code in the function accordingly?

Here's why it came up:

I want to make a template function that will return the number of values
in a known enum--something that would work like this:

int TmpCount = EnumCount<MyEnumType>();

In concept, I want to do something like this:

enum Foo1Enum {Foo1A, Foo1B, Foo1C};
enum Foo2Enum {Foo2A, Foo2B, Foo2C, Foo2D};

template <typename TN> int EnumCount()
{
   int RetVal;
   switch (TN) {
      case Foo1Enum: RetVal =  (int)Foo1C;  break;
      case Foo2Enum: RetVal =  (int)Foo2D;  break;
      default: -1;
   }
   return RetVal;

Quote
}

BUT, of course, you can't use a typename as in "switch(TN)" and you
can't use the names Foo1Enum and Foo2Enum in this manor.

SO, is there a way to test for what kind of typename has been passed in
a template function and execute a block of code accordingly???

Thanks!!!

-Jay

 

Re:Can I use a typename like this?


"Jason W. Hinson" <hins...@cna.org> wrote in message
news:3E96C713.F1FEB948@cna.org...

Quote
> My basic question is this:  is there a way to test for what kind of
> typename has been passed in a template function (like testing for what T
> is passed in a template function "Foo<T>(){...}") and execute a block of
> code in the function accordingly?

Please don't cross-post.  It is against Borland's newsgroup guidelines
(http://www.borland.com/newsgroups).  Only post questions to the single most
appropriate group.

Your question was already answered in the .vcl.components.using group (which
wasn't really the best group, either - .language.cpp would have been the
most appropiate one).

Gambit

Other Threads