|
Boost Users : |
Subject: [Boost-users] enable_if and multiple partial specializations
From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2011-04-08 04:59:02
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?
Gennadiy
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