Re: Help: How many explicit specializations required?
From: CoolPint (coolpint_at_yahoo.co.uk)
Date: 09/16/04
- Next message: Martin Eisenberg: "Re: [OT] Can anyone recommend any Audio Processing libraries?"
- Previous message: steve: "Re: can someone explain to me, a C/Hw guy, what the diff is between a reference (&) and a pointer?"
- In reply to: CoolPint: "Help: How many explicit specializations required?"
- Next in thread: Nicolas Pavlidis: "Re: Help: How many explicit specializations required?"
- Reply: Nicolas Pavlidis: "Re: Help: How many explicit specializations required?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Sep 2004 06:48:45 -0700
I just figured out how to differentiate between T and array of T. Not
only that, I also learned I had to differentiate between array of T
and array of const T, too.
Now, that involves a lot of specialization. I am now a bit clearer
about my originial questions B and C, but I still wonder about
combining the four separate specializations required for handing
C-style char strings.
I still very much love to hear ideas from experts. Thank you again.
Below is the program I modified from the previous post to show me
what's going on.
#include <iostream>
using std::cout;
template <typename T>
void func(const T &)
{ cout << "primary\n" ; }
template <typename T>
void func(T * const &) // should handle T * as well as const T *
{ cout << "Overloading for Pointers\n"; }
template <>
void func(char * const &)
{ cout << "specialization: char * \n"; }
template <>
void func(const char * const &)
{ cout << "specialization: const char * \n"; }
template <int N>
void func( const char (&) [N] )
{ cout << "Overloading for const char[] \n"; }
template <int N>
void func( char (&) [N] )
{ cout << "Overloading for char[] \n"; }
template <typename T, int N>
void func( T (&) [N] )
{ cout << "Overloading for T [] \n"; }
template <typename T, int N>
void func( const T (&) [N] )
{ cout << "Overloading for const T [] \n"; }
int main()
{
char * pc = "whatever";
const char * pcc = "whatever";
char ac[] = "whatever";
const char acc[] = "whatever";
int i;
const int ci=1;
int ai[] = { 0 };
const int aci[] = {0};
cout << "int: "; func(i);
cout << "int *: "; func(&i);
cout << "const int: "; func(ci);
cout << "const int *: "; func(&ci);
cout << "int [] : "; func(ai);
cout << "const int [] :"; func(aci);
cout << "Literal String: "; func("whatever");
cout << "char *: "; func(pc);
cout << "const char *: "; func(pcc);
cout << "char []: "; func(ac);
cout << "const char []: "; func(acc);
}
- Next message: Martin Eisenberg: "Re: [OT] Can anyone recommend any Audio Processing libraries?"
- Previous message: steve: "Re: can someone explain to me, a C/Hw guy, what the diff is between a reference (&) and a pointer?"
- In reply to: CoolPint: "Help: How many explicit specializations required?"
- Next in thread: Nicolas Pavlidis: "Re: Help: How many explicit specializations required?"
- Reply: Nicolas Pavlidis: "Re: Help: How many explicit specializations required?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|