草庐IT

assign_attributes

全部标签

c++ - is_assignable 和 std::unique_ptr

Here是来自gcc的测试文件,livedemostructdo_nothing{templatevoidoperator()(T*){}};intmain(){inti=0;std::unique_ptrp1(&i);std::unique_ptrp2;static_assert(!std::is_assignable::value,"");//note!here.}std::is_assignableIftheexpressionstd::declval()=std::declval()iswell-formedinunevaluatedcontext,providesthemem

c++ - 为什么 boost::assign::list_of 不适用于 pair<string, vector<string>>?

我不明白为什么这不起作用(VisualC++2012):#include#include#include#includeusingnamespacestd;intmain(){pair>("^",boost::assign::list_of("rules"));}错误是:include\utility(138):errorC2668:'std::vector::vector':ambiguouscalltooverloadedfunctionwith[_Ty=std::string]include\vector(786):couldbe'std::vector::vector(std:

【ARM 嵌入式 编译系列 2.4 -- 编译参数-Wl,--gc-sections | -wsuggest-attribute=pure | -wreal-q-constant |】

请阅读【嵌入式开发学习必备专栏之ARMGCC编译专栏】文章目录概述编译参数详细介绍-Wl选项例子:--gc-sections``--gc-sections例子:-Wshadow例子:-Wlogical-op例子:-Waggregate-return例子:-Wfloat-equal例子:-Wconversion例子:-Wpointer-arith例子:概述在使用GCC(GNUCompilerCollection)进行编译时,可以通过不同的编译参数(标志)来控制编译行为、优化级别、警告输出等。以下是您列出的一些GCC编译参数的介绍:编译参数详细介绍参数作用–all-warnings与-Wall相同

c++ - 将 __attribute__ 与 typedef 结合使用

如果问题看起来太明显或太简单,我们深表歉意。不幸的是,在经历了一堆线程并用谷歌搜索了typedef加上attribute前缀之后,我仍然无法弄清楚。我在(据说)可移植应用程序中有以下代码片段-#ifdefWIN32#defineMY_PREFIX__declspec(dllexport)#else#defineMY_PREFIX__attribute__((visibility("default")))#endiftypedefMY_PREFIXboolsome_func(void);所以我的问题是-1)typedef到底在做什么?2)代码在VS2008上编译良好,但在G++(gcc-

c++ - [[attributes]] 是 C++11 的新功能吗?

usingC++11attributes提示[[attributes]]是C++11的新内容。我想确认一下:属性是C++11的新特性吗? 最佳答案 是的,属性是2011ISOC++标准中的一个新特性;以前的2003标准中没有指定它们。它们记录在标准的第7.6节[dcl.attr]中。该标准的最新草案是N3376(PDF,4.9MB)。 关于c++-[[attributes]]是C++11的新功能吗?,我们在StackOverflow上找到一个类似的问题: ht

c++ - STL - 赋值运算符与 `assign` 成员函数

vector(以及list和其他容器)有一个成员函数(MF)assign。我想比较assignMF(范围版本)与赋值运算符。据我所知,在以下情况下使用assign很有用:想要分配vector的子范围(不是从头到尾)。赋值是从一个数组完成的。在其他情况下,assignMF没有缺点,可以使用赋值运算符。我对吗?使用assignMF是否还有其他一些原因? 最佳答案 使用assign的主要原因就是将数据从一种容器复制到另一种容器。例如,如果您要迁移std::set的内容到std::vector,你不能使用赋值运算符,但你可以使用vector

c++ - 使用哪个 : move assignment operator vs copy assignment operator

我似乎不明白为什么要使用移动赋值运算符:CLASSA&operator=(CLASSA&&other);//moveassignmentoperator结束了,复制赋值运算符:CLASSA&operator=(CLASSAother);//copyassignmentoperator移动赋值运算符仅采用r值引用,例如CLASSAa1,a2,a3;a1=a2+a3;在复制赋值运算符中,other可以是使用复制构造函数或移动构造函数的构造函数(如果other是用右值初始化的,它可以是移动构造的——如果move-constructor定义了——)。如果它是copy-constructed,我

c++ - 自定义支持 __attribute__((format))

GCC和Clang都支持对可变参数函数(如printf)进行编译时检查。这些编译器接受如下语法:externvoiddprintf(intdlevel,constchar*format,...)__attribute__((format(printf,2,3)));/*2=format3=params*/在OSX上,Cocoa框架还使用了NSString的扩展:#defineNS_FORMAT_FUNCTION(F,A)__attribute__((format(__NSString__,F,A)))在我们公司,我们有一个自定义的C++框架,其中包含一堆类,例如BaseString,它

Object.assign详解

目录一、Object.assign是什么?二、用法:三、详细讲解1.目标对象和源对象没有同名属性2.目标对象和源对象有同名属性3.有多个源对象4、原始类型会被包装为对象5、对象的拷贝6、对象的深拷贝7、对象的深拷贝总结一、Object.assign是什么?object.assign()主要用于对象合并,将源对象中的属性复制到目标对象中,他将返回目标对象。二、用法:Object.assign(target,...sources)参数:target--->目标对象      source--->源对象返回值:target,目标对象三、详细讲解1.目标对象和源对象没有同名属性vartarget={n

c++ - 开关盒 : declaration-with-initialization & declaration-and-then-assignment

在switch-case语句中,declaration-with-initialization是无效的,但允许declaration-and-then-assignment。如以下代码片段所示。从编译器端看,这两种类型的初始化有什么区别?以及为什么第一种初始化无效而第二种初始化有效。switch(val){case0:intnewVal=42;//Invalidbreak;case1:intnewVal2;//ValidnewVal2=42;break;case2:break;} 最佳答案 实际上,规则是您不能跳入经过具有初始化的声