草庐IT

alloc_traits

全部标签

c++ - boost::call_traits - 为什么 gcc 为此给出 false?

示例:#include#include#includeboost::call_traits::param_typef(){return1;}intmain(){std::cout::param_type>::value::value问题:除非我做错了什么,我想我应该为两者都得到true,但是gcc4.7.0为后者输出false。有什么我想念的吗? 最佳答案 非类类型的右值永远不是const限定的。只有类类型的右值可以是const限定的。因此,即使函数f被声明为返回一个constint,即使函数f的类型是constint(),调用表达

c++ - 为什么 std::allocator<>::deallocate() 有一个未使用的 size_type 参数?

使用std::allocator时,deallocate函数需要pointer参数,和一个size_type参数(std::allocator::deallocate(std::allocator::pointerp,std::allocator::size_type)。但是,没有使用size_type,也不是可选的。那么为什么它在那里?这让我很困惑,因为它应该是可选的,甚至不在那里,因为它没有在函数中使用.编辑:MSVC的分配器实现deallocatevoiddeallocate(pointer_Ptr,size_type){//deallocateobjectat_Ptr,igno

c++ - 反向迭代器错误 : no match for 'operator!=' in 'rcit != std::vector<_Tp, _Alloc>::rend() with _Tp = int, _Alloc = std::allocator'

代码A:vector::const_reverse_iteratorrcit;vector::const_reverse_iteratortit=v.rend();for(rcit=v.rbegin();rcit!=tit;++rcit)cout代码B:vector::const_reverse_iteratorrcit;for(rcit=v.rbegin();rcit!=v.rend();++rcit)coutCODEA工作正常但是为什么代码B通过错误:DEVC++\vector_test.cpp在'rcit!=std::vector::rend()与_Tp=int,_Alloc=s

c++ - 为什么 eglMakeCurrent 因 EGL_BAD_ALLOC 而失败?

我正在使用OpenGLES2.0和AndroidNDKr8b。我有一个用于工作线程的共享上下文。当我尝试使用eglMakeCurrent将共享上下文绑定(bind)到工作线程时,我收到错误EGL_BAD_ALLOC。现在让我感到困惑的是这段代码之前工作得很好......我不确定我做了什么来破坏它......EGL文档说这个错误与资源不可用有关,但我正在运行曾经在这个完全相同的设备上完美运行的同一个应用程序,并且所有纹理都可以从主线程正常加载。那么可能导致此错误的原因是什么?这是我的egl初始化:boolInitialize(void*displaySurface){assert(dis

条款47:请使用traits classes表现类型信息

1.前言STL主要由“用以表现容器,迭代器和算法”的template构成,但也覆盖若干工具性templates,其中一个名为advance,用来将某个迭代器移动某个给定距离:tempalte//将迭代器向前移动d单位voidadvance(IterT&iter,DistTd);//如果d观念上advance只是做iter+=d动作,但其实不可以全然是那样,因为只有randomaccess(随机访问)迭代器才支持+=操作。面对其它迭代器种类,advance必须反复施行++或--,共d次。先回顾下STL迭代器的分类:STL共有5种迭代器分类,inpiut迭代器只能向前移动,一次一步,客户可只读取它

c++ - bad_alloc 在初始化和填充 vector 时?

在尝试生成随机数vector时,我偶然发现了一个std::bad_alloc错误。这是我的代码:#include"search.h"#include"gtest/gtest.h"int_size=100;std::vectorGetSortedVector(intsize){//initvectorstd::vectorv(size);//fillwithrandomnumbersfor(std::vector::size_typei=0;iv=GetSortedVector(_size);//nothingmovesfartherthanthisline}附注:我现在确实在使用gen

c++ - 尽管未定义 <new> header ,但 New 会抛出 bad_alloc?

new是怎么回事?程序中的表达式可以抛出bad_alloc尽管没有#include还是出错(因为这个错误isdefinedintheheader)?来自3.7.4。N3337的:Thelibraryprovidesdefaultdefinitionsfortheglobalallocationanddeallocationfunctions.Someglobalallocationanddeallocationfunctionsarereplaceable(18.6.1).AC++programshallprovideatmostonedefinitionofareplaceablea

c++ - 为什么STL要为Allocator预留接口(interface)?

STL为什么要为Allocator预留接口(interface)?以vector为例:template>classvector;因为我们有很多选择来分配内存和构造对象,比如operatornew,delete,new[],delete[],它几乎可以做我们创建对象时需要做的任何事情。那么,为什么像vector这样的STL容器需要一个Allocator接口(interface),如果我们不分配一个,它在大多数情况下都是默认的std::allocator?为什么不直接使用新的表达式呢?如果目的是使用户定义的分配行为成为可能,为什么不让用户提供他们自己定义的operatornew、new[]

c++ - 为什么 `e.what()` 打印 "bad allocation"?

tryblock中的new表达式在我的计算机中引发了bad_alloc异常。请注意,catch子句按值而不是按引用接收异常对象。为什么e.what()会打印出"badallocation"?我以为它会被切成薄片。#includeintmain(){try{int*p=newint[0x1F000000];}catch(std::exceptione){std::cout 最佳答案 VisualStudio(Dinkumware?)使用std::exception的实现,其中包含消息的内部存储†。(完成一个接受字符串的非标准构造函数。

c++ - 在抛出 'std::bad_alloc' what(): std::bad_alloc 的实例后终止调用

我的程序中出现了bad_alloc异常。这些是限制条件:1每个字符串的长度最多为100000,并且只包含小写字符。由于这些限制,我无法弄清楚为什么我的程序得到bad_alloc。#include#include#include#includeclassSuffixArray{std::vectorsuffixes;size_tN;public:SuffixArray(std::string&s){N=s.length();suffixes.resize(N);for(size_ti=0;i>T;std::vectorresults;for(inti=0;i>str;SuffixArra