473,385 Members | 1,331 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,385 software developers and data experts.

'new' template usage

Hi everyone,

I've been using templates for a while, but I'm not at full power yet
(knowledge=power) ;). Does anyone know where I can get information on
this 'new' template usage?

template<a (b, c, d)>

Does one define it like:

template<typename A (typename B, typename C, typename D)>
{templated class/function definition here}

What is its use?

I also think that I've heard that ellipsis can also be used in the
template list. Is this true? If so, how is it used, and for what
purpose?

Thanks all,
Adrian

Mar 7 '07 #1
2 1982
ad*************@gmail.com wrote:
Hi everyone,

I've been using templates for a while, but I'm not at full power yet
(knowledge=power) ;). Does anyone know where I can get information on
this 'new' template usage?

template<a (b, c, d)>

Does one define it like:

template<typename A (typename B, typename C, typename D)>
{templated class/function definition here}

What is its use?

I also think that I've heard that ellipsis can also be used in the
template list. Is this true? If so, how is it used, and for what
purpose?

Thanks all,
Adrian
Hi Adrian,

The new template usage that you are referring to is not part of
the template standards of C++ I think. You will probably need to
verify it for yourself in comp.std.c++. Having said that, that
template syntax is used by <boost/function.hpp>. The boost people
use boost::preprocessor (a preprocessor meta-programming library)
that essentially uses very nifty preprocessor tricks to map

foo<int (float, double)to a proper looking template like
template<typename T1, typename T2, typename T3>
class foo;

You can see it is action for yourself if you look inside
boost::function. I like the work they did on it and find it
pretty awesome for them to use macros to help create partial
template specializations on the fly. As to what is the use of
this type of programming, well, boost::function sums it up
pretty nicely. I hope that answers your first question.

For the ellipsis, again, I am not sure but once more I think that
the "..." syntax has not yet be standardized. You will need to
verify it for yourself. What is its use? Imagine this:

I would like to write a max function that takes in arbitrary
number of parameters like so

template<typename T1, typename T2, ..., typename TN>
max( T1 &a, T2 &b, ..., TN &z );

this way, I can now call it like this

max( 1, 2, 3 ); or
max( 1.0, 2.0, 3.0, 4.5 );

Now having said that, looking again at boost function we notice that
it requires arbitrary number of arguments also. Yet using a combination
of nifty tricks, they are able to circumvent the problem that the
"..." syntax is unavailable. So it makes me wonder if the "..." syntax
is merely a convenience for the current ways to make it work.

You'll probably get more mileage if you post on the c++ standards
boards instead :)

But I hope I helped by giving you a better idea where templates can
go in the future. :)
Mar 7 '07 #2
On 7 Mar, 01:11, adrian.hawry...@gmail.com wrote:
Hi everyone,

I've been using templates for a while, but I'm not at full power yet
(knowledge=power) ;). Does anyone know where I can get information on
this 'new' template usage?

template<a (b, c, d)>

Does one define it like:

template<typename A (typename B, typename C, typename D)>
{templated class/function definition here}

What is its use?

I also think that I've heard that ellipsis can also be used in the
template list. Is this true? If so, how is it used, and for what
purpose?
I'm sorry to say (since I'd like to have them) that neither of those
are part of the current standard but may be part of the next (the
ellipsis thing I'm quite sure of, but the first I don't know). The
problem with this is that since they are not part of any standard yet,
which means that there probably are no compilers supporting it. And if
there are the functionality of those constructs might change until
they have been standardized.

As I understand things they hope to have the new standard out and
approved by 2009, which means that most things will have settles
sometime by 2008 and widespread compiler support should probably not
be expected until 2010 or later. Worst case scenario would be that
they can't agree about how something is supposed to work and throw it
out of the standard to be part of a separate TR or the next version.
So my advice is to not bother with these kinds of things for at least
a year in any serious project. You can of course play around to stay
up to date.

For more information about what will/might be in the next standard see
http://www.open-std.org/jtc1/sc22/wg...007/n2142.html

--
Erik Wikström

Mar 7 '07 #3

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

Similar topics

9
by: Aaron Anodide | last post by:
Hello, I am using the following template class as a shorthand for zero-ing memory: template<class T> class ZeroMem : public T { public: ZeroMem(void)
6
by: Dmitry Epstein | last post by:
Here is an example of a problem, which I tried to reduce to its bare essentials: // begin test1.cpp class E { public: template<class T> static void f(); }; template<class T> void E::f() {}
11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
1
by: GaryB | last post by:
Hi, (Posted this in scripting.wsh before I realised that it might be better placed here - sorry if you;ve got two copies) I want my (IE) Intranet users to be able to create a new Word document...
3
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a...
3
by: Larry Beck | last post by:
Below is a problem I am having with templates. I am trying to use a template to avoid having multiple class methods that differ only in the return type of the pointer. I have tried putting in...
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
3
by: Anonymous | last post by:
Could someone please explain template template classes, showing: 1). Why they are needed / i.e what problem do they solve ? 2). A simple example I have read various articles etc, but it still...
4
by: Ed | last post by:
Hi, guys, In C language manner, we need to put a "struct" token before one struct variable declaration like following. <code> struct Apple { float Price; };
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.