I am trying to use the CRTP and template template parameters, with a templated derived class, and specify some but not all of it's arguments, before passing to the base class to fully define. The closest concept I can compare it to is something like a templated alias, but since it must all be in the single top line of the class definition, I'm not not sure how I can achieve that. Hopefully an example makes it a bit clearer...
Here is my code so far:
template<template<typename> class Template1, typename Param1>
class Base
{
public:
using type = Param1;
};
template<template<typename, typename> class Template1, typename Param1, typename Param2>
class Derived : public Base<template<typename P1> class Template1<P1, Param2>, Param1>
{};
template<typename Param1, typename Param2>
class Template1
{};
int main()
{
Derived<Template1, int, double>::type d = 0;
}
This currently fails with the following:
9:89: error: wrong number of template arguments (1, should be 2) 2:7: error: provided for 'template<template class Template1, class Param1> class Base' In function 'int main()': 18:3: error: 'type' is not a member of 'Derived<Template1, int, double>'
What really baffles me about that error message, is that I can't see anywhere where I'm only specifying a single template argument. I have also discovered that if I define Derived as follows, then it compiles fine:
template<typename> class Test {};
template<template<typename, typename> class Template1, typename Param1, typename Param2>
class Derived : public Base<Test, Param1>
{};
Which I think indicates that the problem is definitely on this line (which unsurprisingly, is the bit I'm unclear on how to achieve):
class Derived : public Base<template<typename P1> typename Template1<P1, Param2>, Param1>
Basically, here I am trying to define a new template with a single argument, which is a partial specialisation of the first template with two arguments. I guess I'm not doing that correctly. But how can I on a single line?
Thanks in advance for any help. Apologies if this is in any way unclear!
Aucun commentaire:
Enregistrer un commentaire