我为自己做了这个语法,因为我认为它对于以后来说更方便。是否可以使用没有参数的模板专门化?
temolate<typename U> struct identity{typedef U type;};
temolate<typename T, typename identity<T>::type value=0> struct my{
typedef std::vector<T> vec;
typedef std::array<T,value> arr;
typedef std::set<T> set;
// and so forth
};
我用它:
int main(){
my<int>::vec v; // okay
my<int,3>::arr a; // okay
// and so forth
}
但我也希望这样做的语法:
(专攻的我上面)
template<??????????> // what should I do here?
struct my<?????????>{ // or may be here
typedef int i;
typedef float f;
typedef double d;
// and so forth;
}
所以,我可以做此:
int main(){
my::i a; // for int, what should I do?
my::f b; // for float, and
my::d c; // for double, and
// AND I ALSI CAN
my<int>::vec v; // already I know
my<int,3>::arr a; // and know
}
这可能吗?
我看到这里:
Default template parameter partial specialization 之前我问。所以我知道my<>::i
是可能的。
而且我也知道了如何使用
使用别名与我只问这是可能的吗?
using myy = my<int>;
:与其说NO给我的,你让我downvote
如果我理解正确。当然你可以,但你仍然需要使用'我的<> :: i'等。 –
什么是完全投票**? – skypjack
@skypjack,谢谢。我不是英语母语,也只是学习它,而且我也使用我的平板电脑。 –