Article View: pl.comp.objects
Article #15311Re: Jeszcze o C++ templates i ich zwiazku z ....
From: A.L.
Date: Tue, 05 Sep 2006 00:28
Date: Tue, 05 Sep 2006 00:28
58 lines
3048 bytes
3048 bytes
On Mon, 4 Sep 2006 23:56:06 +0200, "Muchomor"
<muchomor_w_kropkiCUT_THIS@gazeta.pl> wrote:
>
>Wytknijcie mi gdzie sie myle, ale dla mnie ten fragment nie ma krzty sensu.
>Autor tutaj najwyrazniej strzela sobie samoboja. Jesli przyjac - za
>autorem - , ze kompilator stosujac copy&paste z czegos takeigo :
>
>template<typename T> void Fun(T val)
>{
> std::cout << "Val = " << val << "\n";
>}
>
>wygeneruje np. 2 funkcje
>
>void Fun(int val); (1)
>void Fun(double val); (2)
>
>to gdzie tu szablony "hurt the C++ compiler's ability to generate efficient
>code" ?
>Czym sie to bedzie roznic od sytuacji gdy programista sam sobie napisze
>funkcje (1) i (2) zamiast szablonu?
>Kompilator bedzie szczesliwszy? Nie sadze..
Tak jest w Javie. A jak jest w C++?...
A.L.
"You might imagine that List<Integer> stands for a version of List
where E has been uniformly replaced by Integer:
public interface IntegerList { void add(Integer x)
Iterator<Integer> iterator();
}
This intuition can be helpful, but it’s also misleading.
It is helpful, because the parameterized type List<Integer> does
indeed have methods that look just like this expansion.
It is misleading, because the declaration of a generic is never
actually expanded in this way. There aren’t multiple copies of the
code: not in source, not in binary, not on disk and not in memory.
If you are a C++ programmer, you’ll understand that this is
very different than a C++ template.
A generic type declaration is compiled once and for all, and turned
into a single class file, just like an ordinary class or interface
declaration. Type parameters are analogous to the ordinary
parameters used in methods or constructors.
Much like a method has formal value parameters that describe the
kinds of values it operates on, a generic declaration has formal
type parameters. When a method is invoked, actual arguments are
substituted for the formal parameters, and the method body is
evaluated. When a generic declaration is invoked, the actual type
arguments are substituted for the formal type parameters..."
Technical Details
Message-ID:
<g1hpf2hs913nsgggpv1dntbhpojg98mcts@4ax.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news-fra1.dfn.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.freenet.de!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!sn-xt-ams-06!sn-xt-ams-05!sn-ams!sn-feed-ams-03!sn-post-ams-02!sn-post-sjc-01!supernews.com!corp.supernews.com!not-for-mailReferences:
<0elmf2h54pl11i82jrlrjeifeaue4np2i6@4ax.com> <9624a$44fca0f9$57cffbdc$22240@news.chello.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news-fra1.dfn.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.freenet.de!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!sn-xt-ams-06!sn-xt-ams-05!sn-ams!sn-feed-ams-03!sn-post-ams-02!sn-post-sjc-01!supernews.com!corp.supernews.com!not-for-mail From: A.L. <alewando@fala2005.com> Newsgroups: pl.comp.objects Subject: Re: Jeszcze o C++ templates i ich zwiazku z .... Date: Mon, 04 Sep 2006 19:28:54 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <g1hpf2hs913nsgggpv1dntbhpojg98mcts@4ax.com> References: <0elmf2h54pl11i82jrlrjeifeaue4np2i6@4ax.com> <9624a$44fca0f9$57cffbdc$22240@news.chello.pl> X-Newsreader: Forte Agent 3.1/32.783 MIME-Version: 1.0 X-Complaints-To: abuse@supernews.com Lines: 58 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit