草庐IT

it_begin

全部标签

c++ - std::begin 和 std::end 的 const 重载的目的是什么?

对于std::begin,我们有两个容器重载:templateautobegin(C&c)->decltype(c.begin());templateautobegin(constC&c)->decltype(c.begin());但是C的常量可以通过通常的模板推导规则来推导,所以看起来第二个重载是多余的。我错过了什么? 最佳答案 在右值上调用begin(和end,就此而言)是合理的,前提是我们在容器被销毁后不使用生成的迭代器。但是,将右值传递给T&形式的参数将不起作用,这是第二个重载发挥作用的地方。但是,很可能我们正在处理对前ra

c++ - 函数参数求值顺序 : is it UB if we pass reference?

这是未定义的行为:voidfeedMeValue(intx,inta){cout因为根据首先评估的参数,我们可以调用(3,2)或(3,3)。但是:voidfeedMeReference(intx,intconst&ref){cout总是会输出33因为第二个参数是一个引用并且所有参数在函数调用之前都已经被计算过了,所以即使第二个参数在ra=3之前或之后被计算过,该函数收到了对a的引用,该引用在评估时将具有2或3的值,但是在函数调用时将始终具有值3。第二个例子是UB吗?知道这一点很重要,因为如果编译器检测到未定义的行为,它可以自由地做任何事情,即使我知道它总是会产生相同的结果。注意:我将留

c++ - 函数参数求值顺序 : is it UB if we pass reference?

这是未定义的行为:voidfeedMeValue(intx,inta){cout因为根据首先评估的参数,我们可以调用(3,2)或(3,3)。但是:voidfeedMeReference(intx,intconst&ref){cout总是会输出33因为第二个参数是一个引用并且所有参数在函数调用之前都已经被计算过了,所以即使第二个参数在ra=3之前或之后被计算过,该函数收到了对a的引用,该引用在评估时将具有2或3的值,但是在函数调用时将始终具有值3。第二个例子是UB吗?知道这一点很重要,因为如果编译器检测到未定义的行为,它可以自由地做任何事情,即使我知道它总是会产生相同的结果。注意:我将留

c++ - STL 算法将整个容器而不是 .begin(), end() 作为 arg?

这个问题在这里已经有了答案:Whydon'tstd::algorithmsworkdirectlyoncontainersaswell?(3个回答)关闭1年前。独立的STL算法(如std::count_if)采用一对迭代器。在我使用这些的所有情况下(以及我在网上看到的所有示例!),我发现自己在输入std::count_if(myContainer.begin(),myContainer.end(),/*...*/);样式的速记模板有什么原因吗std::count_if(myContainer,/*...*/);没有提供,因为更多的是对整个容器执行的操作?我只是忽略了吗?c++11和c+

c++ - STL 算法将整个容器而不是 .begin(), end() 作为 arg?

这个问题在这里已经有了答案:Whydon'tstd::algorithmsworkdirectlyoncontainersaswell?(3个回答)关闭1年前。独立的STL算法(如std::count_if)采用一对迭代器。在我使用这些的所有情况下(以及我在网上看到的所有示例!),我发现自己在输入std::count_if(myContainer.begin(),myContainer.end(),/*...*/);样式的速记模板有什么原因吗std::count_if(myContainer,/*...*/);没有提供,因为更多的是对整个容器执行的操作?我只是忽略了吗?c++11和c+

解决:Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools“

一、问题在安装Python包的时候出现这种报错,是MicrosoftVisualC++14.0BuildTools不全的原因error:MicrosoftVisualC++14.0isrequired.Getitwith"MicrosoftVisualC++BuildTools":http://landinghub.visualstudio.com/visual-cpp-build-tools二、解决参考他人博客,有如下两种方法1、离线安装【亲测有效】(1)下载离线包到下面链接中下载完整的BuildTools包,如果博客内容里的不能用,就到评论区找(已解决)win10安装visualstudi

c++ - 'std::vector<T>::iterator it ;' doesn' t 编译

我有这个功能:templatevoidInventory::insertItem(std::vector&v,constT&x){std::vector::iteratorit;//doesn'tcompilefor(it=v.begin();it而g++给出了这些错误:src/Item.hpp:Inmemberfunction‘voidyarl::item::Inventory::insertItem(std::vector>&,constT&)’:src/Item.hpp:186:error:expected‘;’before‘it’src/Item.hpp:187:error:‘

c++ - 'std::vector<T>::iterator it ;' doesn' t 编译

我有这个功能:templatevoidInventory::insertItem(std::vector&v,constT&x){std::vector::iteratorit;//doesn'tcompilefor(it=v.begin();it而g++给出了这些错误:src/Item.hpp:Inmemberfunction‘voidyarl::item::Inventory::insertItem(std::vector>&,constT&)’:src/Item.hpp:186:error:expected‘;’before‘it’src/Item.hpp:187:error:‘

c++ - vector::begin() 和 std::begin() 之间的区别

在c++中迭代vector时,我注意到标准库中有一个begin()函数,还有一个begin()作为成员函数vector类。如果有的话,两者之间有什么区别,应该使用哪个而不是另一个?例子:vectornumbers;//Codetoputvaluesinmyvectorfor(vector::iteratori=numbers.begin();i对比:vectornumbers;//Codetoputvaluesinmyvectorfor(vector::iteratori=std::begin(numbers);i 最佳答案 std

c++ - vector::begin() 和 std::begin() 之间的区别

在c++中迭代vector时,我注意到标准库中有一个begin()函数,还有一个begin()作为成员函数vector类。如果有的话,两者之间有什么区别,应该使用哪个而不是另一个?例子:vectornumbers;//Codetoputvaluesinmyvectorfor(vector::iteratori=numbers.begin();i对比:vectornumbers;//Codetoputvaluesinmyvectorfor(vector::iteratori=std::begin(numbers);i 最佳答案 std