草庐IT

numeric_traits_integer

全部标签

c++ - libpng 错误 : PNG unsigned integer out of range

当尝试从内存中读取PNG时,我遇到了这个奇怪的错误:libpngerror::PNGunsignedintegeroutofrange这个错误是由引起的png_read_info(png_ptr,info_ptr);它使用以下处理程序:staticvoidReadDataFromBuffer(png_structppng_ptr,png_bytepoutBytes,png_size_tbyteCountToRead){PNGDataPtrdataptr=(PNGDataPtr)png_get_io_ptr(png_ptr);png_uint_32i;coutlenpdataptr->l

c++ - 2 个重载具有相似的转换 - 内置运算符 integer[pointer-to-object]

我有以下类(class):classDictionaryRef{public:operatorbool()const;std::stringconst&operator[](std::stringconst&name)const;//...};然后我尝试使用它:DictionaryRefref=...;ref["asdf"];//error输出提示两个重载,但只列出一个:1>...:errorC2666:'DictionaryRef::operator[]':2overloadshavesimilarconversions1>...:couldbe'conststd::string&D

c++ - 预处理器 "invalid integer constant expression"比较 int 和 double

在我的代码中的某处,我有预处理器定义#defineZOOM_FACTOR1我在另一个地方#ifdefZOOM_FACTOR#if(ZOOM_FACTOR==1)#defineFONT_SIZE8#else#defineFONT_SIZE12#endif#else#defineFONT_SIZE8#endif问题是当我将ZOOM_FACTOR值更改为float值时,例如1.5,出现编译错误C1017:无效的整数常量表达式。有谁知道我为什么会收到这个错误,有没有办法在预处理器指令中比较integer和floatingpointnumber? 最佳答案

C++ : has_trivial_X type traits

boost库,似乎是即将推出的C++0x标准,定义了各种类型特征模板,以区分具有平凡构造函数、复制构造函数、赋值或析构函数的对象与不具有平凡构造函数的对象。其最重要的用途之一是优化某些类型的算法,例如通过使用memcpy。但是,我不明白所有各种has_trivial_X模板之间真正的实际区别。C++标准只定义了我们在这里关注的两大类类型:POD和非POD。如果一个类型具有已定义的构造函数、复制构造函数、赋值运算符或析构函数,则该类型是非POD。换句话说,任何不是内置类型或内置类型的C结构的东西都不是POD。那么区分has_trivial_assign和has_trivial_const

c++ - 为什么无序关联容器在 C++0x 中不使用 allocator_traits<T>

为什么C++0x无序关联容器不使用allocator_traits来定义它们的成员类型pointer和const_pointer?例如,顺序关联容器和有序关联容器使用以下定义:typedeftypenameallocator_traits::pointerpointer;typedeftypenameallocator_traits::const_pointerconst_pointer;而无序关联容器使用这个:typedeftypenameAllocator::pointerpointer;typedeftypenameAllocator::const_pointerconst_po

c++ - std::numeric_limits<T>::digits 应该代表什么?

我正在编写一个类似整数的类,它代表一个位于某个范围内的值。例如,bounded::integer的值位于[0,10]范围内的某处。对于这个类,我定义了radix成为2.digits的值应该是多少?为bounded::integer?那bounded::integer呢?? 最佳答案 在进一步阅读标准并思考这个问题后,我相信我有最好的答案,但我不确定。首先是digits的定义,取自最新的C++14标准草案,N3797,§18.3.2.4:staticconstexprintdigits;8Numberofradixdigitsthat

c++ - std::string 的 type_traits 段错误

从UsingSFINAEtocheckforglobaloperator收集信息和templates,decltypeandnon-classtypes,我得到了以下代码:http://ideone.com/sEQc87基本上,我将两个问题的代码结合起来,如果它有ostream声明,则调用print函数,否则调用to_string方法。摘自问题1namespacehas_insertion_operator_impl{typedefcharno;typedefcharyes[2];structany_t{templateany_t(Tconst&);};nooperatorstruct

c++ - Scala 和 C++ traits 之间的关系是什么

Traits是Scala和C++中使用的一个概念(尽管在C++中它更像是一个习语,而不是一个集成到语言中的概念)。不过,这些概念之间的关系对我来说并不明显。Scala和C++traits之间有什么关系? 最佳答案 他们根本没有关系。在C++中,traits类是一个辅助对象,它告诉您有关类型的一些信息,这些信息您无法从类型名称本身获得。C++traits实际上更类似于Scala的deffoo[A:Manifest]表示法(一个我不知道正确名称的功能。)Scala的特性实际上更像C++的多重继承(尽管它们在细节上有所不同)。我实际上相当

如何正确地从函数(type_traits)提供向量

我如何返回std::vector由此operator+()?#include#include#include#include#includetemplatestructis_std_vector:std::false_type{};templatestructis_std_vector>:std::true_type{};templatestd::enable_if_t>::value>operator+(T&&vec1,T&&vec2){for(inti=0;i(vec2.at(i)));returnvec1;}intmain(){std::vectorvec1{1,2,3,4,5};std

c++ - 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str':非标准语法;使用 '&' 创建指向成员的指针

我正在尝试创建一个可以读取和编译opengl顶点和片段着色器文件的函数,但是我收到了这个错误:'std::basic_string,std::allocator>::c_str':non-standardsyntax;use'&'tocreateapointertomember我不太确定如何修复它。这是我的代码:GLuintshader_load(constGLchar*vertex,constGLchar*fragment){std::stringver=file_read_all(vertex);std::stringfrag=file_read_all(fragment);con