1

I have a templated class ParameterTemplateClass which is a parameter type to another templated class.

Basically my code looks as below.

template <class T1, class T2>
    class ParameterTemplateClass
    { 
      typedef T1 Type1;
      typedef T2 Type2;
    };


    template <ParameterTemplateClass<template<class T1, class T2> > >
    class SomeClass
    { 
      typedef typename ParameterTemplateClass::Type1 Type1;
      typedef typename ParameterTemplateClass::Type1 Type1;
    };

template<>
class SpecializedClass::ParameterTemplateClass<int, float>
{ }

template<>
class SomeSpecializedClass::SomeClass<SpecializedClass>
{ }

I cannot get this to work. I have tryed different approaches, including the approach shown at What are some uses of template template parameters in C++?; however I have not been successful so far.

Please not that I want class SomeClass template parameter to be ParameterTemplateClass, and not T1, T2 which are parameter types for ParameterTemplateClass.

Can this be achieved? Can somebody please let me know. Thanks

Community
  • 1
  • 1
geraldCelente
  • 1,005
  • 2
  • 16
  • 36
  • 3
    I don't understand what you want. Do you want `SomeClass` to be instantiated with a type argument, and make sure that type argument is an instantiation of `ParameterTemplateClass<>`? In that case, template template parameters are not what you want/need – Andy Prowl Jun 10 '13 at 19:44
  • @AndyProwl, Ok I will edit the question to make it more clear. – geraldCelente Jun 10 '13 at 19:46
  • @AndyProwl Ok, I have now updated my question. Do you have the information you need? :) – geraldCelente Jun 10 '13 at 19:57

1 Answers1

4

Please not that I want class SomeClass template parameter to be ParameterTemplateClass, and not T1, T2 which are parameter types for ParameterTemplateClass.

This is not a semantic that templates handle -- can you give a more detailed example?

If you want to refer to the ParameterTemplateClass, then explicitly use it inside of SomeClass, for example,

template <class T1, class T2 >
class SomeClass
{ 
    ParameterTemplateClass <T1, T2> foo;
};

EDIT:

If you want to have SomeClass take a templated class, this can be expressed such as:

template <template <class T1, class T2> class T>   class SomeClass
{ 
};

http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Ftemplate_template_arguments.htm

EDIT2:

If SomeClass should not be aware of T1 and T2, then implement it as:

 template <class T>   
 class SomeClass
 { 
 };

And use it as: SomeClass<ParameterTemplateClass <T1, T2> > Templates do not have the semantic of "limiting" to only use ParameterTemplateClass. If you want a compile time error raised if `SomeClass<...> is passed a class other than ParameterTemplateClass, there are tricks that can do this but there is no clear motivation for using these in this context.

EDIT 3:

Modified based on edits to the question. You can express the typedefs as:

template <class T>
class SomeClass
{ 
  typedef typename T::Type1 Type1;
  typedef typename T::Type2 Type2;
};
hazydev
  • 344
  • 1
  • 9
  • I have updated my question, in order more easy to understand my question. Anyway, I think your answer might be a solution. Only problem is that Some class would also directrly on T1 and T2, whereas I want it only to depend on T, and then T depend on template parameters T1 and T2. Anyway, I am going for dinner now. When I am back I will tell you the result of my experimentation. Thanks – geraldCelente Jun 10 '13 at 20:00
  • The problem is that SomeClass depends on Type1 and Type2 which are types from ParameterTemplateClass. Seed the code above: typedef typename ParameterTemplateClass::Type1 Type1; – geraldCelente Jun 10 '13 at 20:43