|
|
Warp wrote:
> Darren New <dne### [at] sanrrcom> wrote:
>>> But it's compiled only once even if the same template function is used
>>> with a given type at several places in the program. (Without the export
>>> template mechanism the function would be compiled every time it's used.)
>
>> Even if the places it's used are in different compilation units?
>
> Yes. The compiler couldn't compile the template function even if it wanted
> because it only has its declaration, not the implementation (which is in
> its own compilation unit).
Um, OK. That's not what the folks who implemented it in their compiler
seemed to be saying.
>> As in,
>> if I invoke the compiler 12 times with 12 instantiations of the same
>> template in 12 different .cpp files, isn't that code going to have to
>> get translated into object code 12 different times?
>
> We are talking about export templates here, not regular ones.
Right. That's why I'm asking. :-)
> If the function is an export template, it will only be compiled once,
> not 12 times. (Well, naturally assuming all those 12 times use the same
> type with that template.)
Um, ok.
> The environment doesn't change with export templates because they are
> in their own compilation units. The only environment is that compilation
> unit in question. They are basically no different from regular functions.
But if in A.cpp I have xyz:MyTemplate<T> and in the body of MyTemplate
it invokes T.x(i), isn't the code generated going to depend on the
declarations of T.x that are available at the point I instantiate the
template? If x is an overloaded function, doesn't it have to know all
the overloaded functions in scope to pick the one most likely to be the
one I meant by passing whatever type "i" is?
That seemed to be what the paper about the compiler was talking about.
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
|