草庐IT

Size_type

全部标签

报错:JSON parse error: Cannot deserialize value of type `long` from String “1,2“: not a valid `long` v

详细报错信息JSON parse error: Cannot deserialize value of type `long` from String "1,2": not a valid `long` value; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `long` from String "1,2": not a valid `long` value at [Source: (org.springframe

c++ - 将 std::string 解释为 char_type 的 std::vector?

我有一个template接受constvector&的函数.在所述函数中,我有vectorcbegin(),cend(),size(),和operator[].据我了解,string和vector使用连续空间,所以我想知道我是否可以以一种优雅的方式为两种数据类型重用该函数。可以std::string被重新解释为std::vector的(适当的)char_type?如果可以,限制是什么? 最佳答案 如果你只为constT&类型制作你的模板,并使用begin()、end()等,这两个函数vector和string共享,那么您的代码将适用

c++ - gcc-4.9.2 : non-type template parameter

我在gcc-4.9.2上有一个奇怪的编译错误,相同的代码在其他编译器上工作,比如gcc-4.8或我能找到的任何clang。问题与non-typetemplate-arguments有关.所以考虑一下:#include#includeinttemplateParam;templatestructTestTemplate{intvalue(){}};templateintTestTemplate::value(){returntemplateParam;}TestTemplatetestVariable;intmain(){std::cout我在gcc-4.9.2中遇到以下错误:prog.

c++ - 为什么 std::span 缺少 size_type?

我一直在将使用我的自制span类的旧代码更新为更符合C++20std::span的代码,但我遇到了编译错误,因为std::span没有size_type而是有index_type。关于index_type是否应该签名的问题一直存在争议,但为什么要跳过size_type?这打破了期望容器(或类似容器的对象)具有size_type的通用代码。 最佳答案 原提案P1022R0,当它被称为array_view时,有一个size_type成员。它在第一次修订中被删除了P1022R1作为简化的一部分,因为当时不需要size()和元素访问,使用带

c++ - constexpr 与 std::array - "Non-type template argument is not a constant expression"

这个问题在这里已经有了答案:Errorusingaconstexprasatemplateparameterwithinthesameclass(2个答案)关闭9年前。我正在尝试实现以下内容:#include#includeclassClass2{};classClass1{public:staticconstexpruint8_tGetMax(){return5;}staticconstexpruint8_tGetMin(){return0;}staticconstexpruint8_tGetCount(){returnGetMax()-GetMin()+1;}private:std

c++ - 为什么 push_back 签名是 void push_back (const value_type& val) 而不是 void push_back (value_type val)?

这个问题在这里已经有了答案:Passingbyvaluevsconst&and&&overloads(3个答案)关闭8年前。为什么push_back的函数签名如下?voidpush_back(constvalue_type&val);传递的值被复制到容器中,为什么不直接复制到参数列表中呢?voidpush_back(value_typeval);

c++ - 将 size_t 转换为整数 (c++)

我一直在尝试制作一个for循环,该循环将根据网络数据包的长度进行迭代。在API中,event.packet->dataLength存在一个变量(size_t)。我想从0迭代到event.packet->dataLength-7每次迭代时将i增加10,但我遇到了很多麻烦。我寻找解决方案,但找不到任何有用的东西。我尝试将size_t转换为unsignedint并用它进行算术运算,但不幸的是它没有用。基本上我想要的是:for(inti=0;idataLength-7;i+=10){}虽然每次我做这样的事情或尝试我的转换时,我 最佳答案 你

c++ - 是否有标准名称(模板或宏)来替换 ARRAY_SIZE、_countof 等?

我不是在谈论std::array或任何东西,只是经典的VanillaC/C++数组。我知道可以实现ARRAY_SIZE/_countof的各种方式,我只是想知道他们是否已经设法为此标准化了一个名称(在std::我假设)。如果没有,是否有相关建议? 最佳答案 当前的解决方法std::extent-数组的大小如果您正在使用native数组,您可以使用std::extent来自,用于生成数组的Nth维(默认为第一个)中的元素数。inta1[1024];inta2[std::extent::value];//int[1024]一点间接(通用

c++ - std::atomic<X>::value_type 发生了什么?

根据thisreferencemanualForeverystd::atomic(whetherornotspecialized),std::atomic::value_typeisX.但是如果我尝试使用这种类型,我会得到一个编译错误。我用g++8.2.1试过了:$g++-std=c++11test.cctest.cc:Infunction‘intmain()’:test.cc:6:23:error:‘value_type’isnotamemberof‘std::atomic’std::atomic::value_typex=0;还有clang6.0.1$clang-std=c++11

c++ - C++11 是否为 std::type_info 提供散列函数?

我仍在为我的One-Of-A-TypeContainerProblem寻找一个好的解决方案--经过深思熟虑,我认为能够只使用像std::map这样的东西会很好.不幸的是,std::type_info没有定义operator,我认为它定义一个是不合理的。然而,为它定义一个散列函数似乎是合理的,因为你可以简单地使用std::type_info的单例地址。对象作为合理的“哈希”。因此,您可以输入std::type_info进入std::unordered_map作为关键。C++11有提供这样的哈希函数吗?将使用std::type_info的内存地址单例是一个糟糕的哈希策略?