范文健康探索娱乐情感热点
投稿投诉
热点动态
科技财经
情感日志
励志美文
娱乐时尚
游戏搞笑
探索旅游
历史星座
健康养生
美丽育儿
范文作文
教案论文
国学影视

C内置数组STLarraySTLvector

  T[N]
  Built-in array: a fixed-size contiguously allocated sequence of N elements of type T; implicitly converts to a T*
  内置数组:固定大小的连续分配的T型N个元素序列;隐式转换为T*
  array
  A fixed-size contiguously allocated sequence of N elements of type T; like the built-in array, but with most problems solved
  T型N个元素的固定大小连续分配序列;与内置数组类似,但大多数问题都已解决
  A vector is a sequence of elements of a given type. The elements are stored contiguously in memory. A typical implementation of vector will consist of a handle holding pointers to the first element, one-past-the-last element, and one-past-the-last allocated space (§13.1) (or the equivalent information represented as a pointer plus offsets):
  vector是给定类型的元素序列。元素连续存储在存储器中。vector的典型实现将由一个句柄组成,该句柄持有指向第一个元素的指针,一个指针位于最后一个元素之后,一个位于最后分配的空间之后(或表示为指针加偏移的等效信息):
  In addition, it holds an allocator (here, alloc), from which the vector can acquire memory for its elements. The default allocator uses new and delete to acquire and release memory. Using a slightly advanced implementation technique, we can avoid storing any data for simple allocators in a vector object.
  此外,它还包含一个分配器(这里是alloc),vector可以从中获取元素的内存。默认分配器使用new和delete来获取和释放内存。使用稍微先进的实现技术,我们可以避免在vector对象中存储简单分配器的任何数据。template class Vector {        allocator alloc;    // standard-library allocator of space for Ts        T* elem;                     // pointer to first element        T* space;                   // pointer to first unused (and uninitialized) slot        T* last;                       // pointer to last slot public:        // ...        int size() const { return space-elem; }            // number of elements        int capacity() const { return last-elem; }        // number of slots available for elements        // ...        void reserve(int newsz);                         // increase capacity() to newsz        // ...        void push_back(const T& t);                 // copy t into Vector        void push_back(T&& t);                         // move t into Vector };STL array, and tuple elements are contiguously allocated; list and map are linked structures.
  StL array和tuple元素被连续分配;list和map是链接结构。
  An STL array, defined in , is a fixed-size sequence of elements of a given type where the number of elements is specified at compile time. Thus, an array can be allocated with its elements on the stack, in an object, or in static storage. The elements are allocated in the scope where the array is defined. An array is best understood as a built-in array with its size firmly attached, without implicit, potentially surprising conversions to pointer types, and with a few convenience functions provided. There is no overhead (time or space) involved in using an array compared to using a built-in array.
  在中定义的STL array是给定类型的元素的固定大小序列,其中元素的数量在编译时指定。因此,可以在堆栈、对象或静态存储中为数组分配元素。元素在定义数组的范围内分配。STL array最好理解为一个内置数组(built-in array),其大小固定,没有隐含的、可能令人惊讶的指针类型转换,并且提供了一些方便的函数。与使用内置数组相比,使用STL array不需要任何开销(时间或空间)。
  An array does not follow the "handle to elements" model of STL containers. Instead, an array directly contains its elements. It is nothing more or less than a safer version of a built-in array.
  STL array不遵循STL容器的"句柄到元素"模型。相反,数组直接包含其元素。它或多或少是内置array的一个更安全的版本。
  This implies that an array can and must be initialized by an initializer list:
  这意味着数组可以也必须由初始值设定项列表初始化:array a1 = {1,2,3};
  The number of elements in the initializer must be equal to or less than the number of elements specified for the array.
  初始值设定项中的元素数必须等于或小于为数组指定的元素数。
  The element count is not optional, the element count must be a constant expression, the number of elements must be positive, and the element type must be explicitly stated:
  元素计数不是可选的,元素计数必须是常量表达式,元素数必须为正数,并且必须明确声明元素类型:void f(int n) {     array a0 = {1,2,3};                      // error size not specified     array a1 = {"John"s", "Queens" "};  // error: size not a constant expression     array a2;                           // error: size must be positive     array<2> a3 = {"John"s", "Queens" "};         // error: element type not stated     // ... }
  If you need the element count to be a variable, use vector.
  如果您需要元素计数为变量,请使用vector。
  When necessary, an STL array can be explicitly passed to a C-style function that expects a pointer. For example:
  必要时,可以将STL array显式传递给需要指针的C样式函数。例如:void f(int* p, int sz);         // C-style interface void g() {         array a;          f(a,a.size());             // error: no conversion          f(a.data(),a.size());      // C-style use          auto p = find(a,777);      // C++/STL-style use (a range is passed)          // ... }
  Why would we use an STL array when vector is so much more flexible? An array is less flexible so it is simpler. Occasionally, there is a significant performance advantage to be had by directly accessing elements allocated on the stack rather than allocating elements on the free store, accessing them indirectly through the vector (a handle), and then deallocating them. On the other hand, the stack is a limited resource (especially on some embedded systems), and stack overflow is nasty. Also, there are application areas, such as safety-critical real-time control, where free store allocation is banned. For example, use of delete may lead to fragmentation or memory exhaustion.
  当STL vector如此灵活时,我们为什么要使用STL array?STL array不太灵活,因此更简单。有时,直接访问堆栈上分配的元素,而不是在空闲存储(堆)上分配元素,通过vector(句柄)间接访问它们,然后释放它们,会带来显著的性能优势。另一方面,堆栈是一种有限的资源(尤其是在一些嵌入式系统上),并且堆栈溢出非常严重。此外,还有一些应用领域,如安全关键型实时控制,禁止空闲存储(堆)分配。例如,使用delete可能会导致碎片化或内存耗尽。
  Why would we use an STL array when we could use a built-in array? An array knows its size, so it is easy to use with standard-library algorithms, and it can be copied using =. For example:
  当我们可以使用内置数组时,为什么要使用STL array?STL array知道它的大小,因此它很容易与标准库算法一起使用,并且可以使用操作符"="复制它。例如:array a1 = {1, 2, 3 }; auto a2 = a1;     // copy a2[1] = 5; a1 = a2;              // assign
  However, the main reason to prefer STL array is that it saves me from surprising and nasty conversions to pointers. Consider an example involving a class hierarchy:
  然而,更喜欢数组的主要原因是,它避免了对指针的令人惊讶和讨厌的转换。考虑一个涉及类层次结构的示例:void h() {     Circle a1[10];     array a2;     // ...     Shape* p1 = a1;       // OK: disaster waiting to happen     Shape* p2 = a2;       // error: no conversion of array to Shape* (Good!)     p1[3].draw();         // disaster }
  The "disaster" comment assumes that sizeof(Shape)
微小说公摊40我117平的房子,怎么公摊40平,我多付了120万啊,谁来帮帮我?我声嘶力竭地对着卖我房子的中介喊着我今年27岁,在一家化妆品公司做销售经理,谈了一个23岁的女朋友准备结婚了,我们上万企业复工复产!物流抢运潮来袭!上百种化工原料涨价上海市新冠肺炎疫情防控工作第182场新闻发布会指出,目前,上海全市9000多家规模以上工业企业中,已复工4400多家。同时,前期围绕战略功能城市运行保障防疫物资连续生产基础配套等领托卡耶夫访问吉尔吉斯斯坦!成果丰硕签10份合作文件综合哈通社报道,应吉尔吉斯斯坦总统扎帕罗夫邀请,哈萨克斯坦总统托卡耶夫26日抵达比什凯克,开始对吉进行正式访问。在玛纳斯国际机场,托卡耶夫受到了吉总理阿扎帕罗夫以及该国其他多位高级隆胸后怀孕了,还能正常哺乳吗?关于隆胸的3个问题要知道上一次520母乳喂养宣传日过后,有小伙伴非常严谨,问那隆胸后会影响母乳喂养吗?(图源后台截图)好问题!!人类对自身结构的探索总是无限的。女性胸部除了作为生理器官外,还附带着性象征的法医秦明之读心者,空姐被抛尸废弃修理厂,到底经历了什么?拾荒者在郊外的废弃的汽修厂发现了一具已经严重尸蜡化的尸体,警方迅速赶往现场。鉴于保鲜膜包裹下的尸体已经严重尸蜡化,法医通过面部复原确认了受害人的身份,一个年轻漂亮的空姐张雨晨。遥不特稿人教社的生意版图中新经纬5月27日电(常涛马静魏薇)教辅教材,一直被认为是出版行业的一座金山。近日,成立于1950年的人民教育出版社(下称人教社)因教材插图丑,引发大量关注,频上热搜。在此背后,人黄晓明新女友?钟汉良老婆?苏醒隐婚生子?四字小花恋爱?1钟汉良老婆?据说钟汉良在剧组被拍到老婆来探班,能看到钟汉良接过女生手中的雨伞,贴心为她举起,但是有网友跳出来说甜是挺甜的,但好像不是钟汉良,因为被拍的男生看起来太年轻太帅了。钟汉又有铁饭碗单位面向社会招聘,月薪高达9000元,专科生也能报考将要毕业的大学生最关注的问题应该就是工作,因为就业压力越来越大,大批学生选择报考公务员事业单位或者国企。这些单位不仅收入非常可观,稳定性也很高,但因为报考人数越来越多,想要考上的几网传公务员将面临降薪,还要停发年终奖?3类岗位或成大学生新宠据大数据统计,近几年大学毕业生创业率大幅下降,考公率却不断攀升。稳定仿佛已经成为应届生就业时,关注的重点因素。曾几何时,公务员等体制内工作因清闲而著称,但是收入水平并不高。因此很多老婆月工资47000元,称老公配不上自己,老公别忘了你已经结婚两性关系中,不管是男弱女强还是女弱男强都是走不远的,最好的关系是你强,我也不差。在生活上相互照顾,在工作中相互解惑答疑。为了自己的小家而努力奋斗,这种爱情是很多人都非常羡慕的。但在中俄联合战巡后,美日战机打了马后炮,KD63可让基地趴窝近年来中俄两国已经形成了背靠背,包括两国的联手也让美国在亚太地区连续吃了瘪,如今中俄两国的常态化联合战巡已经成为了常态化,在5月24日当天拜登还在日本进行访问的关键时刻,中俄两国空
消息称富士康撤换苹果iPhone组装业务主管IT之家1月17日消息,彭博社周二援引知情人士的话报道称,富士康已任命MichaelChiang为其iPhone组装业务的新主管,取代之前的长期主管WangCharngyang。富太子成为人质,却住他国皇宫,两汉的质子到底有多残酷和现实引言在古代,有一类身份极其特殊的人,被称为质子。其实质子在本质上就是一种特殊的人质。质子现象曾普遍存在于我国古代民族交往过程中,并成为少数民族与内地政权发展关系的一种特殊工具。两汉民国的十大汉奸民国时期国家内忧外患,有人致力于拯救国家,而有人却半路叛变,看看那些民国的汉奸和他们的最终下场。汪精卫第一位,汪精卫。汪精卫出生于广东的山水。幼年接受家族的传统教育,曾获得番禺县县阿敏囚死案皇太极为何囚禁困死堂弟?阿敏介绍阿敏生于明万历14年,是舒尔哈齐的次子。父亲被困时,他侥幸逃脱死罪,从此跟随伯父努尔哈赤南征北战。阿敏骁勇善战,立下不少汗马功劳。天命元年,努尔哈赤称汗建国,就是大金国,封说说吉林省临江市大美的江心岛公园二零二三年一月七日,我看到了一位辽宁大学毕业的黑龙江女孩儿,来到吉林省临江市江心岛公园游玩的视频。看到这个视频,激发出我再次前往吉林省临江市看冬景的强烈愿望二零二三年一月十四日,腊壹点图集黄河大集淄博风物看!金岭大集的烟火气壹点图集黄河大集淄博风物看!金岭大集的烟火气壹点图集黄河大集淄博风物看!金岭大集的烟火气壹点图集黄河大集淄博风物看!金岭大集的烟火气壹点图集黄河大集淄博风物看!金岭大集的烟火气壹点耶伦美政府或因债务达到上限停摆,财政部最早将于6月初耗尽现金来源环球时报环球时报综合报道美国福克斯新闻网16日报道称,美国财政部长耶伦日前警告称,该国将在本月19日达到法定的债务上限。如果国会不采取行动,美国财政部最早将于今年6月初耗尽现金陶匡淳委员错位发展,推动北交所高质量扩容北京日报客户端记者马婧北交所的设立,对于北京建设国际科技创新中心和国家金融管理中心有着重要意义。来自特邀界的市政协委员毕马威中国及亚太区主席陶匡淳建议,利用北交所错位发展优势,实现栖霞提升服务质效助企纾困解难近年来,栖霞市财税部门聚焦纳税人缴费人所需所盼,不断提升服务质效,用真金白银和便民春风为市场主体纾困解难,切实提升纳税人的满意度和获得感。栖霞市财政局严格落实中央省市出台的减税降费老牛捉妖0115天威视讯换手4板,金发拉比爆量3板,谁能笑傲江湖众里寻她千百度,蓦然回首,那人却在,灯火阑珊处。回首过去的2022年,你曾与多少只妖股擦肩而过,又与多少只妖股缠绵悱恻?周末不打烊,捉妖不停留,应粉丝要求,继续今天的捉妖旅程。天威民间故事放牛娃夜归,见兄嫂在缸里洗澡,他偷偷在水里放了把盐明朝末年,在安平县大同镇内有兄弟二人相依为命,哥哥名叫李福,弟弟叫李顺,他们从小就失去了父母,多亏了村子里的乡亲帮助这才得以长大。如今兄弟二人都已经长大,李福年长几岁,从小便承担起