alias template && alias type

 

template<typename T>
using Vec = std::vector<T, MyAlloc<T>>;

//then:;

Vec<int> coll;
// is equivalent to:
std::vector<int, MyAlloc<int>> coll;

// 使用宏macro无法达到相同的效果
#define Vec<T> tempalte<typename T> std::vector<T,MyAlloc<T>>;
Vec<int> coll;
//于是
tempalte<typename int> std::vector<int, MyAlloc<int>>;

//使用typedef也无法达到同样的效果,因为typedef是不接受参数的
//我们最多得到
typedef std::vector<int, MyAlloc<int>> Vec;

 

using func = void(*)(int, int);
//typedef void(*func)(int, int);
void example(int a,int b){
    
}

func fn = example;
fn(3, 4);

 

 

 

但是不可以对这个alias template做特化

 

posted @ 2020-04-06 18:49  狂奔~  阅读(330)  评论(0)    收藏  举报