Topic: Variadic template parameter pack matching non-pack parameters


Author: "terminator(jam)" <farid.mehrabi@googlemail.com>
Date: Tue, 2 Apr 2013 15:56:24 -0700 (PDT)
Raw View
Daniel Kr   gler wrote:
>I would suggest to submit a bug report to VC++.

I wouldn`t recommend that.
They once said they`d have variadic templates in VS2012 but later they
said it`s ** too hard and you can use tuple ... ** and just didn`t do
it. I don`t remember the address but you can check the MS official
page.
Can any one suggest a good alternative IDE to VS on Windows?
I am bored of them spending lots of time on none-standard extensions
ignoring standards features accepted bye the committee.

Regards,
FM.


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]




Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Thu, 4 Apr 2013 19:05:52 CST
Raw View
On 2013-04-03 00:56, terminator(jam) wrote:
> Daniel Kr   gler wrote:
>> I would suggest to submit a bug report to VC++.
>
> I wouldn`t recommend that.

Why? If you don't report it, how will you expect it to be fixed?

> They once said they`d have variadic templates in VS2012 but later they
> said it`s ** too hard and you can use tuple ... ** and just didn`t do
> it. I don`t remember the address but you can check the MS official
> page.

There can be reasons to be unsatisfied with your vendor, but I don't
think that this group should be used to make your complains public.

Just for the record: I have reported this issue and it seems to be fixed
now:

https://connect.microsoft.com/VisualStudio/feedback/details/776438/codename-milan-failing-template-deduction-for-variadics

> Can any one suggest a good alternative IDE to VS on Windows?

I'm quite happy with the CodeBlocks IDE:

http://www.codeblocks.org

> I am bored of them spending lots of time on none-standard extensions
> ignoring standards features accepted bye the committee.

Keep in mind that most compiler vendors (including gcc) do provide some
extensions of the core language and you usually need to perform extra
steps to ensure that they are not active.

HTH & Greetings from Bremen,

Daniel Kr   gler




--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Sylvester Hesp <usenet@oisyn.nl>
Date: Sat, 12 Jan 2013 11:23:41 -0800 (PST)
Raw View
[To the moderators: this is my second attempt, the first one posted
using Google Groups went into the void. Also, a mail to
std-c++-request@cs.rpi.edu was being rejected because "User address is
not valid"]

I was playing around with the November '12 CTP preview of the VC++11
compiler, which includes an implementation of variadic templates, and
something interesting caught my eye.

Consider the following program:

===================
template<class T, class U>
struct Foo { };

template<class... Args>
void Bar(Foo<Args...> f)
{
}

template<class... Args>
void Baz()
{
 Foo<Args...> f;
}

int main()
{
 Foo<int, float> f;
 Bar(f);     // #1
 Bar<int, float>(f);  // #2
 Baz<int, float>(f);  // #3
}
===================

This fails to compile using both VC++11 and GCC 4.6.3 (unfortunately I
was not able to test a more recent version). VC++ in particular reports
these errors:

===================
test1.cpp(5): error C2976: 'Foo' : too few template arguments
          test1.cpp(2) : see declaration of 'Foo'
test1.cpp(18): error C2664: 'void Bar<>(Foo)' : cannot convert
parameter 1 from 'Foo<int,float>' to 'Foo'
          No user-defined-conversion operator available that can
perform this conversion, or the operator cannot be called
test1.cpp(20): error C2780: 'void Baz(void)' : expects 0 arguments - 1
provided
          test1.cpp(10) : see declaration of 'Baz'
===================

I was confused. The first error just seems plain silly - why would it
complain *at definition time of Bar* that Foo has too few template
parameters, if it doesn't yet know the Args parameter pack will be
expanded at instantiation time? Especially given the fact that at #2 no
errors are reported where the template parameters are explicitely
specified, and that Foo is appropriately instantiated in Baz() at #3.
Of course, a specific instantiation could use a different number of
parameters allowed for Foo, but this would then be a clear case of
SFINAE (Bar() I mean, Baz() would be ill-formed).

Also, it fails to deduce the template parameters in #1. Albeit somewhat
less clear that the compiler should be able to deduce a parameter pack
using a list of non-pack parameters in the argument, I recon this is
analogous to matching function parameters like 'R(Args...)', so I would
think that it should also be able to deduce the pack in this particular
case.

My first reasoning was that I was simply hitting a compiler bug in
VC++, but then I found out that GCC reported similar errors. Then I
started to read up on the standard, especially sections 14.5.3
[temp.variadic] and 14.8.2 [temp.deduct] and I found no clear rules why
above program would be ill-formed. However, I did find the following
paragraphs that, in my opinion, at the very least /hint/ that the
program is correct:

14.5.3/4 Decribes that a pack expansion could occur in a
/template-argument-list/, which I believe is the case in the
declaration of Bar.

It is not being mentioned in the non-deduced contexts in 14.8.2.5/5

14.8.2.5/8 States that a deduction can be made in the case of
template-name<T>

And furthermore, 14.8.2.5/9 pretty much states that "If P has a form
that contains <T> or <i>, [...] If Pi is a pack expansion, then the
pattern of Pi is compared with each remaining argument in the template
argument list of A. Each comparison deduces template arguments for
subsequent positions in the template parameter packs expanded by Pi"

Am I right in asserting that, based on above paragraphs, the program is
in fact well-formed C++11, and it just so happens that both VC++ as GCC
have a bug in this regard?


Regards,

Sylvester Hesp



--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]




