C++: Correct syntax for friending a template type member of template parameter? -


i have class takes template type parameter (ttrait). want friend template type member alias of ttrait, can't figure out syntax. (is possible?).

template <bool bbool> struct sfoo {};  struct strait     {         template <bool bbool>         using tfoo = sfoo<bbool>;     };  template <typename ttrait> struct sbar     {         template <bool bbool>         friend typename ttrait::template tfoo<bbool>;     };  sbar<strait> bar; 

clang's error (on friend line) is:

error: friend type templates must use elaborated type 

i have tried exhausting possible combinations can think of:

friend ttrait::tfoo; friend ttrait::template tfoo; friend typename ttrait::tfoo; friend typename ttrait::template tfoo; template <bool bbool> friend ttrait::tfoo; template <bool bbool> friend ttrait::tfoo<bbool>; template <bool bbool> friend ttrait::template tfoo; template <bool bbool> friend ttrait::template tfoo<bbool>; template <bool bbool> friend typename ttrait::tfoo; template <bool bbool> friend typename ttrait::tfoo<bbool>; template <bool bbool> friend typename ttrait::template tfoo; template <bool bbool> friend typename ttrait::template tfoo<bbool>; 

i have tried using using, doesn't seem help.

as ugly hack (which works bool parameters), can work friending each specialization manually.

friend typename ttrait::template tfoo<false>; friend typename ttrait::template tfoo<true >; 

but that's yucky.

does know how this, or if can done?

i don't think possible. standard draft n4296:

§ 14.5.4/1 [temp.friend]

a friend of class or class template can function template or class template, specialization of function template or class template, or non-template function or class.

this doesn't include alias templates, standard doesn't support want do. perhaps due following excerpt (emphasis mine):

§ 14.5.7/1 [temp.alias]

a template-declaration in declaration alias-declaration (clause 7) declares identifier alias template. an alias template name family of types.

an alias template names separate family of types, if there syntax made sense this, friending alias template rather template being aliased.

for example, gcc compile (clang won't), won't able use friendship in reasonable way:

template <bool b> using mytfoo = typename ttrait::template tfoo<b>;  template <bool> friend class mytfoo;  

another example of how alias template not same aliased template:

template <template <typename...> class a, template <typename...> class b> struct is_same_template : std::false_type{};  template <template <typename...> class a> struct is_same_template<a,a> : std::true_type{};  template <typename t> using myvec = std::vector<t>;  //this fails static_assert(is_same_template<myvec,std::vector>::value, "wat"); 

your manual friending explicit instantiation work, because alias template collapse down same type aliased template. analogous example:

//this passes! static_assert(std::is_same<myvec<int>,std::vector<int>>::value, "wat"); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -