草庐IT

enable-stdio-inheritance

全部标签

c++ - 对于 CLang 中的 enable_if 错误(错误 11723)是否有更好的解决方法?

理想情况下,我们可以使用enable_if做类似的事情:#includenamespacedetail{enumclassenabler_t{DUMMY};}templateusingenable_if_u=typenamestd::enable_if::type;templateusingdisable_if_u=typenamestd::enable_if::type;template::value>...>inta(){return0;}template::value>...>doublea(){return0.0;}intmain(){autox=a();}恕我直言,这是最好的

c++ - 从 enable_shared_from_this 返回 self 的 shared_ptr 继承的类的子类

我想知道是否有像这样的伪代码来做一些事情:classA:publicstd::enable_shared_from_this{public:std::shared_ptrgetPtr(){returnstd::static_pointer_cast(shared_from_this());}};classB:publicA{std::vectorcontainer;std::shared_ptraddChild(Achild){container.push_back(child);returngetPtr();}};classC:publicB{public:std::shared_p

c++ - 启动进程并重定向其 stdio 的跨平台方式

我想知道是否有一个跨平台(Windows、Linux、BSD)库,我可以使用它异步启动一个进程,并为其标准管道提供类似于iostream的包装器。我希望它能够知道进程何时终止。谢谢。 最佳答案 您可以使用2个库:Q进程您可以使用Qt工具包中的QProcess类。更多信息可以在thisstackoverflowquestion上找到和qtlibrary.libexecstream这library比Qt轻量级,跨平台其他pstreams发布0.17Ifyouonlywantaconsoleapplicationyoucanusetheo

c++ - 无法使用 __gnu_cxx::stdio_filebuf 进行流式传输

这会创建文件,但不会写入任何内容。std::ofstreamoutstream;FILE*outfile;outfile=fopen("/usr7/cs/test_file.txt","w");__gnu_cxx::stdio_filebuffilebuf(outfile,std::ios::out);outstream.std::ios::rdbuf(&filebuf);outstream我知道还有其他简单的解决方案可以实现输出,但我需要在编辑时使用这个非标准的filebuf来锁定文件,这样其他进程就无法打开文件。我不知道为什么这不起作用。 最佳答案

c++ - 为什么 SFINAE 需要 'Enable' 类模板参数?

(本题与C++11/C++14无关:示例使用C++03编译)enable_bool有成员(member)::type仅当T是booltemplatestructenable_bool{};templatestructenable_bool{typedefbooltype;};在下一个片段中,部分特化是正确的(参见gcc.godbolt.org)templatestructFoo{staticintbar(){return0;}};templatestructFoo::type>{staticintbar(){return1;}};intmain(){returnFoo::bar();}

c++ - 在C/C++中使用stdio文件操作时如何检测磁盘空间不足?

我正在做一个小程序如下:voidreserve_file_space(char*file_path,size_tamount){FILE*fp=fopen(file_path,"w+b");if(!fp){printf("couldnotcreateanewfile\n");return;}intfseek_ret=fseek(fp,amount,SEEK_SET);if(fseek_ret!=0){printf("couldnotseektothedesiredposition\n");fclose(fp);return;}chargarbage=1;size_tret=fwrite

c++ - 海湾合作委员会 : C++11 inline object initialization (using "this") does not work when there is a virtual inheritance in hierarchy

当在初始化中使用此指针并且在层次结构中存在虚拟继承时,C++11内联对象初始化不起作用(在GCC中)。这可能是GCC的错误吗(因为它在CLang中工作)?还是C++11标准本身的差距?示例(可以在here中尝试),当使用GCC编译以下代码时:FieldIndexm_inB{"inB",this};不会被执行。但它会在使用CLang编译时执行。变通方法:从FieldIndexContainer派生A作为虚拟#include#include#includeusingnamespacestd;classFieldIndexContainer{public:classFieldIndex{pu

带有 std::enable_if 的 C++ 可变参数模板部分模板特化

ITNOA我的问题是如何在可变参数模板部分模板特化场景中使用std::enable_if?例如,我有一个类使用如下所示的可变参数模板部分特化/***Commoncase.*/templatestructfoo;/***Finalsuperclassforfoo.*/templatestructfoo{voidfunc(){}};/***Regularfooclass.*/templatestructfoo:publicfoo{typedefsuperfoo;voidfunc(){coutsuper::templatefunc();}}它工作正常,但如果H是整数类型,我想要特定的部分特化

c++ - 警告 : auto-importing has been activated without --enable-auto-import specified on the command line

我的环境:QtCreator2.3.1Qt4.7.4(32位)Windows7旗舰版(64位)尝试在QtforWindows中重建项目时,我遇到以下编译器警告:warning:auto-importinghasbeenactivatedwithout--enable-auto-importspecifiedonthecommandline.Thisshouldworkunlessitinvolvesconstantdatastructuresreferencingsymbolsfromauto-importedDLLs.发出此警告的项目包含一个DLL文件。尽管有警告,DLL中的类和函数

c++ io streams sync_with_stdio 没有区别

出于某种原因,我无法使我的输出流使用该行运行得更快std::ios_base::sync_with_stdio(false);包含在我程序的开头。我正在用这两个程序对此进行测试:#includeintmain(){for(inti=0;i和#includeintmain(){std::ios_base::sync_with_stdio(false);for(inti=0;i每个程序的运行时间如下第一次测试(同步)real0m1.095suser0m0.472ssys0m0.299ssecond_test(关闭同步)real0m1.091suser0m0.471ssys0m0.299s我