|
Boost : |
From: Hamish Mackenzie (hamish_at_[hidden])
Date: 2003-09-12 04:49:32
On Fri, 2003-09-12 at 09:24, Mat Marcus wrote:
> --On Thursday, September 11, 2003 11:31 PM +0100 Hamish Mackenzie
> <hamish_at_[hidden]> wrote:
> > Is there something similar for using with template classes?
> > Something like
> >
> > template< typename T >
> > class my_class : enable_if< is_same< T, x >::value >
> > {
> > };
>
> I think the usual idiom is:
>
> template <typename T, typename Enable = void>
> class my_class; //general case
>
> template <typename T>
> class A<T, typename enable_if<is_same<T, x>::value>::type> //special
> case
> {
> };
Should that be...
template <typename T>
class A<T, typename enable_if<is_same<T, x>::value, void>::type>
{
};
It seems a little long winded (requiring specialisation and all).
Am I correct in thinking that the advantage of this is that you can
have multiple specialisations based on different expressions?
Is it worth having another class for the simpler case where you only have
one definition of the class?
template< bool cond >
class enable_class_if;
template<>
class enable_class_if< true >{};
To be used like so
template< typename T >
class my_class : enable_class_if< is_same< T, x >::value >
{
};
Hamish
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk