From: srp113 on

> Then, you claim that they don't allow programming to interface paradigm.
> Actually, the reverse is true. Take a look at e.g. std::sort. It takes a
> sequence described by two random-access iterators IIRC. In other words, it
> is the interface of a random-access iterator that it is written for.
> However, RA iterators don't share a common baseclass but only interface
> requirements, which are checked at compile time. This is also known as "duck
> typing".
>
Hi Uli,
Thanks for response. This example is for function templates, can
'class templates' support programming to interface concept like
inheritance allows.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Jonathan Campbell on
Ulrich Eckhardt wrote:
> srp113 wrote:
[...]
> BTW: Inheritance is sometimes called run-time polymorphism while templates
> are called compile-time polymorphism, exactly because they achieve very
> similar things only at different times.
>

A famous paper by Cardelli and Wegner (1985) calls templates /generics
'parametric' polymorphism and inheritance-based polymorphism
'inclusion'. I'm not sure that 'inclusion' communicates much, but
'parametric' does --- there's a type parameter.

Best regards,

Jon C.

--
Jonathan Campbell www.jgcampbell.com BT48, UK.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Ulrich Eckhardt on
srp113 wrote:
>> Then, you claim that they don't allow programming to interface paradigm.
>> Actually, the reverse is true. Take a look at e.g. std::sort. It takes a
>> sequence described by two random-access iterators IIRC. In other words,
>> it is the interface of a random-access iterator that it is written for.
>> However, RA iterators don't share a common baseclass but only interface
>> requirements, which are checked at compile time. This is also known as
>> "duck typing".
>>
> Hi Uli,
> Thanks for response. This example is for function templates, can
> 'class templates' support programming to interface concept like
> inheritance allows.

Sure, take a look at std::vector. Its first template parameter must provide
value semantics, i.e. be default-constructible, copyable and assignable.

Uli


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Alp Mestan on
On Nov 17, 2:48 pm, Gerhard Menzl <clcppm-pos...(a)this.is.invalid>
wrote:
> The long answer would fill a book or two.

Anyone interested in such topic should -- must ? -- read either J.
Coplien's book [1] or Ph.D thesis [2].

[1] http://www.amazon.com/Multi-Paradigm-Design-James-O-Coplien/dp/0201824671
[2] http://sites.google.com/a/gertrudandcope.com/info/Publications/Mpd/Thesis.pdf?attredirects=0


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]