目前,我有一个模板类,如下所示:
template<typename T, T value>
struct MyStruct{
/* Stuff */
};
为了当前实例化它,我做了如下操作:
typedef MyStruct<int, 123> struct_def;
typedef typename MagicTemplate<123>::type struct_def;
这将决定
MyStruct<int,123>
....
编辑
如果该解决方案可以与指针、成员指针、函数指针等一起使用,那也太好了。。。
例如:
struct OtherStruct{
int memberA;
long memberB;
void foo(void);
};
static OtherStruct instance;
//Expands to MyStruct<memberA OtherStruct::*, &OtherStruct::memberA>
typedef typename MagicTemplate<&OtherStruct::memberA>::type struct_defA;
//Expands to MyStruct<OtherStruct*,&instance>
typedef typename MagicTemplate<&instance>::type struct_defB;
//Expands to MyStruct<void (OtherStruct::*)(void),&OtherStruct::foo>
typedef typename MagicTemplate<&OtherStruct::foo>::Type struct_defC;