草庐IT

only_auto

全部标签

c++ - 自动将 c++11 auto 关键字重写为派生类型

也许是个奇怪的问题,但是有没有可用的软件,给定一堆c++11代码,派生所有类型的自动类型变量并用这些派生类型重写代码?还有初始化列表?原因是我们想提供我们代码的向后兼容版本(非C++11),主要是为了与osx的可移植性。自动输入和初始化列表是我们最常使用的功能,因为它们使代码更具可读性,但手动删除它们是不行的。由于这实际上是编译器对自动类型化变量所做的,所以它似乎并不太牵强? 最佳答案 查看BOOST_AUTO和/或BOOST_TYPEOFhttp://www.boost.org/doc/libs/1_48_0/doc/html/t

c++ - 从库中的 std::exception 派生:Does a headers-only solution work for catching exceptions?

在我们的跨平台开源库中,我们派生自std::exception以定义可以在库代码和用户代码中捕获的自定义异常。我看到这实际上是一个推荐的过程,但在VisualStudio2015(或者更确切地说,伴随的新MSVC版本?)中,在实现类(warningC4275)中抛出警告-另请参见此处:Howtodllexportaclassderivedfromstd::runtime_error?当然我们可以忽略这个错误,但这对我来说似乎是错误的。与旧的VisualStudio版本相比,出现警告的原因似乎是std::exception曾经在旧的MSVC版本中导出,但同时不再导出。无论哪种情况,我都觉

c++ - auto stdMaxInt = std::max<int> 的类型推导失败;

使用GCC4.8.4和g++--std=c++11main.cpp输出以下errorerror:unabletodeduce‘auto’from‘max’autostdMaxInt=std::max;对于这段代码#includetemplateconstT&myMax(constT&a,constT&b){return(a;myMaxInt(1,2);autostdMaxInt=std::max;stdMaxInt(1,2);}为什么它适用于myMax但不适用于std::max?我们可以让它与std::max一起工作吗? 最佳答案

c++ - constexpr if with initializer 由标准保证吗? 'constexpr(constexpr auto x = f(); x) { }'

我找不到任何关于新C++17if初始化语法的信息和“constexprif”在:http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0128r1.html不过,Clang-HEAD支持该语法...constexprautof(){returntrue;}intmain(){ifconstexpr(constexprautox=f();x){}}在线代码在这里->http://melpon.org/wandbox/permlink/dj3a9ChvjhlNc8nr是constexprif带有标准保证的初始值设定项,如constexpr

c++ - 错误 : ‘template<class> class std::auto_ptr’ is deprecated

我正在使用scons和ubuntu。当我使用'scons'制作一些程序时,会发生错误,例如,src/db/DBTextLoader.cc:296:3:error:‘templateclassstd::auto_ptr’isdeprecated[-Werror=deprecated-declarations]/usr/include/c++/5/bits/unique_ptr.h:49:28:note:declaredheretemplateclassauto_ptr;这是我的命令;$./configuer$sourcesomething.sh$scons其实我也不知道。我已经在搜索这个

c++ - Visual Studio 错误 : LNK1104: cannot open file 'kernel32.lib' - only in WP8 projects/Win32 builds

我最近遇到了这个问题(几天前一切正常):VisualStudio2012开始拒绝构建原生WP8项目。今天,我从模板“WindowsPhoneDirect3D应用程序(仅限native)”创建了新解决方案,以检查WP是否正确支持我新创建的DLL。我尝试编译这个项目,首先没有任何更改或额外的引用-VS生成的纯代码。但是,它因给定错误而失败。我很清楚这是什么意思,可能的原因是什么,但是我不明白,在这种情况下它是从哪里来的。奇怪的事情:这只发生在“Win32”配置中,ARM编译正常:1>------Buildstarted:Project:PhoneDirect3DApp,Configurat

Ubuntu扩容报错:Unable to resize read-only file system /dev/sda3

当我们给Ubuntu新划分了空间,但是去给磁盘划分的时候,会报错:Unable to resize read-only file system /dev[sda3The file system can not be resized while it is mounted read-only.Either unmount the file system or remount it read-write.这是因为磁盘没有挂载起来,因此需要查看该磁盘的挂载路径,首先右键/dev/sda3点击信息,进去后就可以看到挂载的路径,分别是/和/var/snap/firefox/common/host-hun

c++ - 遍历动态 vector 时 auto 的异常行为

我正在使用自动遍历vector(附加代码)。在遍历的同时,我还在后面附加了一些元素。我没想到会得到这样的输出。#include#includeusingnamespacestd;vectordynamic_vector;voidaccess(){for(autoi:dynamic_vector){if(i==3){dynamic_vector.push_back(4);dynamic_vector.push_back(5);}cout输出:123我原以为从1到5的所有数字都会被打印出来。我无法理解如何使用auto进行遍历? 最佳答案

c++ - lambdas 中的模板参数列表中的 auto 是标准的一部分吗?

今天,我偶然发现了以下代码片段:#includeintmain(){autoa=[](std::pairvalue){};a(std::pair{3,true});}http://cpp.sh/5p34我只有一个问题:标准支持这段代码吗?它在GCC中编译(使用-std=c++14),但不是clang或VisualStudio2015(VC++14)。这似乎应该成为标准的一部分,因为如果lambda应该具有与常规函数相同的模板支持,那么应该支持它。这似乎可以转换为所有模板类型,而不仅仅是std::pair。 最佳答案 在C++14中,

c++ - const auto 和 auto const 如何应用于指针?

我尝试了一些代码,想知道在使用auto时C++中的const限定符如何应用于指针类型。intmain(){intfoo=1;intbar=2;//Expected:constint*ptr_to_const_int=&foo;constautoptr_to_const_int=&foo;//Expected:int*constconst_ptr_to_int=&foo;autoconstconst_ptr_to_int=&foo;*ptr_to_const_int=3;//Thoughtthiswoulderror//ptr_to_const_int=&bar;Thisdoeserro