2016-12-22 3 views
2

부분적인 특수화를 수행하면서 내부 클래스의 구현을 분리하는 데 문제가 있습니다.정의와 별도의 void에 부분 특수 템플릿을 구현하는 방법은 무엇입니까?

#include <type_traits> 

template <typename T> 
using enable_if_copyable = std::enable_if_t<std::is_copy_constructible<T>::value>; 

template <typename T> 
using enable_if_not_copyable = std::enable_if_t<!std::is_copy_constructible<T>::value>; 

template <typename T, typename Enabled=void> 
struct Foo; 

template <typename T> 
struct Foo<T, enable_if_copyable<T>> 
{ 
    struct Bar 
    { 
     Bar(); 
    }; 
}; 

template <typename T> 
struct Foo<T, enable_if_not_copyable<T>> { 
    struct Bar 
    { 
     Bar(); 
    }; 
}; 

template <> 
struct Foo<void,void> 
{ 
    struct Bar 
    { 
     Bar(); 
     //Bar() {} This compiles, but it is not what I want. 
    }; 
}; 

template <typename T> 
Foo<T, enable_if_copyable<T>>::Bar::Bar() 
{}  

template <typename T> 
Foo<T, enable_if_not_copyable<T>>::Bar::Bar() 
{} 

template <> 
Foo<void, void>::Bar::Bar() // this does not compile 
{} 


int main() { 
    Foo<int>::Bar b; 
    Foo<void>::Bar v; 
} 

때문에 나는 그들의 선언 외부 Bar의 c'tors을 구현해야 종속성 : 여기 내 문제를 설명하는 샘플 코드입니다. 제 문제는 모든 컴파일러 (Clang, gcc, Visual Studio 2015)가 class Foo<void, void> 선언 외부의 Foo<void, void>::Bar::Bar() {} 구현에 대해 불평한다는 것입니다. void의 전문 분야에 Bar이라는 c'tor를 구현하면 아무런 문제가 없습니다. 이것이 문제가되지 않습니까? 아니면 문제 해결에 도움이 될만한 사람이 있습니까? 미리 감사드립니다.

답변

2

template<>을 삭제 해보세요. 내 말은 :

// template <> 
Foo<void, void>::Bar::Bar() // now compile 
{} 

더 자세한 내용은 this page를 참조하십시오.