"case2005" <case2005@private.email.com> writes:
[color=blue]
> Can anyone help with the following, I don't know if it's possible, but I'm
> certain there must be a standard way of dealing with this.
>
> I have the following:
>
> template<typename FooBar, typename Foo>
> class Bar {
>
> private:
> Foo foo;
> }
>
> Now I want to be able to handle when 'Foo' is a primitive type, or more
> specifically a primitive pointer type, like 'char *' and also when Foo is
> itself a template class:[/color]
To find out if it is a pointer type you can do the following:
template< typename FooBar>
class Bar<FooBar, Foo*>
{
//......
};
If foo is some pointertype hte copiler will instanciate this
specialiization.
[color=blue]
> template<typename FooBar, template<T> class Foo>
> class Bar {
>
> private:
> Foo<FooBar> foo;
> }
>
> All the member functions and other fields of Bar are common to both
> template classes. Can I do this with template specialization, if so how, I
> don't quite get it.[/color]
Maybe I got you wrong, but I think that's not necessary, because the
template will be instaciated with a concrete type, build by a template,
such as:
Bar<int, vector<double> >
for example. SO there is no such specialization necessary, IMHO.
[color=blue]
> I also tried to achieve this with the following, which isn't ideal,
> because the client of the template must be aware that primitive types
> must be wrapped in 'PrimitiveType':
>
> template<class T>
> struct PrimitiveType
> {
> typedef T Type;
> };
>
> template<class T>
> class WrappedClass
> {
> public:
> typedef WrappedClass<T> Type;
>
> private:
> };
>
> template<class FooBar, template<class T> class Foo>
> class Bar {
> public:
>
> Foo<FooBar>::Type wibble;
> };[/color]
Here is
typename Foo<FooBar>::Type wibble
required, becasue Type is a dependend name of the template Foo<...>.
[color=blue]
> I greatly appreciate any light shed on either of these issues.[/color]
I think what you are searchig for are so called typetraits:
http://www.boost.org/libs/type_traits/index.html
This library work with a lot of differnet compilers.
If you use it you can ask the compiler if a special type is a primitive
type, or not and so on, and you'd have not to write a lot of template
specializations for each type.
HTH && Kind regards,
Nicolas
--
| Nicolas Pavlidis | Elvis Presly: |\ |__ |
| Student of SE & KM | "Into the goto" | \|__| |
|
pavnic@sbox.tugraz.at | ICQ #320057056 | |
|-------------------University of Technology, Graz----------------|