Boost logo

Boost :

From: Neal Becker (ndbecker2_at_[hidden])
Date: 2005-07-21 16:11:42


I have a question on usage of enable_if for faking partial specialization of
function templates.

Suppose I have a func F that has a general implementation, and a partial
specialization for std::complex<T>.

The obvious way to do this is to forward to a class member:

template<typename T>
struct F_impl { void DoF (); };

template<typename T>
struct F_impl<std::complex<T> >{ void DoF (); };

template<typename T>
void F () { F_impl<T>(); }

Alternatively, I can define is_cmplx:
template<typename T>
struct is_cmplx {
  static const bool value = false;
};

template<typename FLT>
struct is_cmplx<std::complex<FLT> > {
  static const bool value = true;
};

And use enable_if/disable_if.

Both work. My question is, why would I prefer one over the other approach?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk