c++ - template incomplete type used in nested specifier -
i've looked through several on-topic questions didn't help, sorry if duplicated.
why inner
incomplete type there? circular dependence?
p.s. not_used
placeholder class keep specialization partial
template <class a> struct outer { template <class not_used, class enabled = void> struct inner { static void inner() { std::cout << "not enabled\n"; } }; template <class not_used> struct inner<not_used, typename std::enable_if<std::is_same<int, a>::value>::type> { static void inner() { std::cout << "enabled\n"; } }; }; template <class a> void call_inner(a& a) { outer<a>::template inner<void>::inner(); // #1 } int main() { int intvar = 10; double doublevar = 1; call_inner(intvar); // ok call_inner(doublevar); // error @ #1: incomplete type ‘outer<double>::inner<void>’ used in nested name specifier }
update
if change second specialization (not_used->type
, is_same<int, a>
-> is_same<int, type>
)
template<typename type> struct inner<type, typename std::enable_if<std::is_same<int, type>::value>::type> { static void inner() { std::cout << "enabled\n"; } };
and call_inner
(note inner<void>
->inner<t>
)
template <class t> void call_inner(t& t) { outer<t>::template inner<t>::inner(); }
everything compiles. why that? apparently, dependence on outer
template parameter somehow changes instantiation process?
the clang error message more explicit:
ess.cpp:11:52: error: no type named 'type' in 'std::__1::enable_if<false, void>'; 'enable_if' cannot used disable declaration ...inner<not_used, typename std::enable_if<std::is_same<int, a>::value>::type> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ess.cpp:18:5: note: in instantiation of template class 'outer<double>' requested here outer<a>::template inner<void>::inner(); // #1 ^ ess.cpp:26:5: note: in instantiation of function template specialization 'call_inner<double>' requested here call_inner(doublevar); // error @ #1: incomplete type <bf>outer<dou...
as have enable_if
restrict instanciation == int, cannot instantiate outer<double>::inner<void>
.
Comments
Post a Comment