草庐IT

If-None-Match

全部标签

c++ - 带有早期 if 语句的函数中不必要的 pop 指令

在玩godbolt.org时,我注意到gcc(6.2、7.0快照)、clang(3.9)和icc(17)在编译接近inta(int*a,int*b){if(b-a将(-O2/-O3)编译成这样的东西:pushr15movrax,rcxpushr14subrax,rdxpushr13pushr12pushrbppushrbxsubrsp,184movQWORDPTR[rsp],rdxcmprax,7jg.L95notDWORDPTR[rdx].L162:addrsp,184poprbxpoprbppopr12popr13popr14popr15ret在b-amovrax,rcxsubra

c++ - 在编写平台相关代码时使用 constexpr if 而不是宏?

现在ifconstexpr是C++17的一部分,在编写平台相关代码和类似代码时,它是否是宏的良好替代品?我想知道,因为我真的不喜欢宏,并且只想将它们用于includeguards和includes。//thosevariablesshouldbegivenbythecompilerconstexprunsignedint__os=0x1;//currentosconstexprunsignedint__os_win=0x1;//Windowsconstexprunsignedint__os_linux=0x2;//Linux-flavorsconstexprunsignedint__o

c++ - 混合 decltype 和 enable_if

似乎将decltype与SFINAEenable_if一起使用并不简单。我尝试以三种不同的方式使用enable_if编写go。所有这些都因编译器错误而失败(GCC的字面意思是:“错误:'thing'不是'foo'的成员”和实例化上下文)。#includestructfoo{enum{has_thing=false};};structbar{enum{has_thing=true};staticintthing(){return0;}};templatestructTest{/*autogo(typenamestd::enable_if::type=0)->decltype(T::thi

c++ - std::move_if_noexcept 的基本原理仍在 move 抛出仅 move 类型?

move_if_noexcept将:返回一个右值——促进move——如果move构造函数是noexcept或者如果没有复制构造函数(仅move类型)返回一个左值——强制复制——否则我发现这相当令人惊讶,因为具有抛出move-ctor的仅move类型仍将由使用move_if_noexcept的代码调用此move-ctor。是否对此给出了详尽的理由?(也许直接或在N2983的两行之间?)代码不编译而不是仍然不得不面对不可恢复的move场景会不会更好?N2983中给出的vector示例很好:voidreserve(size_typen){......new((void*)(new_begin

c++ - C++11 正则表达式中有 match_partial 吗?

我通读了n1429与部分Thealgorithmsregex_matchandregex_searchbothsupportafeaturenotcommonlyseeninregularexpressionlibraries:apartialmatch.Whentheflagstd::regex_constants::match_partialissetintheflagspassedtothealgorithm,thenaresultoftruemaybereturnedifoneormorecharacterswerematched,andthestatemachinethenr

c++ - 这是 clang c++11 std::regex_match 的一个特性还是一个错误?

我注意到如果第一个模式是第二个模式的开始部分(在clang3.5和clang3.8上测试),则包含两个带OR条件的模式的正则表达式不匹配示例字符串:std::regex_match("ab",std::regex("(ab|a)"))==true但是std::regex_match("ab",std::regex("(a|ab)"))==false我认为true在这两种情况下在逻辑上都是正确的。Clang和OSX:$cat>test.cpp#include#include#includeintmain(){std::coutClang和FreeBSD:$cat>test.cpp#inc

c++ - fatal error C1017 : invalid integer constant expression when using "#if (false)"

下面的代码可以在Linux下运行,但对于MSVS会出错#if(false)....#endif错误是:fatalerrorC1017:invalidintegerconstantexpression我在Microsoft的网站上找到了这份报告:http://msdn.microsoft.com/en-us/library/h5sh3k99.aspx虽然那里描述的信息与我的情况相比略有不同,因为我没有使用“#define”所以我的问题是:有没有什么方法可以让它在不更改代码的情况下为MSVC工作?如果必须更新代码,这种情况的最佳解决方案是什么? 最佳答案

c++ - 为什么这个enable_if函数模板不能专用于VS2017?

以下使用VS2015编译,但在VS2017中失败并出现以下错误。代码是否在做一些非标准的事情,已在VS2017中修复,或者VS2017应该编译它?#include"stdafx.h"#includetemplateconstexprautoToUnderlying(Ee){returnstatic_cast>(e);}templateboolconstexprIsFlags(T){returnfalse;}templatestd::enable_if_t>operator|(Elhs,Erhs){returnToUnderlying(lhs)|ToUnderlying(rhs);}en

python的条件判断中的not、is、is not、is not None、is None

目录1.notA2.is和isnot3.isnotNone和isNone4.实例1.notA是判断A是否为0、False、空字符串、空列表、空字典、空元组以及None,满足任一条件即返回True2.is和isnot是不是某种对象3.isnotNone和isNoneNone:在Python中是一个单例对象,一个特殊的常量:没有值、空值、值不存在对于在判断条件中的对象值的判断,除了False外,None、0、数据为空[]、""、{}、()都是False,即bool(None)、bool(0)、bool([])、bool("")、bool({})、bool(())的值均为false可以认为判断一个变

c++ - 内联函数指针以避免 if 语句

在我的jpg解码器中,我有一个带有if语句的循环,该语句将始终为真或始终为假,具体取决于图像。我可以创建两个单独的函数来避免if语句,但出于好奇我想知道使用函数指针而不是if语句对效率有什么影响。如果为真,它将指向内联函数;如果为假,它将指向一个空的内联函数。classjpg{private://emtpyfunctionvoidinlinenothing();//realfunctionvoidinlinefunction();//pointertoinlinefunctionvoid(jpg::*functionptr)()=nullptr;}jpg::nothing(){}mai