开发者

C++ problem "adapting" a three-parameters class template into a two-parameters class template

I have a class expecting a two parameters template, like this:

template<template <class, class> class TwoParamsClass>
class Test
{};

also I have a class like this:

template<int a, class A, class B>
class ThreeParamsClass
{};

I need an adapter that sets the first int param of "ThreeParamsClass", to be able to use them in Test class.


Here my partial solution (and a problem with it).

template<int a>
struct Alias
{
    template<class A, class B>
    struct Type
    {
        typ开发者_运维技巧edef ThreeParmamsClass<a, A, B> Type2;
    };
};

and then, I call Test like this:

Test<Alias<1>::Type> 

(of course, inside Test I need to take the param and get the ::Type2 type)

But the problem is, after that, I'need to wrap the Test class, like this:

template<int n>
struct Wrap
{
    typedef Test<Alias<n>::Type> WrappedTest;
};

but, i'm getting this error:

error: type/value mismatch at argument 1 in template parameter list for 'template class T> class Test'

That's strange, because this works fine:

template<int n>
struct Wrap
{
    typedef Test<Alias<1>::Type> WrappedTest;
};

I hope to be clear, I thought to make two question of this matter, but I think is better to ask the second one into the context of the first.

Thanks


Not really understanding your reasoning, but try this:

template<int n>
struct Wrap
{
    typedef Test<Alias<n>::template Type> WrappedTest;
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