我通过"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