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 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
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.
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
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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:...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |