Hi,
In [1] Evans proposes to use expansion inheritance in line (*)
#ifdef __clang__
template<typename... Functors>
struct overloader : forwarder<Functors>... // (*)
{
overloader(Functors&&... functors_a)
: forwarder<Functors>(functors_a)...
{}
};
#else
template<typename... Functors>
struct overloader;
template<>
struct overloader<>
{
void operator()()
{
}
};
template<typename Functor0, typename... Functors>
struct overloader<Functor0, Functors...>
: forwarder<Functor0>, overloader<Functors...>
{
overloader(Functor0&& functor0, Functors&&...
functors_a)
:
forwarder<Functor0>(std::forward<Functor0>(functor0))
,
overloader<Functors...>(std::forward<Functors>(functors_a)...)
{}
using forwarder<Functor0>::operator();
using overloader<Functors...>::operator();
};
#endif
The code after #ifdef __clang__ fails to compile with gcc, with the
following compile error
error: request for member ‘operator()’ is ambiguous
ovldr(udt_i<0>{});
IMO it is missing something like the line (**) below
template<typename... Functors>
struct overloader : forwarder<Functors>...
{
overloader(Functors&&... functors_a)
: forwarder<Functors>(functors_a)...
{}
using forwarder<Functor>::operator();... //( **)
};
but (**) is not correct in C++14.
The code after the #else part uses recursive inheritance and works
with both compilers.
The question is if the code after #ifdef __clang__ is correct or if
it is a BUG on clang?
Vicente
[1]
https://github.com/viboes/tags/issues/6#issuecomment-143444996