On Fri, Apr 8, 2011 at 9:59 AM, Gennadiy Rozental <rogeeff@gmail.com> 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; }
};

struct S {};
enum FOO { FOO1, FOO2 };

int main()
{
   M<S>::foo();
   M<int>::foo();
   M<FOO>::foo();
}

---------------

M<FOO>::foo() fails to compile due to ambiguity.

Any pointers? Or How to get what I want?


I'm assuming the problem is that the scalar case is also true for the enum case?

On that basis, could you not us an enabler that asks if it is scalar && ! enum? 

- Rob.

(That's just off the cuff - I 'spect a proper expert will be along soon!)