草庐IT

move_if_noexcept

全部标签

c++ - 我怎么知道我使用的是复制还是 move ?

我对C++14标准库使用move语义的理解正确吗?换句话说,我可以确信我在以下程序中使用的是move而不是复制:#include#include#includeusingnamespacestd::string_literals;std::vectorgreeting(){std::vectorvs{"hello"s,"world"s};returnvs;}intmain(){std::vectors=greeting();std::cout有什么方法可以检查吗?在下面的例子中怎么样:#include#include#includeusingnamespacestd::string_l

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++ - noexcept(false) 析构函数覆盖所有特殊成员函数的异常规范?

考虑这个类TstructT{T()noexcept(true){}T(T&&)noexcept(true){}T(constT&)noexcept(true){}T&operator=(T&&)noexcept(true){return*this;}T&operator=(constT&)noexcept(true){return*this;}~T()noexcept(false){}};考虑这个简单的测试程序:intmain(){constexprbooldefault_ctor=noexcept(T());static_assert(default_ctor==true,"Defa

c++ - 当从函数返回元组时,元组的参数被复制而不是 move

我对以下代码有疑问。我的编译器是MSVC++17VisualStudio15.3版,编译器选项为/std:c++14(相对于/std:c++latest),在Release模式下运行:structBar{inta;std::stringb;Bar(){std::coutfoo(){std::strings="dsdf";return{{1,s},{5,"asdf"}};}intmain(){Bara,b;std::tie(a,b)=foo();std::cout输出是:defaultdefaultdirectdirectmovebconstcopyconstcopymoveassign

带有 std::enable_if 的 C++ 可变参数模板部分模板特化

ITNOA我的问题是如何在可变参数模板部分模板特化场景中使用std::enable_if?例如,我有一个类使用如下所示的可变参数模板部分特化/***Commoncase.*/templatestructfoo;/***Finalsuperclassforfoo.*/templatestructfoo{voidfunc(){}};/***Regularfooclass.*/templatestructfoo:publicfoo{typedefsuperfoo;voidfunc(){coutsuper::templatefunc();}}它工作正常,但如果H是整数类型,我想要特定的部分特化

c++ - gsl_vector 有 count_if 函数吗? C/C++

我正在使用gnu科学图书馆(GSL)。假设我有一个像这样的gsl_vector:70-658010-2这是一个包含正数、负数和零作为元素的vector。我想统计这个gsl_vector中非零元素或零元素的个数。我知道C++Vector有一个名为count_if的函数。但是我搜索了gsl_vector.h和gsl_blas.h,没有能与之匹敌的功能。我可以通过gsl_vector_get()评估它们来遍历所有元素,然后问if问题。intcounter=0;for(inti=0;i但是我想了将近一天,GSL中是否已经有这样一个效率更高的函数。或者gsl_array有一个count_if函数

C++11 - 单独 move 数组(原始数组、std::array、std::vector)的每个元素?

在C++11中,move语义等等,人们可能想知道实际上可以move什么。这方面的一个例子是数组。是否可以move原始数组的每个元素,intarray1[8];intarray2[8];array1[0]=std::move(array2[0]);std::数组,std::arrayarray1;std::arrayarray2;array1[0]=std::move(array2[0]);和std::vectorsstd::vectorarray1;std::vectorarray2;array1[0]=std::move(array2[0]);个人? 最佳

c++ - 将从函数返回 vector<vector <int>> 调用 C++11 中的任何 move 构造函数

在C++11中将返回一个vector>从函数调用任何move构造函数?还是下面的代码只是制作所有vector及其元素的另一个拷贝?vector>Func(){vector>vec;//vecisfilledherereturnvec;}对于简单类型的STL容器,当使用move构造函数或将它们作为函数值返回时进行复制时,是否有一个通用的发现? 最佳答案 return语句在标准中特别涵盖,可自动视为move。所以是的,这将调用move构造函数。这方面的法律条文是C++11,[class.copy]§31+32:31Whencertain

c++ - 将本地结构传递给 count_if

我正在尝试将匿名结构传递给std::count_if,但编译失败。当我尝试编译时(使用g++4.5.3,不使用c++03或c++11扩展),我在fail()方法中遇到错误,但是pass()方法没有那个错误。Infunction‘voidfail()’:Test.cpp:34:24:error:nomatchingfunctionforcallto‘count_if(std::map::iterator,std::map::iterator,fail()::&)’如果我将结构设为命名结构,我会遇到类似的错误。我不明白为什么在函数外部和内部声明它应该有所不同。我错过了什么?#include

LeetCode --- 2027. Minimum Moves to Convert String 解题报告12

https://h5.weishi.qq.com/weishi/feed/7OLnHCrBU1Rx4Avoshttps://m.weishi.qq.com/vise/share/index.html?id=7OLnHCrBU1Rx4Avoshttps://m.weishi.qq.com/vise/share/index.html?id=7OLnHCrBU1Rx4Avos&js=oszhttps://h5.weishi.qq.com/weishi/feed/7OLnHyfsP1Rx4AsKMhttps://m.weishi.qq.com/vise/share/index.html?id=7OLn