Author: =?UTF-8?B?RGFuaWVsIEtyw7xnbGVy?= <daniel.kruegler@googlemail.com>
Date: Sun, 13 Jan 2013 14:33:50 CST
Raw View
Am 12.01.2013 20:23, schrieb Sylvester Hesp:
> I was playing around with the November '12 CTP preview of the VC++11
> compiler, which includes an implementation of variadic templates, and
> something interesting caught my eye.
>
> Consider the following program:
>
> ===================
> template<class T, class U>
> struct Foo { };
>
> template<class... Args>
> void Bar(Foo<Args...> f)
> {
> }
>
> template<class... Args>
> void Baz()
> {
>      Foo<Args...> f;
> }
>
> int main()
> {
>      Foo<int, float> f;
>      Bar(f);                    // #1
>      Bar<int, float>(f);        // #2
>      Baz<int, float>(f);        // #3

Given the definition of function Baz() above how on earth should #3
work? Did you intent to write

Baz<int, float>();         // #3

instead?

> }
> ===================
>
> This fails to compile using both VC++11 and GCC 4.6.3 (unfortunately I
> was not able to test a more recent version). VC++ in particular reports
> these errors:
>
> ===================
> test1.cpp(5): error C2976: 'Foo' : too few template arguments
>           test1.cpp(2) : see declaration of 'Foo'
> test1.cpp(18): error C2664: 'void Bar<>(Foo)' : cannot convert
> parameter 1 from 'Foo<int,float>' to 'Foo'
>           No user-defined-conversion operator available that can
> perform this conversion, or the operator cannot be called
> test1.cpp(20): error C2780: 'void Baz(void)' : expects 0 arguments - 1
> provided
>           test1.cpp(10) : see declaration of 'Baz'
> ===================

Its clear that #3 cannot work, but except from that the code should be
accepted. Looks like a compiler defect to me.

> My first reasoning was that I was simply hitting a compiler bug in
> VC++, but then I found out that GCC reported similar errors.

I have no gcc 4.6 here (it is rather out-aged), but current gcc 4.8
except the code except for #3.

> Am I right in asserting that, based on above paragraphs, the program is
> in fact well-formed C++11, and it just so happens that both VC++ as GCC
> have a bug in this regard?

I would suggest to submit a bug report to VC++. I don't think its worth
sending one for gcc, to my knowledge such fixes will not be applied in 4.6.

HTH & Greetings from Bremen,

Daniel Kr  gler



--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]