* Re: C++11 - Parameter pack question
[not found] <201408160114.s7G1EKDO087976@nef2.ens.fr>
@ 2014-08-16 7:12 ` Marc Glisse
[not found] ` <alpine.DEB.2.11.1408160907210.1729@laptop-mg.saclay.inria. fr>
0 siblings, 1 reply; 5+ messages in thread
From: Marc Glisse @ 2014-08-16 7:12 UTC (permalink / raw)
To: Sidney Marshall; +Cc: gcc-help
On Fri, 15 Aug 2014, Sidney Marshall wrote:
> The following code compiles and runs correctly but gives a warning:
>
> ----------------------------------------
> #include<iostream>
>
> using namespace std;
>
> template<class T>
> T sum(T value) {
> return value;
> }
>
> template<class T, class ... U>
> auto sum(T value, U ... values) {
> return value + sum(values ...);
> }
>
> int main() {
> cout << sum(1, 2, 4.6) << endl;
> cout << sum(1, "abcde", 2) << endl;
> }
> --------------------------------------
>
> $ g++ -std=c++11 pack.cpp
> pack.cpp:11:31: warning: â??sumâ?? function uses â??autoâ?? type specifier
> without trailing return type [enabled by default]
> auto sum(T value, U ... values) {
The warning should probably specify that this is a C++14 feature. You
should be compiling with -std=c++1y.
--
Marc Glisse
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: C++11 - Parameter pack question
[not found] ` <alpine.DEB.2.11.1408160907210.1729@laptop-mg.saclay.inria. fr>
@ 2014-08-17 2:28 ` Sidney Marshall
2014-08-17 2:28 ` Sidney Marshall
1 sibling, 0 replies; 5+ messages in thread
From: Sidney Marshall @ 2014-08-17 2:28 UTC (permalink / raw)
To: gcc-help; +Cc: Sidney Marshall, gcc-help
At 09:12 AM 8/16/2014 +0200, Marc Glisse wrote:
>On Fri, 15 Aug 2014, Sidney Marshall wrote:
>
>>The following code compiles and runs correctly but gives a warning:
>>
>>----------------------------------------
>>#include<iostream>
>>
>>using namespace std;
>>
>>template<class T>
>>T sum(T value) {
>> return value;
>>}
>>
>>template<class T, class ... U>
>>auto sum(T value, U ... values) {
>> return value + sum(values ...);
>>}
>>
>>int main() {
>> cout << sum(1, 2, 4.6) << endl;
>> cout << sum(1, "abcde", 2) << endl;
>>}
>>--------------------------------------
>>
>>$ g++ -std=c++11 pack.cpp
>>pack.cpp:11:31: warning: â??sumâ?? function
>>uses â??autoâ?? type specifier without trailing
>>return type [enabled by default]
>>auto sum(T value, U ... values) {
>
>The warning should probably specify that this is
>a C++14 feature. You should be compiling with -std=c++1y.
You are correct - I didn't read section 7.1.6.4
paragraphs 2 and 5 of the standard correctly. Thank you.
I guess I can't write this function in C++11 this way.
>--
>Marc Glisse
--Sidney Marshall
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: C++11 - Parameter pack question
[not found] ` <alpine.DEB.2.11.1408160907210.1729@laptop-mg.saclay.inria. fr>
2014-08-17 2:28 ` Sidney Marshall
@ 2014-08-17 2:28 ` Sidney Marshall
1 sibling, 0 replies; 5+ messages in thread
From: Sidney Marshall @ 2014-08-17 2:28 UTC (permalink / raw)
To: gcc-help; +Cc: Sidney Marshall, gcc-help
At 09:12 AM 8/16/2014 +0200, Marc Glisse wrote:
>On Fri, 15 Aug 2014, Sidney Marshall wrote:
>
>>The following code compiles and runs correctly but gives a warning:
>>
>>----------------------------------------
>>#include<iostream>
>>
>>using namespace std;
>>
>>template<class T>
>>T sum(T value) {
>> return value;
>>}
>>
>>template<class T, class ... U>
>>auto sum(T value, U ... values) {
>> return value + sum(values ...);
>>}
>>
>>int main() {
>> cout << sum(1, 2, 4.6) << endl;
>> cout << sum(1, "abcde", 2) << endl;
>>}
>>--------------------------------------
>>
>>$ g++ -std=c++11 pack.cpp
>>pack.cpp:11:31: warning: â??sumâ?? function
>>uses â??autoâ?? type specifier without trailing
>>return type [enabled by default]
>>auto sum(T value, U ... values) {
>
>The warning should probably specify that this is
>a C++14 feature. You should be compiling with -std=c++1y.
You are correct - I didn't read section 7.1.6.4
paragraphs 2 and 5 of the standard correctly. Thank you.
I guess I can't write this function in C++11 this way.
>--
>Marc Glisse
--Sidney Marshall
^ permalink raw reply [flat|nested] 5+ messages in thread
* C++11 - Parameter pack question
@ 2014-08-16 1:14 Sidney Marshall
0 siblings, 0 replies; 5+ messages in thread
From: Sidney Marshall @ 2014-08-16 1:14 UTC (permalink / raw)
To: gcc-help; +Cc: sidneym
Hello,
The following code compiles and runs correctly but gives a warning:
----------------------------------------
#include<iostream>
using namespace std;
template<class T>
T sum(T value) {
return value;
}
template<class T, class ... U>
auto sum(T value, U ... values) {
return value + sum(values ...);
}
int main() {
cout << sum(1, 2, 4.6) << endl;
cout << sum(1, "abcde", 2) << endl;
}
--------------------------------------
$ g++ -std=c++11 pack.cpp
pack.cpp:11:31: warning: âsumâ function uses
âautoâ type specifier without trailing return type [enabled by default]
auto sum(T value, U ... values) {
$ ./a.exe
7.6
de
-------------------------------------------
All of my attempts to use a trailing return type
failed (and I believe should have failed according to the standard).
My two questions:
1. What possible user mistake is the warning worried about?
2. How can I write my code with better style so that there is no warning?
Thank you.
--Sidney Marshall
^ permalink raw reply [flat|nested] 5+ messages in thread
* C++11 - Parameter pack question
@ 2014-08-16 1:14 Sidney Marshall
0 siblings, 0 replies; 5+ messages in thread
From: Sidney Marshall @ 2014-08-16 1:14 UTC (permalink / raw)
To: gcc-help; +Cc: sidneym
Hello,
The following code compiles and runs correctly but gives a warning:
----------------------------------------
#include<iostream>
using namespace std;
template<class T>
T sum(T value) {
return value;
}
template<class T, class ... U>
auto sum(T value, U ... values) {
return value + sum(values ...);
}
int main() {
cout << sum(1, 2, 4.6) << endl;
cout << sum(1, "abcde", 2) << endl;
}
--------------------------------------
$ g++ -std=c++11 pack.cpp
pack.cpp:11:31: warning: âsumâ function uses
âautoâ type specifier without trailing return type [enabled by default]
auto sum(T value, U ... values) {
$ ./a.exe
7.6
de
-------------------------------------------
All of my attempts to use a trailing return type
failed (and I believe should have failed according to the standard).
My two questions:
1. What possible user mistake is the warning worried about?
2. How can I write my code with better style so that there is no warning?
Thank you.
--Sidney Marshall
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-08-17 2:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <201408160114.s7G1EKDO087976@nef2.ens.fr>
2014-08-16 7:12 ` C++11 - Parameter pack question Marc Glisse
[not found] ` <alpine.DEB.2.11.1408160907210.1729@laptop-mg.saclay.inria. fr>
2014-08-17 2:28 ` Sidney Marshall
2014-08-17 2:28 ` Sidney Marshall
2014-08-16 1:14 Sidney Marshall
-- strict thread matches above, loose matches on Subject: below --
2014-08-16 1:14 Sidney Marshall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).