草庐IT

static_visitor

全部标签

c++ - 为什么 C++11 中没有 `static_if`

就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter寻求指导。关闭9年前。我想知道为什么像static_if这样自然的东西没有设法进入C++11?有些人反对使用继承或模板特化我们可以实现所需的结果但是:为什么我们没有一个简单的static_if来应对不想让源代码膨胀的简单情况? 最佳答案 我想委员会没有时间讨论这个特性,所以他们决定在C++11之后推迟它。无论如何建议在这

c++ - 为什么 C++11 中没有 `static_if`

就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter寻求指导。关闭9年前。我想知道为什么像static_if这样自然的东西没有设法进入C++11?有些人反对使用继承或模板特化我们可以实现所需的结果但是:为什么我们没有一个简单的static_if来应对不想让源代码膨胀的简单情况? 最佳答案 我想委员会没有时间讨论这个特性,所以他们决定在C++11之后推迟它。无论如何建议在这

c++ - static_assert 可以检查类型是否为 vector 吗?

static_assert可以检查一个类型是否是一个vector吗?IE,一个int会提出断言,而vector不会。我正在考虑以下内容:static_assert(decltype(T)==std::vector,"Someerror") 最佳答案 是的。考虑以下元函数:#include#includetemplatestructis_vector{staticconstintvalue=0;};templatestructis_vector>{staticconstintvalue=1;};intmain(){printf("is

c++ - static_assert 可以检查类型是否为 vector 吗?

static_assert可以检查一个类型是否是一个vector吗?IE,一个int会提出断言,而vector不会。我正在考虑以下内容:static_assert(decltype(T)==std::vector,"Someerror") 最佳答案 是的。考虑以下元函数:#include#includetemplatestructis_vector{staticconstintvalue=0;};templatestructis_vector>{staticconstintvalue=1;};intmain(){printf("is

C++ vector 问题 - 'LNK2001: unresolved external symbol private: static...'

在有人指责我不查看预先存在的问题之前,我已经查看并意识到它与声明有关,但我仍然无法让它工作(可能与我使用vector有关)。Manager.h:#include"Flight.h"#ifndefmanager_h#definemanager_hclassManager{staticvectorairports;staticvectorflights;public:staticvoidloadAirports();staticvoidloadFlights();staticAirportgetAirport(stringcode);staticvectorsplit(conststrin

C++ vector 问题 - 'LNK2001: unresolved external symbol private: static...'

在有人指责我不查看预先存在的问题之前,我已经查看并意识到它与声明有关,但我仍然无法让它工作(可能与我使用vector有关)。Manager.h:#include"Flight.h"#ifndefmanager_h#definemanager_hclassManager{staticvectorairports;staticvectorflights;public:staticvoidloadAirports();staticvoidloadFlights();staticAirportgetAirport(stringcode);staticvectorsplit(conststrin

c++ - static 对 const 局部变量有影响吗?

想象以下声明:voidfoo(){conststd::arrayarr={/*alotofdifferentvalues*/};//dostuff}还有第二个:voidfoo(){staticconststd::arrayarr={/*alotofdifferentvalues*/};//dostuff}如果有的话,这两者之间可能存在哪些性能差异?这些解决方案是否存在任何危险? 最佳答案 暂时忘记数组。这混淆了两个不同的问题。您已经找到了解决生命周期和存储问题的答案。我将解决初始化问题。voidf(){staticconstintx

c++ - static 对 const 局部变量有影响吗?

想象以下声明:voidfoo(){conststd::arrayarr={/*alotofdifferentvalues*/};//dostuff}还有第二个:voidfoo(){staticconststd::arrayarr={/*alotofdifferentvalues*/};//dostuff}如果有的话,这两者之间可能存在哪些性能差异?这些解决方案是否存在任何危险? 最佳答案 暂时忘记数组。这混淆了两个不同的问题。您已经找到了解决生命周期和存储问题的答案。我将解决初始化问题。voidf(){staticconstintx

c++ - 在类型特征中,为什么人们使用 enum 而不是 static const 作为值?

例如,我就是这样写的,它编译和工作得很好:templatestructis_pointer{staticconstboolvalue=true;}那为什么有些人写的不那么明显templatestructis_pointer{enum{value=true};}相反?仅仅是因为staticconst变量使用了一个字节的内存,而enum没有? 最佳答案 一个显着的区别在于以下代码的编译和链接:templatestructis_pointer{};templatestructis_pointer{enum{value=true};};vo

c++ - 在类型特征中,为什么人们使用 enum 而不是 static const 作为值?

例如,我就是这样写的,它编译和工作得很好:templatestructis_pointer{staticconstboolvalue=true;}那为什么有些人写的不那么明显templatestructis_pointer{enum{value=true};}相反?仅仅是因为staticconst变量使用了一个字节的内存,而enum没有? 最佳答案 一个显着的区别在于以下代码的编译和链接:templatestructis_pointer{};templatestructis_pointer{enum{value=true};};vo