English 中文(简体)
是否导致病媒的重新定位?
原标题:Does std::erase() and std::erase_if() cause reallocation of the vector?
  • 时间:2024-01-20 02:14:01
  •  标签:
  • c++
  • std
  • c++20

如问题标题所示,在<代码>上:erase()和std:erase_if( 病媒重新定位的原因?

两者中哪一种效率更高:我是否应当使用切除的异构体,或者我是否应当直接使用<代码>std:erase_if(?

I assume that no reallocation is supposed to happen since no additional memory is requested when removing elements from the vector but I would like to have a definitive answer to that.

问题回答

只有在病媒生长时才会重新定位。 <代码>erase或erase_if/code>在逻辑上不可能使病媒大于原样。 永远不会发生重新分配。

As far as which one is more "efficient" that s mostly meaningless. The two methods are not comparable replacements for each other. If one needs to select values to remove based on some logical criteria, anything other than a fixed value, erase_if is your only option. No matter how hard you ll try you won t accomplish your goals with erase, but only erase_if, no matter how much the former is or is not "efficient".

在只需要删除固定价值的情况下,大多数现代C++汇编者很可能最终产生类似的(如果不是相同的话)代码:<代码>eraseerase_if。 但是,随着现代的多国集团(CPU)的形成,很难说明差异;然而,<代码>erase导致更短的简单代码,而C++则不太明智。 这是一件好事。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签