2015-12-03 4 views
2

Вот простейший случай того, что я пытаюсь сделать:См собственного типа для параметра шаблона шаблона

template <template <typename...> class Wrapper> 
struct WrapperTraits { }; 

template <typename... Whatever> 
struct Foo { 
private: 
    // I want Foo here to refer to the template, and not the current 
    // concrete type (which is injected into the namespace by default) 
    using Traits = WrapperTraits<Foo>; 
}; 

int main() 
{ 
    return 0; 
} 

А вот ошибка лязга 3.6 (он компилирует штраф на GCC 4.8 и 5.2):

error: template argument for template template parameter must be a class template or type alias template 
using Traits = WrapperTraits<Foo>; 
^ 
1 error generated. 
Compilation failed 

Вот пример вопроса о godbolt: https://goo.gl/cSx6QR

Спасибо за вашу помощь!

+0

'шаблона с использованием Foo_Z = Foo ,' затем использовать 'Foo_Z'? – Yakk

+0

не может воспроизвести ошибку: https://ideone.com/rXiUhl – user463035818

+1

@ tobi303 Это на gcc 5.1. Он не компилируется на clang. Я предоставил ссылку на godbolt –

ответ

2

Никогда не думал, понял. Необходимость охвата его к пространству имен он находится в:

template <template <typename...> class Wrapper> 
struct WrapperTraits { }; 


template <typename... Whatever> 
struct Foo { 
private: 
    using Traits = WrapperTraits<::Foo>; // explicit namespace 
}; 


int main() 
{ 
    return 0; 
} 
Смежные вопросы