Question about curiously recursive template pattern

  • Follow


Is Coplien's curiously recursive template pattern synonymous
with F-bounded polymorphism? I can't find the original C++
Report article, is there an online version?

Thanks,
Andrew

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply andrew_queisser 11/5/2003 4:44:12 PM

andrew queisser wrote:

 > Is Coplien's curiously recursive template pattern synonymous
 > with F-bounded polymorphism? I can't find the original C++
 > Report article, is there an online version?

I doubt it - it's in the C++ Gems book IIRC.

But, what is F-bounded polymorphism? I know of runtime and compile
time polymorphism but hasn't heard about this one.

Ali



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Albrecht 11/8/2003 1:16:36 PM


Albrecht Fritzsche <alis-news@gmx.net> wrote in message news:<boh1dt$1eb255$2@ID-144146.news.uni-berlin.de>...
 > andrew queisser wrote:
 >
 >  > Is Coplien's curiously recursive template pattern synonymous
 >  > with F-bounded polymorphism? I can't find the original C++
 >  > Report article, is there an online version?
 >
 > I doubt it - it's in the C++ Gems book IIRC.
 >
 > But, what is F-bounded polymorphism? I know of runtime and compile
 > time polymorphism but hasn't heard about this one.
 >
 > Ali
 >
That's the problem - I'm not exactly sure what F-bounded polymorphism
is either. In compile-time polymorphism you have unbounded (type
parameter can be anything), bounded (type parameter has to conform to
some kind of constraint, e.g a particular interface or base class) and
F-bounded. As I understand it F-bounded means that a class A is
derived from a template which is parametrized with A. But I'm not
really sure exactly. The paper that introduces F-bounded polymorphism
is a bit too dense for me (Canning,Cook,Hill,Olthoff, "F-Bounded
Polymorphism for Object-Oriented Programming")

In C++ this is all really implicit - you just throw your type into the
template and hope that everything resolves.

Andrew

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply andrew_queisser 11/12/2003 9:14:58 AM

andrew queisser wrote:
> That's the problem - I'm not exactly sure what F-bounded polymorphism
> is either. In compile-time polymorphism you have unbounded (type
> parameter can be anything), bounded (type parameter has to conform to
> some kind of constraint, e.g a particular interface or base class) and
> F-bounded. As I understand it F-bounded means that a class A is
> derived from a template which is parametrized with A. But I'm not
> really sure exactly. The paper that introduces F-bounded polymorphism
> is a bit too dense for me (Canning,Cook,Hill,Olthoff, "F-Bounded
> Polymorphism for Object-Oriented Programming")

I've found this at www.cse.ogi.edu/~black/publications/black.pdf

"The F-bounding condition is defined by Canning et al. as

    t <= F[t]

where <= is the subtyping relation and F[t] is an expression, generally
containing the type variable t." ("Dismissing the 'Final Concern'" by
Andrew P. Black)

So, /bounded polymorphism/ means a restriction on type parameters. For
instance, a sort function requires the elements to be comparable. If I
understand this correctly, than /F-bounded polymorphism/ restricts this
further on elements of type t only.
> 
> In C++ this is all really implicit - you just throw your type into the
> template and hope that everything resolves.

Yeah, fortunately ;-)
Ali


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Albrecht 11/12/2003 8:34:10 PM

andrew queisser wrote:
 > Albrecht Fritzsche <alis-news@gmx.net> wrote in message
 > news:<boh1dt$1eb255$2@ID-144146.news.uni-berlin.de>...
 > > andrew queisser wrote:
 > >
 > >  > Is Coplien's curiously recursive template pattern synonymous
 > >  > with F-bounded polymorphism? I can't find the original C++
 > >  > Report article, is there an online version?
 > >
 > > I doubt it - it's in the C++ Gems book IIRC.
 > >
 > > But, what is F-bounded polymorphism? I know of runtime and compile
 > > time polymorphism but hasn't heard about this one.
 > >
 > > Ali
 > >
 > That's the problem - I'm not exactly sure what F-bounded polymorphism
 > is either. In compile-time polymorphism you have unbounded (type
 > parameter can be anything), bounded (type parameter has to conform to
 > some kind of constraint, e.g a particular interface or base class) and
 > F-bounded. As I understand it F-bounded means that a class A is
 > derived from a template which is parametrized with A. But I'm not
 > really sure exactly. The paper that introduces F-bounded polymorphism
 > is a bit too dense for me (Canning,Cook,Hill,Olthoff, "F-Bounded
 > Polymorphism for Object-Oriented Programming")

Also it doesn't appear to be available online (and the title is
actually "F-Bounded Quantification...").

 > In C++ this is all really implicit - you just throw your type into the
 > template and hope that everything resolves.

I had a look at a paper that cites this (Basic theory of F-bounded
quantification, Baldan et al., 1999, p.6) and it gives this example:

    "...F-bounded quantification allows the programmer to express the
     fact that a function works with any type that matches the Point
     type, by assigning to such function a type:

                    \/a<=[x:Int;eq:a->Bool].a->B"

     (\/ stands for the universal quantifier and a for alpha.)

This means the function accepts arguments of a type that has a
certain interface that is parameterised by the type itself, but as
I understand it this doesn't imply any inheritance relationship.
So while the class template's member functions in the curiously
recurring template pattern are using F-bounded quantification it
seems to be a much broader concept that covers almost everything
that we do with function templates.

You are right that we can't express these types in C++ but there are
techniques that template writers can use to check explicitly and
these could be enhanced by typeof() (or whatever it's going to be
called).  We could perhaps write a function with the above type
thus:

     #include <boost/type_traits.hpp>
     using boost::is_same;

     template<typename T>
     B f(T)
     {
         BOOST_STATIC_ASSERT(
             is_same<typeof(&T::x), int (T::*)>::value);
         BOOST_STATIC_ASSERT(
             is_same<typeof(&T::eq), B (T::*)(T)>::value);

         // and now the real code
     }

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Ben 11/13/2003 8:32:05 AM

4 Replies
206 Views

(page loaded in 0.081 seconds)

Similiar Articles:







7/15/2012 12:53:10 PM


Reply: