473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Is there a way to span a suite of explicit instantiations automatically?

Hi,

I am creating a template library for a template class with two template
arguments.
Is there a way to span a suite of explicit instantiation, instead of
having to specify all the combinations of the template arguments
specifically?

Say I have a class

template <class T1, class T2>
class Foo
{
T1 t1;
T2 t2;
}

with T1, T2 having the following possibilities:

T1 - unsigned char, short, unsigned short, long
T2 - unsigned char, short, float, double

I was thinking of some way like a function that scans all the
combinations and constructs the class for each of the combinations.
Maybe having the function as static will force the generation of the
code, which will force the generation of the class code for each
combination of the template arguments.
Something like:

template <class S1, class D>
static void foo()
{
loop on all T1 possibilities
{
loop on all T2 possibilities
{
Foo<T1, T2> *p = new Foo<T1, T2>;
}
}
}
Thanks,
Avner

Jun 27 '06 #1
5 1427
Avner wrote:
I am creating a template library for a template class with two
template arguments.
Is there a way to span a suite of explicit instantiation, instead of
having to specify all the combinations of the template arguments
specifically?
Create an XML file and then XSLT for it to span the sets. Output C++
code from it. Then find a command-line XSLT applier (translator) and
insert it into your build process.
[...]


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '06 #2
Avner wrote:
Hi,

I am creating a template library for a template class with two template
arguments.
Is there a way to span a suite of explicit instantiation, instead of
having to specify all the combinations of the template arguments
specifically?

Say I have a class

template <class T1, class T2>
class Foo
{
T1 t1;
T2 t2;
}

with T1, T2 having the following possibilities:

T1 - unsigned char, short, unsigned short, long
T2 - unsigned char, short, float, double

I was thinking of some way like a function that scans all the
combinations and constructs the class for each of the combinations.
Maybe having the function as static will force the generation of the
code, which will force the generation of the class code for each
combination of the template arguments.
Something like:

No, templates are instantiated at compile time, so you can't instantiate
them at run time.

Just write a simple code generator to spit out a test file and add it as
a step in your build process.

--
Ian Collins.
Jun 27 '06 #3
Ian Collins wrote:
No, templates are instantiated at compile time, so you can't instantiate
them at run time.

Just write a simple code generator to spit out a test file and add it as
a step in your build process.

--
Ian Collins.


Can yoy give me an example of how the simple code generator should look
like and explain how I should add it into the build process?

Thanks,
Avner

Jun 27 '06 #4
Ian Collins wrote:
No, templates are instantiated at compile time, so you can't instantiate
them at run time.

Just write a simple code generator to spit out a test file and add it as
a step in your build process.

--
Ian Collins.


Can yoy give me an example of how the simple code generator should look
like and explain how I should add it into the build process?

Thanks,
Avner

Jun 27 '06 #5
Avner wrote:
Ian Collins wrote:
No, templates are instantiated at compile time, so you can't instantiate
them at run time.

Just write a simple code generator to spit out a test file and add it as
a step in your build process.

--
Ian Collins.

Can yoy give me an example of how the simple code generator should look
like and explain how I should add it into the build process?

You should set your news reader not to quote sigs (the bit below the
'--'). This is normally the default.

The code generator would look very much like you original function
pseudo code, except rather than

loop on all T2 possibilities
{
Foo<T1, T2> *p = new Foo<T1, T2>;
}

It would have something like
loop on all T2 possibilities
{
out << "Foo<" << T1 << ',' << T2 << "> *p = new Foo<" << T1 <<','
<< T2 <<">;" << std::endl;
}

where out is an ostream&

How you add it to your build process depends on what that process is!

--
Ian Collins.
Jun 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Brian Sabbey | last post by:
Here is a pre-PEP for what I call "suite-based keyword arguments". The mechanism described here is intended to act as a complement to thunks. Please let me know what you think. Suite-Based...
9
by: Yahel | last post by:
Hi all, I'm having a small but a quite upseting problem using Css and the <span> tag. I've set up a style for the extract of some articles that goes like this : ..Texte { font-family:...
4
by: CoolPint | last post by:
I would be grateful if someone could point out if I am understanding correctly and suggest ways to improve. Sorry for the long message and I hope you will kindly bear with it. I have to make it...
3
by: Dilip | last post by:
I am stumbling my way through C++ templates and I keep running into way too many questions. Here is one: If a library writer exposes a function template like so: template<typename T> void...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.