草庐IT

is_constexpr_copiable

全部标签

c++ - 具有未触及的非 constexpr 参数 : Who is correct, clang 或 gcc 的 constexpr?

我有4个测试用例,我相信它们都是有效的:constexprintf(intconst&/*unused*/){return1;}voidg(intconst&p){constexprinta=f(p);//clangerror,gccvalidintv=0;constexprintb=f(v);//clangvalid,gccvalidintconst&r=v;constexprintc=f(r);//clangerror,gccerrorintn=p;constexprintd=f(n);//clangvalid,gccvalid}intmain(){intp=0;g(p);}Cla

c++ - 为什么 std::scan_is 在 vi​​sual studio 编译器中发出运行时错误?

示例here在VisualStudio2013中发出内存访问冲突的运行时错误。#include#include#includeintmain(){auto&f=std::use_facet>(std::locale(""));//skipuntilthefirstletterchars1[]="\t\t\nTest";constchar*p1=f.scan_is(std::ctype_base::alpha,std::begin(s1),std::end(s1));std::cout这是为什么呢?编译器的错误实现? 最佳答案 aut

c++ - SFINAE 在评估模板参数中的 constexpr 时失败?

出于某种原因,此constexpr在模板参数上下文中未被正确评估:#include#includenamespacedetail{//Reasontouseanenumclassrahterthanjustanintissoastoensure//therewillnotbeanyclashesresultinginanambigiousoverload.enumclassenabler{enabled};}#defineENABLE_IF(...)std::enable_if_t=detail::enabler::enabled#defineENABLE_IF_DEFINITION(

c++ - CUDA 内核 "Only a single pack parameter is allowed"解决方法?

关于可变全局函数模板的CUDA7标准指出"onlyasinglepackparameterisallowed."有没有优雅的解决方法?我希望能够做类似的事情:templatevoidRecursiveFunct(){}templatevoidRecursiveFunct(Tt,Args...args){t.templatecall();RecursiveFunct(args...);}我想我可以在传递它们之前将我的整数包包装成某种东西,但是否可以通过一种对该代码的调用者透明的方式来做到这一点? 最佳答案 不确定是否理解您的确切限制,

c++ - 如何在不重复代码的情况下使用 if-constexpr?

目前我在做:ifconstexpr(constexpr_bool_var1){autoarg1=costly_arg1();autoarg2=costly_arg2();if(costly_runtime_function(arg1,arg2)){//doX,possiblymoreconstexprconditions//doY//...}}else{//doX,possiblymoreconstexprconditions//doY//...}一种可能的方法是将doX/Y等转换为一个函数doXY()并在两个地方调用它,但是它看起来很笨拙,因为我必须编写一个函数,它只存在于方便元编程

c++ - 在某些情况下允许从 constexpr 调用非 constexpr 函数

来自那个问题:Howtobuildacustommacrothatbehavesdifferentlywhenusedasconstexpr(likeassert)?我想知道如果有条件的话为什么可以调用非constexpr函数。voidbla(){std::coutnotconstexpr!condition?void(0):bla();//compilesandrunsevenifconditionistrueorfalse!//ifconditionisconst,itdidnotcompilebecauseit//directlyforceexecutionofnonconste

c++ - constexpr 构造函数不会显示覆盖率数据

今天我将矩阵类重写为constexpr。我对这个类有100%的单元测试覆盖率,但我注意到在我将几乎所有函数转换为constexpr之后,构造函数的一部分在lcov中被标记为根本不再被覆盖。这是只有构造函数的类。templateclassMatrix{static_assert(std::is_arithmetic::value,"Matrixcanonlybedeclaredwithatypewhere""std::is_arithmeticistrue.");public:constexprMatrix(std::initializer_list>matrix_data){if(ma

c++ - 调用模板参数 constexpr 方法?

std::array::size()是非staticconstexpr方法;正在constexpr我可以将它用作模板参数:#include#includeintmain(void){std::arraya={{"Helloworld"}};std::coutb=a;std::cout但是,如果std::array是一个模板参数,事情变得不确定:templatevoidcopy(Tconst&a){std::arrayc=a;std::coutGCC愉快地编译这个[1],而CLANG拒绝[2]:6:20:error:non-typetemplateargumentisnotaconsta

c++ - 导致运行时执行的 constexpr 仿函数中的成员

我正在使用仿函数以下列方式生成编译时计算代码(对于长代码我深表歉意,但这是我发现重现该行为的唯一方法):#include#includetemplateconstexprautocompute(constdoubleh){std::tuple,std::array>paw{};autoxtab=std::get(paw).data();autoweight=std::get(paw).data();ifconstexpr(order==3){xtab[0]=-1.0E+00;xtab[1]=0.0E+00;xtab[2]=1.0E+00;weight[0]=1.0/3.0E+00;we

c++ - 错误 "lambda is not derived from ' std::function'

我正在尝试将lambda传递给通过可变参数模板定义的std::function,但似乎这在gcc上不起作用。有什么原因,为什么这段代码在gcc7.4.0上不起作用,但在VisualStudio2017上却能正常工作?有没有办法让它在gcc上也能工作,而无需先手动将其转换为std::function?#includetemplateintTestFunction(std::function){return0;}voidTest(){autofce=[](int/*n*/,double/*d*/){};//Thisdoesn'tworkwitherrornomatchingfunction