草庐IT

enable-stdio-inheritance

全部标签

c++ - 在类定义之外使用 enable_if 实现函数

所以基本上,我现在有一个非常基本的通用类,目前正在测试type_traitsheader。我目前正在尝试制作一个函数来处理某些类型,即现在的算术类型。#includetemplateclassTest{public:templatetypenamestd::enable_if::value>::typeprint();};该函数完美运行且仅适用于算术类型。但我喜欢保持我的类整洁,只有它们有原型(prototype),而函数实现在类之外。使用标准模板即voidtest();templatevoidTest::test(){}这很简单,我知道怎么做,但我不知道如何用“std::enable

C++ - std::enable_if 更多类型

我有一个函数:template::value==true>::type*=nullptr>voidtest(Ti){//processdata}有效。但是,我不仅需要为int启用此功能,还需要为float和constchar*启用此功能......如何无需将相同的方法写3次就可以做到这一点? 最佳答案 像这样:template::value||std::is_same::value||std::is_same::value>::type*=nullptr>voidtest(Ti){//processdata}

c++ - libjpeg 版本6b jpeg_stdio_src 与 jpeg_mem_src

我使用的是Libjpeg版本6b。在版本8中,他们有一个很好的函数可以从内存中读取数据,称为jpeg_mem_src(...),不幸的是。6b没有这个功能。我可以用什么直接从内存中读取压缩数据?我所看到的只是从硬盘读取的jpeg_stdio_src。 最佳答案 自己写.../*ReadJPEGimagefromamemorysegment*/staticvoidinit_source(j_decompress_ptrcinfo){}staticbooleanfill_input_buffer(j_decompress_ptrcinf

c++ - std::enable_if 的模糊部分特化

我在如下情况下遇到了问题:#include#include#defineTRACEvoidoperator()()const{std::cerrstructcheck:std::true_type{};templatestructconvert{TRACE;//firstcase};templatestructconvert::value&&check::value),void>::type>{TRACE;//secondcase};templatestructconvert::value),void>::type>{TRACE;//thirdcase};然后convertc;c();

c++ - 来自同一个 enable_shared_from_this 实例的两个 shared_ptr

鉴于这个类是enable_shared_from_this:classconnection:publicstd::enable_shared_from_this{//...};假设我从sameconnection*创建了两个std::shared_ptr实例,如下所示:std::shared_ptrrc(newconnection);std::shared_ptrfc(rc.get(),[](connectionconst*c){std::cout到目前为止一切正常,因为资源{connection*}由单个shared_ptr—rc准确地说,fc只是有一个假的删除器。之后,我这样做:a

c++ - 从 enable_if 基础继承

我正在尝试为非字符数组部分特化一个特征:templatestructis_container:std::false_type{};templatestructis_container:std::enable_if::value,std::true_type>::type{};VisualStudio2010给了我一个C2039(type不是enable_if的元素...)。但是,SFINAE不应该在这里触底而不是给出编译器错误吗?或者SFINAE不适用于这种情况?当然,我可以将非字符和字符的特化分开:templatestructis_container:std::false_type{

c++ - 如何正确链接 boost::mpl::inherit_linearly 和 boost::mpl::inherit 以便解析占位符?

假设我有这些类型:templateclassStorage>structAbstractFactoryUnit{virtual~AbstractFactoryUnit(){}virtualtypenameStorage::StoredTypedoCreate(Storage)=0;};和templateclassProductStorage,templateclass>classUnit=AbstractFactoryUnit>structAbstractFactory:boost::mpl::inherit_linearly>>::type{typedefTypeSequencePr

c++ - enable_if : minimal example for void member function with no arguments

我试图更好地理解C++11中的std::enable_if并且一直在尝试编写一个最小的示例:一个类A带有成员函数voidfoo()根据类模板中的类型T具有不同的实现。下面的代码给出了期望的结果,但我还没有完全理解它。为什么版本V2有效,但V1无效?为什么需要“冗余”类型U?#include#includetemplateclassA{public:A(Tx):a_(x){}//EnablethisfunctionifT==int/*V1*///template::value,int>::type=0>/*V2*/template::value,int>::type=0>voidfoo(

C++ 如何保护自己不受 stdio.h 宏的影响

我花了很长时间试图找出为什么以下代码无法编译:enumIPC_RC{OK,EOF,ERROR,NEW};错误消息只说明了它不希望看到左括号的意思。直到我尝试在更现代的编译器上编译它,我才了解到:/usr/include/stdio.h:201:13:note:expandedfrommacro'EOF'#defineEOF(-1)所以我终于被宏烧死了!:)我的代码没有#include(我没有包含任何带有.h后缀的内容),但显然我包含的内容导致包含。.有什么方法(namespace?)可以保护我自己,而无需追查它的确切位置吗? 最佳答案

c++ - MSVC 无法评估 enable_if 中的 constexpr 函数

考虑一个简单的效用函数来计算合取,并使用这个效用来确保std::tuple中的类型都相等。#include#includeconstexprautoall()noexcept->bool{returntrue;}templateconstexprautoall(boolconstx,Bools...xs)noexcept->bool{returnx&&all(xs...);}templatestructfoo;templatestructfoo,std::enable_if_t::value...)>>{};intmain(){foo>x;}GCC和Clang可以处理这段代码,但MSV