c++ - Name conflict between template struct and template member function -


in following, gcc confuses template struct name template member function name of class a, while clang compiles fine (live example):

template<typename t> struct name {};  struct {     template<bool b>     void name() { } };  template<bool b, typename t> void f(t& x) { x.template name<b>(); } 

function f apparently meant called argument of type a in example, else, f needs remain template function.

i don't care compiler correct, need work-around because don't know syntax other

x.template name<b>(); 

to call member function, , cannot see how using declaration or other way of disambiguation apply.

edit yes, tried more explicit syntax

x.t::template name<b>(); 

which works, ugly. way make brief syntax work? otherwise, might preferable change 1 of 2 names begin with...

edit2 original version of f works on universal reference t&&, needs ugliest

using x = typename std::remove_reference<t>::type; x.x::template name<b>(); 

in case t reference... , simple function call.

i've thought bit , can't see way make basic syntax want work, due templates involved. reason have specify template because otherwise looks compiler using < compare address of function b.

as said, rename 1 of name identifiers, allowing compiler have no ambiguity 1 mean.

alternately said , qualify call. don't find ugly syntax: it's clear reader exactly what's going on, , after have write function 1 time.

template<bool b, typename t> void f(t& x) {     typedef typename std::remove_reference<t>::type callee;      x.callee::template name<b>(); } 

finally if elaborate little more on real problem you're trying solve template might able offer orthogonal solution doesn't involve such type aliasing @ all.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -