Я пытаюсь добавить поддержку icc в один из своих проектов, но у меня возникают проблемы с SFINAE, когда методов больше двух. Вот простой пример проблемы:
#include <iostream>
template<std::size_t Selector>
struct impl {
template<bool Enable = true, typename std::enable_if<Selector == 1 && Enable, int>::type = 0>
static void apply(){
std::cout << "First selector" << std::endl;
}
template<bool Enable = true, typename std::enable_if<Selector == 2 && Enable, int>::type = 0>
static void apply(){
std::cout << "Second selector" << std::endl;
}
template<bool Enable = true, typename std::enable_if<Selector == 3 && Enable, int>::type = 0>
static void apply(){
std::cout << "Big selector" << std::endl;
}
};
int main(){
impl<1>::apply();
impl<2>::apply();
impl<3>::apply();
return 0;
}
Это прекрасно работает с g++ и clang++, но не компилируется с icc:
test.cpp(16): error: invalid redeclaration of member function template "void impl<Selector>::apply() [with Selector=1UL]" (declared at line 11)
static void apply(){
^
detected during instantiation of class "impl<Selector> [with Selector=1UL]" at line 22
test.cpp(11): error: invalid redeclaration of member function template "void impl<Selector>::apply() [with Selector=3UL]" (declared at line 6)
static void apply(){
^
detected during instantiation of class "impl<Selector> [with Selector=3UL]" at line 24
compilation aborted for test.cpp (code 2)
Есть ли обходной путь для этого с icc ? Я бы не хотел менять слишком много кода, у меня есть эта проблема в нескольких местах моего проекта.
Я использую icc 16.0.2.164.
Спасибо
apply
вimpl_base<Selector>
и добавлениеusing impl_base<Selector>
вimpl
. Это полностью устраняет необходимость в SFINAE. - person MSalters   schedule 31.03.2015impl
не может быть создана допустимая специализация по крайней мере для двух из трехapply
. - person T.C.   schedule 31.03.2015