草庐IT

copy-initialization

全部标签

c++ - 是否可以从大括号类型的初始化中推断出元组的模板参数?

在这个例子中,是否可以允许推导元组的模板参数类型?#include#includetemplatevoidfun(std::tuplet,std::stringother){}intmain(){fun(std::tuple(2.,3),std::string("other"));//okfun(std::make_tuple(2.,3),std::string("other"));//ok,buttryingtoavoid`make_tuple`fun({2.,3},std::string("other"));//desiredsyntaxbut//givingcompilation

c++ - std::copy 的限制是否比 std::memcpy 更宽松?

与regardtothe问题copyvs.memcpyvsmemmove(这里的信息非常好,顺便说一句。),我一直在阅读,在我看来,这不像口语中所说的,例如cppreference注意:memcpy已更改为memmove,因为采用了此引用。--NotesInpractice,implementationsofstd::copyavoidmultipleassignmentsandusebulkcopyfunctionssuchasstd::memcpyifthevaluetypeisTriviallyCopyable--std::copy(也不是std::copy_backward)不

c++ - 我应该从 Boost::filesystem::copy 得到什么错误代码

我正在尝试使用带有system::error_code参数的boost::filesystem::copy_file将文件复制到目标位置,因为我不想抛出异常。如果同名文件已经存在,该函数接受一个参数是否应该失败,这是我想要的行为。来自http://www.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/reference.html#copy_file:Effects:Ifoption==copy_option::fail_if_exists&&exists(to),anerrorisreported.但是,我找不到我应该期待的错误代码。

c++ - 不能将 std::vector<T> 转换为 std::initializer_list<T> 吗?

我还以为有人可以做到这一点?然而,情况似乎并非如此。为什么?还是我做错了什么?#include#include#includeusingnamespacestd;voidfn(std::initializer_listi){for(intivalue:i){cout{4,5,6})return0;}demo我问这个的原因是因为我有一个带有初始化列表的类,我是从它派生的,但需要在将初始化列表传递给基类之前修改初始化列表。我怎样才能做到这一点? 最佳答案 有时旧的方法是最好的方法:只传入范围:voidfn(std::initialize

c++ - CUDA 推力 : copy from device to device

我使用标准CUDAmalloc在CUDA中分配了一个内存数组,并将其传递给函数,如下所示:voidMyClass::run(uchar4*input_data)我还有一个类成员,它是一个推力device_ptr声明为:thrust::device_ptrdata=thrust::device_malloc这里的num_pts是数组中值的个数,input_data指针保证是num_pts长。现在,我想将输入数组复制到thrust_device_ptr中。我看过推力文档,其中很多都在谈论从设备复制到主机内存,反之亦然。我想知道在推力上执行此设备到设备复制的最佳性能最佳方式是什么,还是我应该

c++ - 编译器错误 : "Non-aggregates cannot be initialized with initializer list."

尝试在C++中创建一个简单的vector时,出现以下错误:Non-aggregatescannotbeinitializedwithinitializerlist.我使用的代码是:#include#include#includeusingnamespacestd;intmain(intargc,char*argv[]){vectortheVector={1,2,3,4,5};cout我试着把:CONFIG+=c++11进入我的.pro文件,保存并重建它。但是,我仍然遇到同样的错误。我正在使用我认为是Qt5.5的东西,如果它对你有意义的话,这是当我按下About时发生的事情:Qt'sAb

c++ - CMake : softlink resource ( such as GLSL shaders ) or copy each complilation

使用CMake将资源从源目录复制到构建目录的最简单方法是file(COPY${CMAKE_CURRENT_SOURCE_DIR}/resourcesDESTINATION${CMAKE_CURRENT_BINARY_DIR})但是,这仅当我调用cmake时才会更新构建目录中的资源。我需要每次调用make来更新资源。例如现在我开发了一些GLSL着色器。我需要同时更改C++代码和GLSL代码,并且我需要在我的IDE中每次点击compile或run时一切都同步(我将CodeBlocks与CMake生成的项目文件一起使用)简单的解决方案是使从源目录到构建目录的软链接(softlink)。但我不

c++ - [conv]/6中语句 "The expression e is used as a glvalue if and only if the initialization uses it as a glvalue"的确切含义是什么

[conv]/6(重点是我的):Theeffectofanyimplicitconversionisthesameasperformingthecorrespondingdeclarationandinitializationandthenusingthetemporaryvariableastheresultoftheconversion.TheresultisanlvalueifTisanlvaluereferencetypeoranrvaluereferencetofunctiontype([dcl.ref]),anxvalueifTisanrvaluereferencetoob

C++符号分析: how to determine which static initialization is performed?

我想分析是什么原因导致我在Linux上由GCC(v.6.1.1)编译的共享C++库的大小。readelf-sWlibfoo.so告诉我特别大的函数叫做__static_initialization_and_destruction_0,例如:000000000026c42010272FUNCLOCALDEFAULT12__static_initialization_and_destruction_0(int,int)[clone.constprop.1774]我将-Wl,-Map,foo.map添加到CXX标志以生成链接器映射文件。在该映射文件中查找0x000000000026c420会

c++ - 海湾合作委员会 : C++11 inline object initialization (using "this") does not work when there is a virtual inheritance in hierarchy

当在初始化中使用此指针并且在层次结构中存在虚拟继承时,C++11内联对象初始化不起作用(在GCC中)。这可能是GCC的错误吗(因为它在CLang中工作)?还是C++11标准本身的差距?示例(可以在here中尝试),当使用GCC编译以下代码时:FieldIndexm_inB{"inB",this};不会被执行。但它会在使用CLang编译时执行。变通方法:从FieldIndexContainer派生A作为虚拟#include#include#includeusingnamespacestd;classFieldIndexContainer{public:classFieldIndex{pu