enable_if type is not of a certain template class

为君一笑 提交于 2019-12-05 11:04:35

You should be able to construct your own trait for this:

template <class T>
struct IsClassNot : std::false_type
{};

template <class T>
struct IsClassNot<ClassNot<T>> : std::true_type
{};


template <typename T, typename T_Rhs>
typename std::enable_if<!IsClassNot<T_Rhs>::value,
ClassAnd<Class<T>, T_Rhs>>::type operator&(Class<T> const &lhs, T_Rhs const &rhs) {
    return ClassAnd<Class<T>, T_Rhs>(lhs, rhs);
}

Live example


Of course, you can go crazy with generalisations and create an all-purpose trait:

template <class T, template <class...> class TT>
struct is_instantiation_of : std::false_type
{};

template <template <class... > class TT, class... A>
struct is_instantiation_of<TT<A...>, TT> : std::true_type
{};

template <class T>
using IsClassNot = is_instantiation_of<T, ClassNot>;

Live example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!