I have this code:
#include <iostream>
#include <type_traits>
using namespace std;
template<typename T>
T f2(T&&t) {
return t;
}
int rr(int i) {
return 40*i;
}
int main()
{
cout << is_function< remove_reference<decltype(f2(rr))>::type>::value << endl;
}
When compiled with VC++2015, i got this error:
error C2893: Failed to specialize function template 'T f2(T &&)'
The main issue is with using decltype()
on the expression f2(rr)
. Note that f2
's parameter is T&&
. This is called Universal Reference by Scott Meyers: universal reference. I am expecting f2(rr)
yields an expression whose type is a function reference. In GCC, it runs normally and returns true, and hence, confirms that f2(rr)
is a function reference.
Is this simply a bug with VC++2015 rather than undefined behavior when the univeral reference is used with a function name?
EDIT: This works correctly in VC++2015:
int main()
{
cout << f2(rr)(10) <<endl;
}
result:
400
Aucun commentaire:
Enregistrer un commentaire