I think this is similar to how such an indirect (dependent) type cannot be
deduced for a function argument. The compiler's problem is, given some use of
FunctorImpl<X,Y>, find out if it matches the above with R=X and P1 some unique
type such that Seq<P1>::Type = Y. Uhm, deducing P1 from Y is rather difficult...

I guess you're thinking from the perspective of sort of handing in P1 and get
out Seq<P1>::Type.

The compiler, however, must work in the opposite direction: for any concrete use
of FunctorImpl it's handed some type Y, which it (if it accepted the code above)
would have to match against all possible Type in Seq<P1>::Type for all possible
P1, to find the presumably unique type P1.

Advertisements

On Jul 11, 12:34 pm, "Alf P. Steinbach" <> wrote:
>
> I think this is similar to how such an indirect (dependent) type cannot be
> deduced for a function argument. The compiler's problem is, given some use of
> FunctorImpl<X,Y>, find out if it matches the above with R=X and P1 some unique
> type such that Seq<P1>::Type = Y. Uhm, deducing P1 from Y is rather difficult...
>
> I guess you're thinking from the perspective of sort of handing in P1 and get
> out Seq<P1>::Type.
>
> The compiler, however, must work in the opposite direction: for any concrete use
> of FunctorImpl it's handed some type Y, which it (if it accepted the code above)
> would have to match against all possible Type in Seq<P1>::Type for all possible
> P1, to find the presumably unique type P1.
>
> > // This of course works:
> > //
> > template <class R, class P1>
> > class FunctorImpl<R, TypeList<P1, Nil> >
> > {
> > public:
> > typedef R ResultType;
> > typedef P1 Parm1;
> > virtual R operator()(Parm1) = 0;
> > };
>
> Yes. Given use of FunctorImpl<X, Y>, the compiler matches X to R, and Y to
> TypeList<P1, Nil>, that is, Y must be a type of that form, from which P1 follows.
>

Ahh... wasn't thinking about what the compiler had to do... this makes
sense.
> Uhm, I think macros... ;-)

Yeah... That's how the Loki library (haven't looked at what Boost
does) does it. It defines a bunch of macros for typelists, but also
just specializes FunctorImpl on Seq itself:

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!