1
我想根据给定的枚举模板参数(store_type)选择一个类模板。现在我实例化一个使用这个类的类,但它似乎总是尝试实例化这个类的basic_store。通过枚举模板参数编译时间模板选择
enum store_type
{
none,
basic,
lockless,
};
template<class T, store_type S = none, typename = void>
struct get_store_type
{
};
template<class T>
struct get_store_type<T, basic,
typename std::enable_if<!std::is_abstract<T>::value>::type>
{
using store_type = typename basic_store<T>;
};
template<class T>
struct get_store_type<T, lockless>
{
using store_type = typename lockless_store<T>;
};
template<typename T, store_type S>
class client
{
public:
using my_store_type = typename get_store_type<T, S>::store_type;
}
//Tries to instantiate a basic store... which is not allowed.
client<SomeAbstractType, lockless> something;
Ofcourse!谢谢你,一直盯着这个年龄:P。 –
@AndreasLoanjoe欢迎您。 – Rabbid76
我如何接受它?你的意思是我应该放弃吗?因为我做到了。编辑:nvm明白它被接受! –