草庐IT

is_constexpr_copiable

全部标签

c++ - Opencv 错误 : no GPU support (library is compiled without CUDA support)

我正在尝试使用CUDA在GPU上使用opencv处理一些图像处理任务。我正在使用ubuntu。我毫无问题地设置了我的两个产品Opencv和Cuda,我确信这一点。但是,当我尝试在eclipse中运行sampleCOde时,出现错误:OpenCV错误:在mallocPitch中没有GPU支持(库在没有CUDA支持的情况下编译),文件/home/muad/Source/OpenCV-2.4.2/modules/core/src/gpumat.cpp,第749行我重做了我的opencv,但我还是明白了。 最佳答案 如文档中所述,您必须使用

C++11 is_pod 与 GCC 4.6

在relaxeddefinitionofPOD下在C++11中,我的理解是以下结构被视为POD:templatestructFoo{Foo(){}explicitFoo(T*obj):m_data(obj){}T*m_data;};但是,使用GCC4.6并使用-std=c++0x标志进行编译,如果我说:std::cout>::value输出:false这是一个ideonelink显示完整的程序。(注意ideone使用的是GCC4.5)那么,我对C++11中POD的理解是错误的,还是GCC4.6在C++11合规性方面根本不是最新的? 最佳答案

C++11 : Is it possible to give fixed-template-parameted template to varidic-template-template-parameter?

(是的,由于我糟糕的英语,标题很奇怪;我希望有人能改进它。)接听thisquestion,我发现这段代码有效:templateclassA{};templateclassU>classB{};intmain(){Bit_works;}..虽然templateclass和templateclass不相等。我试图弄清楚为什么这是可能的,并观察了N3337standard的[temp.param],但我找不到任何东西。怎么可能? 最佳答案 是的,这是可能的。C++1114.3.3/3特别允许,并提供了一个例子。3Atemplate-arg

c++ - 在 constexpr 构造函数中复制数组

我用constexpr复制构造函数编写了一个类。(在示例中它是一个结构,以使其更简单。)其中一个字段是一个数组。我也想复制。structFoo{staticconstexprintSIZE=4;constexprFoo()=default;constexprFoo(constFoo&foo):arr{foo.arr[0],foo.arr[1],foo.arr[2],foo.arr[3]},bar(foo.bar+1){}intarr[SIZE]={0,0,0,0};intbar=0;};我的版本有效,但不可扩展。如果我更改SIZE,我必须修改构造函数。此外,代码看起来很难看。在构造函数

c++ - 使用 float 给出 "call to overloaded function is ambiguous"错误

这个问题在这里已经有了答案:Referencetofunctionisambiguous[duplicate](2个答案)关闭6年前。我正在重载函数add(),但是当我使用float数据类型时它显示错误。但是,当我将其更改为double时,它工作正常。为什么float会导致错误?代码是:#includeusingnamespacestd;classstudents{private:inti;floatf;public:voidadd(intb){i=b;cout错误:Infunction'intmain()':[Error]callofoverloaded'add(double)'is

c++ - 逗号运算符使 lambda 表达式成为非 constexpr

根据[thisQ&A]因为c++11逗号运算符支持constexpr。根据[thisQ&A]constexpr变量不应被lambda捕获,但应在其主体内可用。这两条规则使得以下代码可以在clang中编译://Example1templatestructFoo{};intmain(){constexprintc=1;static_cast(Foo{});}//Example2templatestructFoo{};intmain(){constexprintc=1;autolambda=[]{returnc*2;};static_cast(Foo{});}然而,虽然这两个示例都在clan

c++ - 为什么在此 constexpr 函数中允许使用 std::swap?

我写了一个计算两个数字的gcd的函数,它使用std::swap在第二个参数大于第一个参数的情况下。一段时间后,我意识到std::swap不是constexpr,但我的函数仍然编译并成功运行。我尝试使用MinGW-w648.1.0和VisualC++2017,它对两者都有效。我的第一个想法是因为constexpr允许在运行时执行函数,所以我尝试了std::integral_constant,它奏效了。但是,我不能使用我自己的任何非constexpr函数(这是我所期望的)。这是我的测试代码:#includeinlinevoidfoo()noexcept{}templateconstexpr

c++ - 尝试实现 is_constexpr() - 编译器分歧

以下是基于RichardSmith实现is_constexpr()的三种尝试的answer至Isis_constexprpossibleinC++11?版本1templateboolconstexpris_constexpr_impl_1(constT&x,decltype(int{(x,0u)})){returntrue;}templateboolconstexpris_constexpr_impl_1(constT&,...){returnfalse;}templateboolconstexpris_constexpr_1(constT&x){returnis_constexpr_

c++ - SIMD : Why is the SSE RGB to YUV color conversion about the same speed as the c++ implementation?

我刚刚尝试优化RGB到YUV420转换器。使用查找表可以提高速度,就像使用定点算法一样。然而,我期待使用SSE指令获得真正的yield。我的第一次尝试导致代码变慢,并且在链接所有操作之后,它的速度与原始代码大致相同。我的实现是否有问题,或者SSE说明是否不适合手头的任务?部分原始代码如下:#defineRRGB24YUVCI2_000.299#defineRRGB24YUVCI2_010.587#defineRRGB24YUVCI2_020.114#defineRRGB24YUVCI2_10-0.147#defineRRGB24YUVCI2_11-0.289#defineRRGB24Y

C++11 constexpr 字符串实现

有没有办法让字符串在编译时和运行时都能工作?据我所知,要将一个类构造为constexpr,它需要有一个平凡的析构函数。然而,当我们处理字符串时,这被证明是困难的。如果字符串不是constexpr,则需要释放内存。然而,如果它是constexpr,那么它是静态分配的,不应被删除,因此允许一个微不足道的析构函数。但是,不可能说“嘿,编译器!如果我是constexpr,你不需要破坏我!”或者是?它会像下面这样:classstring{private:char*str;public:templateconstexprstring(constchar(&s)[l]):str(&(s[0])){}