Topic: Suffix Return Type Syntax.
Author: Kenshin <kenshin.himura.sakabato@gmail.com>
Date: Tue, 24 Nov 2009 12:47:31 CST Raw View
Hi. Given the below, to sum all arguments passed,
1. What should be coded in place of the "/*What goes here*/" part?
2. How can I modify this to use std::plus<>() instead?
template<class T1, class T2>
[]sum(const T1& t1, const T2& t2)->decltype(t1 + t2){
return t1 + t2;
}
template<class T1, class T2, class... T3> []sum(const T1& t1, const
T2& t2, const T3&... t3)->decltype(/*What goes here*/){
return t1 + sum(t2, t3...);
}
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Joe Smith" <unknown_kev_cat@hotmail.com>
Date: Tue, 24 Nov 2009 14:38:37 CST Raw View
"Kenshin" <kenshin.himura.sakabato@gmail.com> wrote in message
news:3853dc6a-9848-4247-aa46-1b8db97733ed@e7g2000vbi.googlegroups.com...
Hi. Given the below, to sum all arguments passed,
1. What should be coded in place of the "/*What goes here*/" part?
2. How can I modify this to use std::plus<>() instead?
template<class T1, class T2>
[]sum(const T1& t1, const T2& t2)->decltype(t1 + t2){
return t1 + t2;
}
template<class T1, class T2, class... T3> []sum(const T1& t1, const
T2& t2, const T3&... t3)->decltype(/*What goes here*/){
return t1 + sum(t2, t3...);
}
Why not the following?
template<class T1, class T2, class... T3> []sum(const T1& t1, const
T2& t2, const T3&... t3)->decltype(t1+sum(t2,t3...)){
return t1 + sum(t2, t3...);
}
Further, AFAIK, you cannot use std::plus here if you really want to
support mixed types with this function. If you do not wish to support
mixed types, then I'm not really sure. Neither varidict functions nor
variadict function templates seem to provide a way to specify a
variable number of arguments all of the same type.
I find that unfortunate, since being able to support a variable number
of arguments of some single specified type can be quite usefuk in some
cases.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- 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: Tue, 24 Nov 2009 16:17:59 CST Raw View
On 24 Nov., 21:38, "Joe Smith" <unknown_kev_...@hotmail.com> wrote:
> "Kenshin" <kenshin.himura.sakab...@gmail.com> wrote in message
>
> news:3853dc6a-9848-4247-aa46-1b8db97733ed@e7g2000vbi.googlegroups.com...
>
> Hi. Given the below, to sum all arguments passed,
>
> 1. What should be coded in place of the "/*What goes here*/" part?
> 2. How can I modify this to use std::plus<>() instead?
>
> template<class T1, class T2>
> []sum(const T1& t1, const T2& t2)->decltype(t1 + t2){
> return t1 + t2;
> }
>
> template<class T1, class T2, class... T3> []sum(const T1& t1, const
> T2& t2, const T3&... t3)->decltype(/*What goes here*/){
> return t1 + sum(t2, t3...);
> }
>
> Why not the following?
>
> template<class T1, class T2, class... T3> []sum(const T1& t1, const
> T2& t2, const T3&... t3)->decltype(t1+sum(t2,t3...)){
> return t1 + sum(t2, t3...);
>
> }
>
> Further, AFAIK, you cannot use std::plus here if you really want to
> support mixed types with this function. If you do not wish to support
> mixed types, then I'm not really sure. Neither varidict functions nor
> variadict function templates seem to provide a way to specify a
> variable number of arguments all of the same type.
>
> I find that unfortunate, since being able to support a variable number
> of arguments of some single specified type can be quite usefuk in some
> cases.
I certainly agree, that this is really complicated (but not
impossible).
In the draft N2723 the min/max/minmax overloads in [alg.min.max]
were intended to enforce a library implementation to realize that (but
the wording is not as good as it could be). AFIAK prototype
implementations
for these species realized that - even with the additional constraint
that
the last parameter should be a function object for the overloads
with a predicate instead of <, but these were far from trivial.
Greetings from Bremen,
Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]