Boost logo

Boost :

From: Stjepan Rajko (stipe_at_[hidden])
Date: 2007-11-20 14:18:30


On Nov 19, 2007 6:12 PM, Stjepan Rajko <stipe_at_[hidden]> wrote:
> // ---- A PARTIAL SOLUTION
>
> template <typename T2, typename Enable=void>
> class enabled_class
> {
> BOOST_MPL_ASSERT((is_same<Enable, void>));
>
> // default implementation
> };
>
> // we forget to change the user code
> enabled_class<X, Y> o; // ERROR (except in the unfortunate case when Y is void)
>

Actually, looks like the void case can be handled as well:

namespace detail {
    struct enable_guard;
}

template <typename T2, typename Enable=detail::enable_guard>
class enabled_class
{
  // Error: Enable has non-default parameter value
  BOOST_MPL_ASSERT((is_same<Enable, detail::enable_guard>));

  // base template implementation...
};

template<typename T>
class enabled_class<
  T,
  typename enable_if<
    some_condition<T>,
    detail::enable_guard
>::type >
{
  // partial specialization implementation...
};

// we forget to change the user code
enabled_class<X, Y> o; // ERROR (even if Y is void)

Stjepan


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