議論の控除が私が予想するように機能しない理由を誰かが教えてもらえますか?私の考え方については、私のコードコメントを参照してください。
#include <iostream>
#include <type_traits>
#include <iomanip>
#include <string>
using namespace std;
template<class T>
void deduce1(T args, string arg){
cout << "template<class T> void deduce1(T args) " << " argument passed in was: " << arg << " deduced as: " << typeid(T).name() << endl;
cout << "Is const: " << boolalpha << is_const<T>::value << endl;
cout << "Is reference: " << boolalpha << is_reference<T>::value << endl;
cout << "Is pointer: " << boolalpha << is_pointer<T>::value << endl;
}
template<class T>
void deduce2(T& args,string arg){
cout << "template<class T> void deduce2(T args) " << " argument passed in was: " << arg << " deduced as: " << typeid(T).name() << endl;
cout << "Is const: " << boolalpha << is_const<T>::value << endl;
cout << "Is reference: " << boolalpha << is_reference<T>::value << endl;
cout << "Is pointer: " << boolalpha << is_pointer<T>::value << endl;
}
template<class T>
void deduce3(T&& args,string arg){
cout << "template<class T> void deduce3(T args) " << " argument passed in was: " << arg << " deduced as: " << typeid(T).name() << endl;
cout << "Is const: " << boolalpha << is_const<T>::value << endl;
cout << "Is reference: " << boolalpha << is_reference<T>::value << endl;
cout << "Is rvalue reference: " << boolalpha << is_rvalue_reference<T>::value << endl;
cout << "Is pointer: " << boolalpha << is_pointer<T>::value << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
int a = 1;
const int b = 5;
int c[] = {12};
int const d[] = {12};
int& e = a;
deduce1(a,"int a = 1");
deduce1(b,"const int b = 5");
deduce1(c,"int c[] = {12}");
deduce1(d,"int const d[] = {12}"); // would have thought is_const<T> would return true any comments?
deduce1(e,"int& e = a");
deduce1(5,"5");
deduce2(a,"int a = 1");
deduce2(b,"const int b = 5"); //would have though type would be deduced as int const comments?
deduce2(c,"int c[] = {12}"); // why is this not returning true as a reference?
deduce2(d,"int const d[] = {12}"); // would have thought is_const<T> would return true any comments
deduce2(e,"int& e = a");
deduce3(a,"int a = 1");
deduce3(b,"const int b = 5");
deduce3(c,"int c[] = {12}"); // why is this not returning true as a reference?
deduce3(d,"int const d[] = {12}"); // would have thought is_const<T> would return true any comments
deduce3(e,"int& e = a");
deduce3(string("Hello"),"string(\"Hello\")"); // why not rvalue reference
return 0;
}