草庐IT

is_constexpr_copiable

全部标签

c++ - 为什么 std::is_constructible 在直接上下文中停止?

源自this话题。也与此有关topic.我的问题是为什么std::is_constructible在直接上下文中停止?我认为std::is_constructible的用户会期望它能够深入工作并给出准确的答案。有了这个直接的上下文,你可能会让std::is_constructible给你一个绿灯,只是在你实际执行它时得到一个硬编译器错误。这是否违背了std::is_constructible的最初目标和目的。现在,它对我来说基本上看起来没用。我想std::looks_constructible_at_first_sight是当前语义的更好名称:( 最佳答案

C++ 概念 : Can I define a concept that is itself a template?

抱歉,如果问题不太清楚。我不确定表达它的最佳方式(随意编辑!)。我认为一个例子是最清楚的:我试图根据Haskelldefinition定义一个Monad概念.绑定(bind)运算符(>>=)要求A类型的Monad可以绑定(bind)到接受A并返回B类型的Monad。我可以根据value_typetypedef定义A,但是如何在我的概念中定义类型B?templateconceptboolMonad(){returnrequires(Mm,Function>f){//(>>=)::ma->(a->mb)->mb{m>>=f}->M}}在上面的例子中,我用什么来代替Function概念中的_

c++ - 错误 "requested alignment is not an integer constant"

我在解决GCC问题时遇到问题。我在GCC4.8下体验过它,但不是5.1。看起来它被报道了here和/或here.问题如下:templatestructS{staticconstintALIGN=16;__attribute__((aligned(ALIGN)))intx;};intmain(intargc,char*argv[]){Ss1;Ss2;return0;}和:$g++test.cxx-otest.exetest.cxx:9:41:error:requestedalignmentisnotanintegerconstant__attribute__((aligned(ALIGN

c++ - 使用 constexpr C 字符串作为编译器错误消息

正如问题所暗示的,我想做的是templatestructbroken{templateconstexprbroken(Args&&...){//thesizeof...confusesthecompilerastoonlyemiterrorswheninstantiated//thisdoesnotwork,static_assertonlyacceptsstringliteralsstatic_assert(sizeof...(Args)我希望broken在实例化时发出编译器错误消息Err。但是,static_assert只接受一个字符串文字作为它的第二个参数。有什么方法可以根据co

c++ - 将 `hana::string` 转换为 `constexpr const char (&)[]`

我有一些旧代码使用了与str_const非常相似的东西描述here和here做一些constexpr字符串操作。str_const是ScottSchurr描述的文字类型,可以从字符串文字构造,因为它具有来自constchar(&)[]的模板构造函数.我现在也有一些使用boost::hana的新代码.我希望能够参加hana::string并创建一个str_const那是指它。最简单的方法是转换hana::string到constexprconstchar(&)[].(实际上,在这一点上这不是最简单的方法,最简单的方法肯定是在我的str_const实现中添加一个新的模板构造函数。但在这一点

c++ - 规则 "A user-defined but do-nothing destructor is also a non-trivial destructor"是否过于严格?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。ImprovethisquestionclassBase{public:~Base(){}private:intval;};Basebase;//aglobalvariable你看,析构函数什么都不做,和c++编译器提供的默认析构函数一样。但是根据帖子Whatisanon-trivialdestructorinC++?,析构函数仍然是一个非平凡的析构函数我知道,标准中的每条规则都必须严格。但是,根据我粘贴的上面的代码,用户定义

c++ - MSVC 无法识别带有模板自动参数的 constexpr 函数

我试图为值列表中的值创建一个索引元查找器。这是代码:#include#includetemplatestructValueTplList;templateconstexprintMetaFindV(intind){//notfoundcasereturn-1;}templateconstexprintMetaFindV(intind=0){ifconstexpr(std::is_same_v){returnNeedleV==V?ind:MetaFindV(ind+1);}else{returnMetaFindV(ind+1);}}//maintemplatestructMetaInde

C++ : subtracting unsigned values is unsigned

这个问题在这里已经有了答案:IssubtractinglargerunsignedvaluefromsmallerinC++undefinedbehaviour?(2个答案)关闭3年前。在C++中,编译器提醒我减去无符号值是无符号的,因此调用abs()是没有意义的:uint64_ta,b;if(std::abs(a-b)>10){std::cout好的,我知道减法就是加法,而且我知道在我的实例中数字将小于2^63,所以我将static_cast转换为int64_t。但是调用abs的目的是为了避免写if(a-b>10||b-a>10){std::cout有没有更惯用的方法来做到这一点?

c++ - `inline` , `constexpr` 或 `noexcept` 仅声明函数

对于没有主体的函数,仅用于类型检查目的或在非评估上下文中,是否有任何冒险将此类函数标记为inline,noexcept或constexpr?例如:namespace_detail{templateconstexprRresult_type(R(T::*)(Params...))noexcept;templateconstexprRresult_type(R(T::*)(Params...)const)noexcept;templateconstexprRresult_type(R(*)(Params...))noexcept;templateconstexprRresult_type(

c++ - g++, R_X86_64_32S : what is it?

我使用C++和OpenGL编写了一个3D引擎。我通常在我的archlinux64位上从事这个项目,但在这些假期我在32位系统上做。我使用subversion,自从我的64位系统上最后一次svn启动以来,我遇到了错误:http://pastebin.be/23730核心、包装器和接口(interface)是使用-fPIC选项编译的,我不明白所以...谢谢:) 最佳答案 这似乎是一个重定位错误,您的某些文件未使用-fPIC进行编译。更改您的标志以包含-fPIC,然后在再次构建之前执行makeclean。