I realize "why are things the way they are" questions are not usually the best, but there are many people on SO that are tuned to standard committee discussions so I hope this can be answered factually, as I'm legitimately curious as to what the answer is.
Basically, it took me a long time to figure out what was going on with std::result_of
's template signature the first time I saw it: I thought it was an entirely new construct for template parameters that I had never seen before.
template< class F, class... ArgTypes >
class result_of<F(ArgTypes...)>;
After some time thinking about it, I realized what this actually was: F(ArgTypes...)
is a function type, but it's not the type of the function whose result type is being evaluated (that's just F
): it's the type of a function taking ArgTypes...
arguments and returning type F
.
Isn't this...odd? Kind of hackish? Does anyone know if the committee ever discussed any alternatives, like, say, the following...
template< class F, class... ArgTypes >
class result_of<F, ArgTypes...>;
?
I guess it's possible that there's situations where the second construct can't be used as easily as the first one, but which ones?
I'm not trying to pass judgement on this, but it's just that this was legitimately confusing to me the first time I saw it, so I'm curious if there's a good reason for it. I realize part of the answer might simply be "because Boost did it" that way, but still that leave the remaining (factual) questions...
Is there a technical reason Boost choose this syntax to encode type information rather than any alternative?
Was there any discussion by the C++11 committee about how appropriate it was to standardize this, given that
std::result_of
can be implemented in terms ofdecltype
fairly easily anyway?
std::tuple
faux varadic approach would have been too hard either, really...I could be wrong though) – Enthusiasm