I have the following code, which I cannot get to work:
struct foo {};
foo foo1 = {};
template <foo& F>
class FooClass {};
template <foo& F>
void foobar(FooClass<F> arg) {
}
int main() {
FooClass<foo1> f;
foobar(f);
}
The error is:
main.cpp:14:5: error: no matching function for call to 'foobar'
note: candidate template ignored: substitution failure : deduced non-type template argument does not have the same type as the its corresponding template parameter ('foo' vs 'foo &')
Is it at all possible to infer lvalue reference template parameters? If so, how should it be done?
foo1
as an expression isfoo
and therefore does not match the typefoo&
of the template parameterF
exactly. Might be a defect in the Standard. – dypf
asFooClass<foo1>
on both clang and gcc. This represents independently written versions of__cxa_demangle
as specified here: mentorembedded.github.io/cxx-abi/abi.html#mangling – Howard Hinnantf
has typeclass FooClass<&struct foo foo1>
. And it successfully compiles this example. – Howard Hinnant