Boost logo

Boost Users :

Subject: Re: [Boost-users] enable_if and multiple partial specializations
From: Joel Falcou (joel.falcou_at_[hidden])
Date: 2011-04-08 05:06:38


On 08/04/11 10:59, Gennadiy Rozental wrote:
> Hi,
>
> It's late and I might be missing something, but I can't figure out how can I use
> enable_if to disambiguate 2 partial specializations where one is subcase of
> another one:
>
> #include<boost/utility/enable_if.hpp>
> #include<boost/type_traits/is_enum.hpp>
> #include<boost/type_traits/is_scalar.hpp>
>
> #include<iostream>
>
> template<typename T, typename Enabler=void>
> struct M {
> static void foo() { std::cout<< "generic"<< std::endl; }
> };
>
> template<typename T>
> struct M<T, typename boost::enable_if<boost::is_scalar<T> >::type> {
> static void foo() { std::cout<< "scalar"<< std::endl; }
> };
>
> template<typename T>
> struct M<T,typename boost::enable_if<boost::is_enum<T> >::type> {
> static void foo() { std::cout<< "enum"<< std::endl; }
> };

> M<FOO>::foo() fails to compile due to ambiguity.
>
> Any pointers? Or How to get what I want?

enum are scalar so :

template<class T>
struct M<T,typename boost::enable_if< boost::is_enum<T> >::type> {
       static void foo() { std::cout<< "enum"<< std::endl; }
  };

template<typename T>
  struct M<T, typename boost::enable_if_c< boost::is_scalar<T>::value &&
!boost::is_enum<T>::value >::type> {
       static void foo() { std::cout<< "scalar"<< std::endl; }
  };


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net