草庐IT

type_value

全部标签

C++ : has_trivial_X type traits

boost库,似乎是即将推出的C++0x标准,定义了各种类型特征模板,以区分具有平凡构造函数、复制构造函数、赋值或析构函数的对象与不具有平凡构造函数的对象。其最重要的用途之一是优化某些类型的算法,例如通过使用memcpy。但是,我不明白所有各种has_trivial_X模板之间真正的实际区别。C++标准只定义了我们在这里关注的两大类类型:POD和非POD。如果一个类型具有已定义的构造函数、复制构造函数、赋值运算符或析构函数,则该类型是非POD。换句话说,任何不是内置类型或内置类型的C结构的东西都不是POD。那么区分has_trivial_assign和has_trivial_const

c++ - boost 梅森扭曲器 : how to seed with more than one value?

我正在使用boostmt19937实现进行模拟。模拟需要可重现,这意味着存储RNG种子并可能在以后重复使用。我正在使用windowscryptoapi生成种子值,因为我需要种子的外部来源,而不是因为任何特定的随机性保证。任何模拟运行的输出都会有一个注释,包括RNG种子-所以种子需要相当短。另一方面,作为模拟分析的一部分,我将比较几次运行——但为了确保这些运行实际上不同,我需要使用不同的种子——所以种子需要足够长以避免意外碰撞。我已经确定64位的播种应该足够了;在大约2^32次运行后发生碰撞的可能性将达到50%——这个概率足够低,以至于由它引起的平均错误对我来说可以忽略不计。仅使用32位

c++ - 如何在获得 future 值(value)后重用 boost::promise 对象?

voidsss(boost::promise&res){res.set_value("hi");}voidyyy(boost::promise&res){res.set_value("hello");}intmain(){boost::threadth;boost::promisea;th=boost::thread(sss,boost::ref(a));th.join();std::cout我收到promise已经满足的错误。如何复用同一个Promise对象? 最佳答案 用未使用的promise替换它:a=boost::promi

c++ - 从 std::true_type 继承 vs static constexpr const bool 成员

我知道这不是一个非常尖锐的问题。使用一个比另一个有优势(编译时间、依赖性、调试符号大小、可用性、可读性等)吗?templatestructIsSharedPtr:std::false_type{};对比templatestructIsSharedPtr{staticconstexprboolvalue=false;};相关问题...templatestructS;templatestructS{};templatestructS{};对比templatestructS;templatestructS{};templatestructS{}; 最佳答案

c++ - G++ 4.4.7 中的 "names the constructor, not the type"

我有以下简单的C++代码:#includeclassA{public:A(inty):x(y){}A&operator=(constA&rhs);intx;};A::A&A::operator=(constA&rhs){this->x=rhs.x;return*this;}intmain(int,char**){Aa1(5);Aa2(4);printf("a2.x==%d\n",a2.x);a2=a1;printf("a2.x==%d\n",a2.x);return0;}第11行,A的operator=()函数的定义所在,格式不正确......或者,至少,我相信是这样。正如预期的那样,

.net - 警告 C4341 - 'XX' : signed value is out of range for enum constant

在编译我的C++.Net应用程序时,我收到104条警告类型:WarningC4341-'XX':signedvalueisoutofrangeforenumconstantXX可以在哪里字符长位二进制GUID...无论我做什么,我似乎都无法删除这些警告。当我双击它们时,它会将我带到使用OdbcParameters的代码的一部分-当我尝试使用我的所有其他东西但没有OdbcParameters的测试项目时,它不会发出警告。知道如何摆脱这些警告吗?他们从我实际上很难看到的代码中发出真正的警告-知道我的应用程序有104个警告让我感觉很糟糕! 最佳答案

c++ - 前向声明的类型和 "non-class type as already been declared as a class type"

我对以下代码有疑问:templatevoidfoo(structbar&b);structbar{};intmain(){}它在GCC上编译成功,但在MSVC(2008)上编译失败并出现以下错误:C2990:“bar”:已声明为类类型的非类类型是代码错误还是MSVC中的错误?如果我在模板定义之前添加structbar;就可以了。 最佳答案 我们有我们的赢家:https://connect.microsoft.com/VisualStudio/feedback/details/668430/forward-declared-type-

c++ - 错误 C2678 : binary '=' : no operator found which takes a left-hand operand of type 'const Recipe' (or there is no acceptable conversion)

我正在尝试对每个元素中包含一个int和一个字符串的vector进行排序。它是一个称为vector食谱的类类型的vector。出现上述错误,这是我的代码:在我的Recipe.h文件中structRecipe{public:stringget_cname()const{returnchef_name;}private:intrecipe_id;stringchef_name;在我的Menu.cpp文件中voidMenu::show()const{sort(recipes.begin(),recipes.end(),Sort_by_cname());}在我的Menu.h文件中#include

c++ - std::is_convertible 用于 type_info

在C++11中,可以通过usingstd::is_convertible确定类型A的变量是否可以隐式转换为类型B.如果你真的知道类型A和B,这很有效,但我只有type_infos。所以我正在寻找的是这样的功能:boolmyIsConvertible(consttype_info&from,consttype_info&to);是否可以在C++中实现类似的东西?如果是,怎么办? 最佳答案 在可移植的C++中做你想做的事是不可能的。可能如果您将自己限制在给定的平台上,则有可能获得部分答案。例如那些遵守ItaniumABI的平台将实现此功

c++ - CRTP + 特征类 : "no type named..."

我尝试使用模板化类实现CRTP,但在使用以下示例代码时出现错误:#includetemplateclassTraits{public:typedeftypenameT::typetype;//'staticconstunsignedintm_const=T::m_const;staticconstunsignedintn_const=T::n_const;staticconstunsignedintsize_const=T::m_const*T::n_const;};templateclassCrtp{public:typedeftypenameTraits::typecrtp_typ