一种缩短声明的方法

时间:2010-12-08 16:47:23

标签: c++ templates

我有这样的事情:

 template<class Key,
                 class Value,
                 class Compare_p = Compare<ByKey>,
                 template<class,class> class Insert_p = NoOverride,
                 template<class> class FailureSignal_p = ThrowOnFailure,
                 class AllocFactor_p = AllocFactorScientific<>,
                 class Alloc = Allocator<FailureSignal_p>
                >
        class Map : private Map_Base<Implementation> //Implementation is a Link with identical  
//params to Map
        {
        public:  
//I've tried to use typedef here but it's too late
            typedef LinkImplementation<Pair<Key,Value>,Compare_p,Insert_p,FailureSignal_p,AllocFactor_p,Alloc> Implementation;
    };

所以最重要的问题是:有没有办法让这个声明(LinkImplementation&lt;&gt;)缩短?

1 个答案:

答案 0 :(得分:1)

可能会为地图参数创建一个模板“struct”,如下所示:

template <class Key, ...  blablabla > 
struct MapParams{
typedef Key key_t;
typedef Value value_t;
..................
};

然后使用此“struct”作为单个模板参数 对于Map和Map_Base模板?