草庐IT

upload_max_size

全部标签

c++ - tuple_size 的特化不一致

当为某个模板显式特化tuple_size和tuple_element时,我意识到§14.5.1/4,它是这样写的Inaredeclaration,partialspecialization,explicitspecializationorexplicitinstantiationofaclasstemplate,theclass-keyshallagreeinkindwiththeoriginalclasstemplatedeclaration(7.1.6.3).似乎违反了标准本身:我是否遗漏了什么(例如,标准规定class-key“仅供说明”并且应在实际实现中达成一致)?

c++ - 为什么 rand() 在以 1 和 UINT_MAX 为种子时产生相同的值?

这是一些代码:#includeintmain(){srand(1);std::cout这会产生以下输出:1680716807为什么这两个种子会产生相同的结果?它们在连续的rand()调用中产生的整个值序列也是相同的。可能值的范围太大,这不可能是纯巧合。是吗:rand()的执行意外(如果是这样,我很好奇那可能是什么)通过设计(如果是,为什么?)(可能相关:种子10、100、1000、10000和100000分别产生168070、1680700、16807000、168070000和1680700000。) 最佳答案 一个非常简单可用的

C++ 枚举类 std::size_t 隐式转换

我通过创建一个枚举类定义了一个元组及其索引:/**parameter{key;value1;value1;}*/usingParameter=std::tuple;enumclassParameterKey:std::size_t{KEY=0,VALUE1=1,VALUE2=2};现在我想从这个元组中获取一个值:constauto&key=std::get(*parameterPointer);我认为从int到std::size_t的隐式转换是由:std::size_t语法确保的:enumclassParameterKey:std::size_t{....}但是我收到了这个错误erro

c++ - SIMD:实现 _mm256_max_epu64_ 和 _mm256_min_epu64_

我想问一个关于SIMD的问题。我的CPU中没有AVX512但想要一个_mm256_max_epu64.我们如何用AVX2实现这个功能?在这里,我尝试拥有我的微不足道的。也许我们可以将其作为讨论并加以改进。#defineSIMD_INLINEinline__attribute__((always_inline))SIMD_INLINE__m256i__my_mm256_max_epu64_(__m256ia,__m256ib){uint64_t*val_a=(uint64_t*)&a;uint64_t*val_b=(uint64_t*)&b;uint64_te[4];for(size_t

c++ - 推导非类型模板参数 Unsigned Int/size_t

我正在尝试推断一个非类型模板参数。#includetemplatevoidgetsize(unsignedints){std::cout(4);//orevengetsize();//Isthispossible?}但是我得到了错误:deduce_szie_t.cpp:Infunction'intmain()':deduce_szie_t.cpp:9:15:error:nomatchingfunctionforcallto'getsize(unsignedint)'deduce_szie_t.cpp:9:15:note:candidateis:deduce_szie_t.cpp:4:6

c++ - 使用 size_t 索引以相反的顺序枚举数组

假设我们需要以相反的顺序打印大小为N的int数组://Wrong,iisunsignedandalways>=0:for(size_ti=N-1;i>=0;--i){cout=0;--i){cout0;--i){cout是否有更好的方法来使用size_t索引进行此类枚举并且无需在循环中进行额外操作?假设(size_t)0-1给出(size_t)(-1)还是未定义是否有效? 最佳答案 您可以将减量移动到条件“之后”。for(size_ti=N;i>0;){--i;cout它不像前向循环那么优雅,但它可以工作。我们在0处中断,所以i永远

c++ - 使用 vector<int>::size_type 和普通整数有什么区别?

我是c++STL语言的初学者。我想知道这两个代码之间的区别。我问过我的friend,但他说两者是一样的。任何人都可以解释这两个是否相同。并解释为什么这些不同#include#includeusingnamespacestd;intmain(){vectorstudent_marks(20);for(vector::size_typei=0;i>student_marks[i];}return0;}和#include#includeusingnamespacestd;intmain(){vectorstudent_marks(20);for(inti=0;i>student_marks[

c++ - lambda 函数中的 max_element

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭7年前。Improvethisquestion我实现了这个功能,但它仍然给出以下错误,我无法弄清楚为什么../usr/include/c++/4.8/bits/stl_algo.h:6325:error:nomatchforcallto'(Farm::killHeaviestAnimalOnFarm

c++ - 无法将 'int (*)[size]' 转换为 'int**'

我有一个256x256的二维float组,我试图将其传递给函数,但g++给我错误消息:无法将'int(*)[256]'转换为'int**'。我该如何解决这个问题?voidhaar2D(int**imgArr);intimageArray[256][256];haar2D(imageArray);我曾尝试将函数参数更改为int[256][256]和int*[256]类型,但没有成功。 最佳答案 必须按照编译器的要求声明函数参数。所以声明它要么像voidhaar2D(intimgArr[256][256]);或voidhaar2D(in

c++ - 从 'size_t' 到 'rapidjson::SizeType' 的转换

我有这个C++示例代码:voidtest(){rapidjson::Documentdoc;doc.SetObject();conststd::stringsource="Thequickbrownfoxjumpsoverthelazydog";rapidjson::Valuesource_val;source_val.SetString(source.c_str(),source.length(),doc.GetAllocator());}在编译时,在x64平台上,我收到此警告:warningC4267:'argument':conversionfromsize_ttorapidjs