我确信boost有一些函数可以做到这一点,但我不太了解相关的库。我有一个模板类,除了需要定义一个条件类型之外,它是非常基础的。下面是我想要的psuedo代码
struct PlaceHolder {};
template <typename T>
class C{
typedef (T == PlaceHolder ? void : T) usefulType;
};我该如何编写条件类型?
发布于 2010-06-11 17:49:55
同样在新标准中:
typedef typename std::conditional<std::is_same<T, PlaceHolder>::value, void, T>::type usefulType
发布于 2010-06-10 01:58:50
我想这就是你所追求的原则:
template< class T >
struct DefineMyTpe
{
typedef T usefulType;
};
template<>
struct DefineMyType< PlaceHolder >
{
typedef void usefulType;
};
template< class T >
class C
{
typedef typename DefineMyType< T >::usefulType usefulType;
};发布于 2010-06-10 01:57:18
template < typename T >
struct my_mfun : boost::mpl::if_
<
boost::is_same<T,PlaceHolder>
, void
, T
> {};
template < typename T >
struct C { typedef typename my_mfun<T>::type usefulType; };https://stackoverflow.com/questions/3008413
复制相似问题