草庐IT

custom-cursor-default-hover

全部标签

c++ - "Custom intrinsic"x64 函数而不是内联汇编可能吗?

我目前正在尝试为我的库创建高度优化、可重用的函数。例如,我按以下方式编写函数“是2的幂”:templateinlineboolis_power_of_two(constIntTypex){return(x!=0)&&((x&(x-1))==0);}作为内联C++模板,这是一个可移植、低维护的实现。这段代码被VC++2008编译为如下带有分支的代码:is_power_of_twoPROCtestrcx,rcxjeSHORT$LN3@is_power_olearax,QWORDPTR[rcx-1]testrax,rcxjneSHORT$LN3@is_power_omoval,1ret0$L

c++ - Boost Spirit Qi Re-Establish skipping with custom skip 语法

到目前为止,我有一个语法一直在使用标准的boost::spirit::ascii::space/boost::spirit::ascii::space_type船长。我有一些使用船长的规则和一些不使用的规则,比如qi::rule(),ascii::space_type>expression;qi::rule()>term;当我在跳跃式非终结符(如expression)内部使用非跳跃式非终结符(如term)时,一切都像我期望的那样工作-空格只在内部起作用term非终结符。此外,到目前为止,我一直很好地包括在不使用qi::skip重新建立跳过的非终端内部使用skipper的非终端,例如in

c++ - 为什么 "default"是复制/移动构造函数或析构函数?

C++0x允许您将某些函数指定为默认函数:structA{A()=default;//defaultctorA(Aconst&)=default;//copyctorA(A&&)=default;//movectorA(Other);//otherctor~A()=default;//dtorA&operator=(Aconst&)=default;//copyassignmentA&operator=(A&&)=default;//moveassignment};这些函数的实现与编译器生成它们一样,在您不声明自己的大多数情况下通常会发生这种情况。如果您声明任何构造函数(上述任何其他构

c++ - “Default member initializer needed within definition of enclosing class outside of member functions” - 我的代码格式不正确吗?

structfoo{structbar{~bar(){}//noerrorw/othisline};bar*data=nullptr;//noerrorw/othislinefoo()noexcept=default;//noerrorw/othisline};是的,我知道,还有一个题目完全相同,但有点不同的问题(涉及noexceptoperator和没有嵌套类型)。那里建议的解决方案(将foo的构造函数替换为foo()noexcept{})改变了语义,这里没有必要:这里我们有一个更好的答案(因此问题不是重复的)。编译器:AppleLLVM版本9.0.0(clang-900.0.37)

c++ - std::is_default_constructible<T> 错误,如果构造函数是私有(private)的

我有以下片段#include#includeclassC{C(){}};intmain(){static_assert(!boost::has_trivial_default_constructor::value,"Constructible");static_assert(!std::is_default_constructible::value,"Constructible");}条件不相等,但第一个条件工作正常,第二个构造给出错误,构造函数是私有(private)的。编译器gcc4.7...那么,这是gcc错误,还是由标准定义的?http://liveworkspace.org/

C++ [[gnu::visibility ("default")]] 与 Windows 和 Linux 上的 __declspec(dllexport)

我需要用C++创建一些共享库,我使用linux作为我的开发者操作系统。我知道如果我想通过dlsym/LoadLibrary加载它们,我需要让符号可见。所以在Linux中,我所有的符号都遵循这种模式:extern"C"[[gnu::visibility("default")]]voidf();我在启用C++11的情况下使用了clang,并且能够在我的主机程序中加载f。当我转移到Windows时,我使用启用了C++11的GCC4.8.2,并且该模式在Windows机器上也适用于LoadLibrary。(我需要使用C++11来实现新的属性语法)。我知道在Windows上我需要使用__decl

c++ custom UI ToolKit -- 跨平台抽象层的选项

作为跨平台文本编辑器SublimeText2的粉丝,我一直在研究它的开发方式。开发人员注意到它是99%的c++和一些用于linux的GTK,并且它使用他称之为“SublimeGUI”的自定义UI工具包。这是来自开发者的引述SublimeText2itselfusesacustomUItoolkit.Therearealotofappswherethismaynotmakesense,butit'snotsuchanunreasonablechoiceforSublimeText,whereIalwaysknewthatalotoftheUIcontrolsweregoingtohave

c++ - 在 =delete 的含义中使用 =default

下面的代码编译的很好:structB{B(int){}};structD:B{D()=default;};直到我必须创建类D的实例:Dd;//error:useofdeletedfunction'D::D()'是否有任何理由(用例)允许D的构造函数使用=default,而实际上它的工作原理是=delete;? 最佳答案 g++在错误中给出了很好的解释:bla.cpp:6:5:note:‘D::D()’isimplicitlydeletedbecausethedefaultdefinitionwouldbeill-formed:D()

c++ - 为什么我不能将 =default 用于带有成员初始值设定项列表的默认 ctors

考虑以下类:classFoo{inta,b;public:Foo():a{1},b{2}{}//Defaultctorwithmemberinitializerlist//Foo():a{1},b{2}=default;//Doesnotworkbutwhy?};(编辑:因为在几个答案中提到了它-我知道类内成员初始化器,但这不是这里的重点)我认为第二个ctor定义会更优雅并且更适合现代C++代码(另请参见whyyoushoulduse=defaultifyouhavetobeexplicitaboutusingthedefaultsemantics)。但是,似乎没有通用编译器接受它。c

c++ - 没看懂Stroustup先生建议删除抽象类Shape的copy default和move操作

我试图理解作者在他的新书(TCPL第4版)中3.3.4SuppressingOperations中的建议,但无济于事。书摘Usingthedefaultcopyormoveforaclassinahierarchyistypicallyadisaster:Givenonlyapointertoabase,wesimplydon’tknowwhatmembersthederivedclasshas(§3.3.3),sowecan’tknowhowtocopythem.So,thebestthingtodoisusuallytodeletethedefaultcopyandmoveoper