草庐IT

VT_ARRAY

全部标签

c++ - 固定大小的 std::span 与 std::array

C++20包括std::span,which"describesanobjectthatcanrefertoacontiguoussequenceofobjectswiththefirstelementofthesequenceatpositionzero".它的接口(interface)非常接近std::array,尽管它支持动态范围和固定范围。明显的区别是std::array拥有它的元素(因此它的析构函数销毁它们)而std::span没有。还有什么array可以用于span不能的吗? 最佳答案 span是array,因为指针是指

c++ - 带有 std::tuple 数组的 std::array 不完整类型错误

我在使用C++11时遇到了一些奇怪的行为std::array.当我尝试使用std::array,6>myTuples;进行编译时作为成员变量,我得到这些错误:mingw32\4.7.2\include\c++\array:-1:Ininstantiationof'structstd::array,6u>':mingw32\4.7.2\include\c++\array:77:error:'std::array::_M_instance'hasincompletetype我不确定这是否有任何改变,但它所在的类是从另一个模板类派生的模板类。模板参数是unsignedintan确定prote

c++ - std::array 的嵌套聚合初始化

这个问题在这里已经有了答案:Whencanouterbracesbeomittedinaninitializerlist?(1个回答)关闭5年前。我想知道,为什么在下面的代码中声明std_arr会产生错误,而c_arr编译得很好:structS{inta,b;};Sc_arr[]={{1,2},{3,4}};//OKstd::arraystd_arr={{1,2},{3,4}};//Error:toomanyinitializersstd::array和S都是集合。来自aggregateinitializationoncppreference.com:Iftheinitializerc

c++ - 初始化非默认可构造元素的 std::array?

假设输入foo_t使用命名构造函数,make_foo().现在,我想要恰好有123个foo,不多也不少。所以,我正在考虑std::array.现在,如果foo_t是默认可构造的,我会写:std::arraypity_the_foos;std::generate(std::begin(pity_the_foos),std::end(pity_the_foos),[](){returnmake_foo();});Bob是我叔叔,对吧?不幸的是...foo_t没有默认构造函数。那么我应该如何初始化我的数组呢?我是否需要使用一些可变参数模板扩展巫术?注意:如果有帮助,答案可以使用C++11、C

c++ - 使用自定义删除器 boost scoped_ptr/scoped_array

我不知道如何让scoped_ptr或scoped_array使用自定义删除器。也许还有另一种实现类似于shared_ptr允许受控删除?顺便说一句,为什么shared_ptr允许自定义删除器而scoped_ptr不允许?只是好奇。 最佳答案 Idon'tseehowtogetscoped_ptrorscoped_arraytousecustomdeleter你不能。Maybethereisanotherimplementationwhichallowscontrolleddeletionsimilartoshared_ptr?如果您

c++ - 表达式 -2[array] 是如何工作的?

这个问题在这里已经有了答案:Witharrays,whyisitthecasethata[5]==5[a]?(19个回答)关闭6年前。我遇到了这个美女,但我真的看不懂!#includeusingnamespacestd;intmain(){intarray[]={10,20,30};cout它打印-30。提前谢谢你编辑:不是thisquestion的拷贝因为“-”号。

c++ - OpenGL 3 : glBindVertexArray invalidates GL_ELEMENT_ARRAY_BUFFER

我确信如果您通过glBindBuffer()绑定(bind)一个缓冲区,您可以安全地假设它保持绑定(bind)状态,直到目标通过另一次调用glBindBuffer()。因此,当我发现调用glBindVertexArray()会将绑定(bind)到GL_ELEMENT_ARRAY目标的缓冲区设置为0时,我感到非常惊讶。这是最小的C++示例代码:GLuintbuff;glGenBuffers(1,&buff);std::cout我在初始化OpenGL3.2设备上下文后立即运行此代码并获得以下输出:Bufferis1BoundbeforeglBindVertexArray:1Boundaft

c++ - 在编译时将 std::array 转换为另一种数据类型?

在C++11中有没有一种方法可以在编译时将一种类型的数组转换为另一种数据类型:#include#include#includeintmain(){staticconstexprstd::arraydarray{{1.5,2.5,3.5}};staticconstexprstd::arrayiarray(darray);//notworking//Isthereawaytocastanarraytoanotherdatatype?return0;} 最佳答案 不,但是您可以使用indicestrick轻松地手动完成,假设实现提供了co

c++ - OpenCV 2.3 : Convert Mat to RGBA pixel array

我正在尝试使用OpenCV从网络摄像头抓取帧并使用SFML在窗口中显示它们。VideoCapture以OpenCV的Mat格式返回帧。要显示帧,SFML需要uint8格式的一维像素数组,(据我所知)可以与uchar互换。该数组预计每像素RGBA表示32位。所以,我有一个uchar数组,我正在遍历Mat数据并复制每个像素:VideoCapturecap(0);Matframe;cap>>frame;uchar*camData=newuchar[640*480*4];uchar*pixelPtr=frame.data;for(inti=0;i不幸的是,这不太行得通。该循环中的某些地方是错误

c++ - 如何使用省略尾随 '\0' 的字符串文字初始化 std::array<char, N>

我有一个文件结构,其中固定长度的字符串没有尾随零。如何将字段初始化为不带尾随零的std::array:#pragmapack(push,1)structData{//Compiles,butithasanundesired'\0':std::arrayundesired_number{"12345"};//Doesnotcompile:std::arraynumber{"12345"};//stripping'\0'};#pragmapack(pop) 最佳答案 制作辅助函数templateconstexprstd::arrayto