草庐IT

is_const

全部标签

c++ - 为什么 boost::call_traits<double>::param_type 是 "const double&"而不是 "double"

我在win32program@windows7机器上使用代码“boost::call_traits::param_type”。令我惊讶的是,它不是“double”而是“constdouble&”。我认为所有原始类型都适合对函数参数使用“按值传递”,这不是常识吗?因为很多人会使用is_pod来判断是否使用引用,不是吗? 最佳答案 根据doc,该优化显然只适用于“小型”内置类型。.快速浏览source,看起来“小”类型被认为是满足sizeof(T)的类型.在32位机器上,这显然不包括double.在某些情况下,将参数传递为double可

c++ - 应该如何使用 const/non-const 参数重载函数?

我有以下代码://stringspecializationsvoidfoo(constchar*a,constchar*b);voidfoo(constchar*a,conststd::string&b);voidfoo(conststd::string&a,constchar*b);voidfoo(conststd::string&a,conststd::string&b);//genericimplementationtemplatevoidfoo(TAa,TAb){...}问题是这个测试用例:chartest[]="test";foo("test",test);最终调用了foo的

c++ - MPL 序列 : is this legal? 的用户定义文字

能够将传递给文字运算符的字符串转换为MPL序列会很有用,因为这样我们就可以根据字符串的内容控制代码生成。以前,我认为这是不可能的,因为constexpr函数的参数在函数体内不被视为常量表达式。但是,我想出了以下在Clang3.4.2和GCC4.8.2下编译的解决方法:#include#include#includestructstring{constuintmax_tm_str[64];constsize_tm_length;templateconstexprstring(constTs...ts):m_str{(uintmax_t)ts...},m_length{sizeof...(

c++ - std::set<K, C>::operator<(const std::set<K, C>&) 不使用 C() 但 std::less()

无法删除我自己的问题,所以改写它... 最佳答案 这实际上不是实现中的错误,尽管它可以说是标准中的错误:23.2.1Generalcontainerrequirements[container.requirements.general]13Table98listsoperationsthatareprovidedforsometypesofcontainersbutnotothers.Thosecontainersforwhichthelistedoperationsareprovidedshallimplementtheseman

c++ - 扭曲的逻辑 : a global variable in one file refers to an extern variable but is also referred by that extern variable

文件A.cpp:#includeexternintiA;externintiB=iA;intmain(){std::cout文件B.cppexternintiB;externintiA=2*iB;编译链接运行,out进来debug和release模式是0,0我的问题是它是如何工作的,为什么在链接阶段没有问题?我正在使用VC++2003。 最佳答案 初始化程序覆盖了extern关键字,因此这没有什么“神奇”:您只是在不同的翻译单元中声明和定义两个完全不相关的变量。来自StandardforProgrammingLanguageC++-

解决报错:Can‘t connect to HTTPS URL because the SSL module is not available.

本人今天准备打开Pycharm安装一个label-studio包,试了很多次,接连报如下错误,因此我就去找了一些解决方案,现在总结如下:1、报错信息如下2、解决方案如下:github上有对应的解决方案,链接:https://github.com/conda/conda/issues/8273说的是D:\Anaconda3\DLLsssl.pydsearchfortheOpenSSLDLLsbutinthewrong/currentlocation,也就是D:\Anaconda3\DLLs文件夹下存在一个ssl.pyd文件,它在错误或者当前的目录上搜索OpenSSLDLL文件。但是这个目录下没有

c++ - 使用 const 引用的函数模板重载决议

我试图理解以下情况下的重载决议规则:templatevoidf(constT&x){std::coutvoidf(T&x){//ÜberladungVariante2std::cout输出是:voidf(T&)[T=int]voidf(constT&)[T=int]据我所知,第一次调用f(e1)会导致可行的功能voidf(constint&)voidf(int&)从中选择第一个,因为没有删除const限定。第二次调用f(e2)导致类型推导/可行函数voidf(constint&);//T->intfromfirsttemplateoverloadvoidf(constint&);//T

c++ - Ctags 错误 "Is a directory"

我试图用ctags标记一个C++项目,并使用此答案C++sourcetagging中列出的选项.我在一个包含多个文件夹的项目树中,这些文件夹包含源文件。我尝试了以下方法来标记整个源代码树ctags--c++-kinds=+p--fields=+iaS--extra=+q--language-force=C++-R.find.-typef\(-iname"*.cpp"-o-iname"*.hpp"\)|xargsctags--c++-kinds=+p--fields=+iaS--extra=+q--language-force=C++ctags-R.ctags-R*和上面所有的都给出同样

c++ - 与 friend 一起上课而不是前向声明,: which compiler is correct

这个问题在这里已经有了答案:Friendmethod"notdeclaredinthisscope"inC++(1个回答)Error:'FriendMemberFunctionName'wasnotdeclaredinthisscope(3个答案)关闭3年前。我有这个简单的C++程序:#includestructobj{friendintf(int);voidm(intx){std::cout如果我使用GNUC++编译器g++进行编译,我会得到错误prog.cpp:7:55:error:'f'wasnotdeclaredinthisscope但是,如果我使用cl(和/W4)编译它,它会

编译gcc踩坑记录——libtool: error: ‘/usr/local/lib/libgmp.la‘ is not a valid libtool archive

安装gcc依赖过程中出现错误,解决方法在google找到的。三个依赖如下:libgmplibmpfr依赖libgmplibmpc依赖libgmp、libmpfr直接就无脑(网上很多教程,这里就不赘述了)./configure--prefix=/home/xx/make&&makeinstall然后在libmpc时候就报错了:libtool:error:'/usr/local/lib/libgmp.la'isnotavalidlibtoolarchive解决方法:因为libmpc引用了libmpfr,libmpfr引用了libgmp而libgmp.la这个文件有bug,编译脚本里libtool路