草庐IT

fixed-size-types

全部标签

c++ - 为什么 std::vector max_size() 函数会返回 -1?

我有一个std::vectorm_vData;m_vData.max_size()总是返回-1。为什么会这样? 最佳答案 可能是因为您在查看之前将其分配给签名类型。max_size的返回值通常是size_t,这是一个无符号类型。在许多平台上直接转换为int将返回-1。试试下面的方法std::vector::size_typev1=myVector.max_size(); 关于c++-为什么std::vectormax_size()函数会返回-1?,我们在StackOverflow上找到一

c++ - `void func() throw(type)` 有什么意义?

我知道这是一个有效的C++程序。函数声明中的throw有什么意义?据我所知,它什么都不做,也不用于任何事情。#includevoidfunc()throw(std::exception){}intmain(){return0;} 最佳答案 它指定任何std::exception都可以从func()中抛出,除此之外别无他法。如果抛出其他东西,它将调用一个unexpected()函数,该函数默认调用terminate()。这意味着抛出其他东西几乎肯定会以与未捕获异常相同的方式终止程序,但实现必须强制执行此操作。这通常与在func()周围

c++ - 无法在 VS 14 CTP : conditional expression of type 'void' is illegal 中使用 auto 声明 lambda

使用VisualStudio2014CTP、C++(v140)编译器:autogp=[&](BYTE*buff){autogp1=[](char*bff,char**p1){*p1=strstr((char*)bff,"(");return(*p1);};};错误:conditionalexpressionoftype'void'isillegal(也许auto真的输入错误?)如果我将内部lambda声明为std::functiongp1然后就可以了是我做错了什么还是编译器错误? 最佳答案 我没有运行2014,但您可能需要指定内部l

c++ - 使用前向声明时如何修复 "field has incomplete type"错误

如注释中所述,此代码抛出编译器错误error:field‘fTarget’hasincompletetype。为什么会这样?我只是分配那个字段而不做任何需要知道里面是什么的操作......或者我是?也许它无法弄清楚复制构造函数?classFSRVertex;//fwdclassFSREdge{public:charfC;FSRVertexfTarget;//compilererrorFSREdge(charc,FSRVertextarget):fC(c),fTarget(target){}//compilererror};classFSRVertex{public:boost::uno

c++ - Size of the Byte 是否可以大于 octet 8 bits

我正在浏览http://www.parashift.com/c++-faq/index.html在那里我发现字节也可以是64位http://www.parashift.com/c++-faq/very-large-bytes.html.一个字节的那么多存储容量有什么用? 最佳答案 重点不在于大字节“本身”的用处,而在于,对于标准而言,字节是系统上的最小可寻址数量1;如果系统无法以小于64位的单位寻址其内存,则char将为64位。显然,在现代通用计算机上几乎不可能找到这种奇怪的东西,这些奇怪的东西出现在非常专业的硬件上(我听说DSP特

c++ - 错误 C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'

下面是一个给出编译时错误的程序。这主要与D类中的Boo函数有关。我最终尝试使用多个线程来调用solve方法,但目前这对我来说似乎不太有效,无法做到这一点。错误是:1>d:\dummy\project1\trash.cpp(37):warningC4101:'d':unreferencedlocalvariable1>c:\programfiles(x86)\microsoftvisualstudio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(240):errorC2672:'std::invoke':no

c++ - std::vector 应该尊重 alignof(value_type) 吗?

如果我定义一个具有特定对齐要求的简单类型,该类型的std::vector难道不应该为每个元素遵守对齐吗?考虑下面的例子typedefstd::arrayalignas(32)avx_point;std::vectorx(10);assert(!(std::ptrdiff_t(&(x[0]))&31)&&//assertthatx[0]is32-bytealigned!(std::ptrdiff_t(&(x[1]))&31));//assertthatx[1]is32-bytealigned我发现clang3.2(带或不带-stdlib=libc++)悄悄地(没有任何警告)违反了对齐要求

c++ - std::hardware_destructive_interference_size 的可靠性

C++17引入了常量,这似乎对缓存感知编程很有用:https://en.cppreference.com/w/cpp/thread/hardware_destructive_interference_sizeinlineconstexprstd::size_thardware_destructive_interference_size,inlineconstexprstd::size_thardware_constructive_interference_size尽管我想知道它们的可靠性如何?是否保证以后不会有相同CPU架构内具有其他缓存线大小的新CPU型号?即x64缓存行大小为64字

c++ - 振奋 spirit : What type names should be used for the built in terminals?

我正在重构一个类型系统(类型模型),它使用spirit进行字符串序列化。我正在使用类型特征的编译时建模构造。templatetype_traits{typedefboost::spirit::qi::int_parserstring_parser;}templatetype_traits{typedefboost::spirit::ascii::stringstring_parser;}在这个例子中,我展示了原始解析器,但我希望也加入规则。int4类型有效,但这是因为(home/qi/numeric/int.hpp+27):namespacetag{templatestructint_

c++ - "size_t"作为类型参数,未重现转换警告

我一直在尝试消除一些旧代码中的警告(必须使用MSVC2005,目前使用32位构建),但一直在努力消除size_t至unsignedint转换警告。我们有自己的Array实现一个不断增长的数组的实现templateconstT&at(constIi)const{returnatImpl(i);}方法。当调用为size_ti=10;myArray.at(i);我得到一个conversionfrom'size_t'to'constunsignedint',possiblelossofdata警告。一个工作理论是I理解为unsignedint,这导致编译器强制转换/转换size_t至unsig