我通過"C++ Template Metaprogramming" by Abrahams & Gurtovoy工作「 這實際上不是在第二章,但是是我嘗試過,而在第一次演練工作(2.10,2.0),這是混淆了我:爲什麼boost :: is_same <int const&,boost :: add_const <int &> :: value等於false?
#include <iostream>
#include <boost/type_traits.hpp>
std::string display(bool b)
{
return (b ? "true" : "false");
}
int main()
{
using namespace std;
cout << display(boost::is_same<int const&, boost::add_const<int &>::type >::value) << "\n";
return 0;
}
輸出爲' false' 但是,如果我刪除了引用,即'int const'和'int'。輸出爲'true'。
順便說一句你可以通過設置'std :: cout << std :: boolalpha;' – juanchopanza 2011-06-02 16:51:34