This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: The future C++ template model in gcc


[Nathan Sidwell]
> Florian Schintke wrote:
> 
> > My idea is to not instantiate the templates,
> > but to provide a generic template implementation that works
> > for all template arguments.
> In general this is not possible, consider (on an ILP=32 machine)
> 	template <typename T> int Foo () {return sizeof (T);}
> 	Foo<char> () // return 1
> 	Foo<int> () // return 4
> 	Foo<void *> () // return 4
> 
> Foo<char> must have a different instantiation than Foo<int> and Foo<void
> *>,
> but Foo<int> and Foo<void *> can have the same body. (This is what
> you mean, right?)

No, my idea is to provide additional information to solve this
differences in a single implementation.
The compiler would add information about the size of the template
parameter object when instantiating:

The compiler would do something like the following, not the user:
 	template <typename T, typename sizeofT> int Foo () {return sizeofT;}
 	Foo<char, sizeof(char)> () // return 1
 	Foo<int, sizeof(int)> () // return 4
 	Foo<void *, sizeof(void *)> () // return 4

So one could try, with additional information from the instantiation
point made available by the compiler to the runtime environment, 
to implement a single generic template implementation. 


Florian Schintke
-- 
Florian Schintke <schintke@zib.de>, http://www.zib.de/schintke/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]