C++0X parameter packs as last arguments only

M

Marc

Hello,

in C++0X, we can have functions with a number of arguments that is not
fixed, which is cool:

template<class...U> void f(double d,U... u);

However, there is a restriction that the parameter pack must be the last
argument, so I cannot write:

template<class...U> void g(U... u,double d);

I understand that having 2 parameter packs wouldn't make sense (or at
least would be much more complicated), but as long as there is just one,
I am not sure why it has to be at the end. Is it just to simplify the
partial ordering of overloads for the compiler?

I know this can be worked around with tuple manipulations (Daniel
Krügler showed me the cool technique on clc++m a couple months ago), but
it is incredibly more complicated.
 
C

Chris Ahlstrom

Marc posted this message in ROT13 encoding:
Hello,

in C++0X, we can have functions with a number of arguments that is not
fixed, which is cool:

template<class...U> void f(double d,U... u);

However, there is a restriction that the parameter pack must be the last
argument, so I cannot write:

template<class...U> void g(U... u,double d);

I understand that having 2 parameter packs wouldn't make sense (or at
least would be much more complicated), but as long as there is just one,
I am not sure why it has to be at the end. Is it just to simplify the
partial ordering of overloads for the compiler?

Probably because the size of "..." is not known, so that the compiler would
not where to push the following arguments.
 
M

Marc

Chris said:
Marc posted this message in ROT13 encoding:

Qvq V? V zhfg unir orra qvfgenpgrq.
Probably because the size of "..." is not known, so that the compiler would
not where to push the following arguments.

Uh? I am talking about the C++0X variadics, where the size is perfectly
well known. Not about the C-inherited "..." where the size is indeed a
runtime property.
 
H

Howard Hinnant

Hello,

in C++0X, we can have functions with a number of arguments that is not
fixed, which is cool:

template<class...U> void f(double d,U... u);

However, there is a restriction that the parameter pack must be the last
argument, so I cannot write:

template<class...U> void g(U... u,double d);

I understand that having 2 parameter packs wouldn't make sense (or at
least would be much more complicated), but as long as there is just one,
I am not sure why it has to be at the end. Is it just to simplify the
partial ordering of overloads for the compiler?

I know this can be worked around with tuple manipulations (Daniel
Krügler showed me the cool technique on clc++m a couple months ago), but
it is incredibly more complicated.

See:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1603.pdf

Section 5.4.

It was considered and just didn't happen because it wasn't a
sufficiently high priority.

-Howard
 
C

Chris Ahlstrom

Howard Hinnant posted this message in ROT13 encoding:
See:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1603.pdf

Section 5.4.

It was considered and just didn't happen because it wasn't a
sufficiently high priority.

We feel that the few operations that would benefit may better be
accomplished by working with a true heterogeneous data structure such as
a tuple.

Thanks for the reference!

--
: Any porters out there should feel happier knowing that DEC is shipping
: me an AlphaPC that I intend to try getting linux running on: this will
: definitely help flush out some of the most flagrant unportable stuff.
: The Alpha is much more different from the i386 than the 68k stuff is, so
: it's likely to get most of the stuff fixed.

It's posts like this that almost convince us non-believers that there
really is a god.

-- Anthony Lovell, to Linus's remarks about porting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top