下面的问题只是通过我的头部开枪。 对++级推器而言,一种共同做法是:
for (iterator it=obj.begin(); it!=obj.end(); it++)
我很想知道的是,如果要停止这种做法,就象:
for (iterator it=obj.begin(); !it.end(); it++)
这样做的好处是使变压器更加自封,而且能够在集装箱类别中节省(发动机终端)。
下面的问题只是通过我的头部开枪。 对++级推器而言,一种共同做法是:
for (iterator it=obj.begin(); it!=obj.end(); it++)
我很想知道的是,如果要停止这种做法,就象:
for (iterator it=obj.begin(); !it.end(); it++)
这样做的好处是使变压器更加自封,而且能够在集装箱类别中节省(发动机终端)。
如果设计该标的标的器具类似,那么点码就是一个有效的导体(因为点人显然有<代码>end()。 因此,这将排除最直截了当的方式,为数据结构提供随同的记忆。
Sometimes you want to do something other than iterate over the entire contents of a container. For example, you can create a pair of iterators that will iterate over only the first half of a container. So having a separate object to represent the end is more flexible since it allows the user more control of where to place the end of a range.
你们正确地认为,在一切事情的循环方面,这是最常见的情况。 然而,C++11为整个集装箱的住宿提供了一系列的通道,因此,如同方案规划中的许多内容一样,它实际上只是选择正确的建筑以最好地表达你的意向。
一些图书馆提供“java型异构体”。
然而,这一计划(hasNext(
>, 等)的主要问题是,这种装置是班级的。
For example, STL contains <algorithm>
header that contains functions like std::copy
, std::generate
, std::sort
, std::lower_bound
, std::fill
etc. All those routines use begin/end style iterators. As a result, you can use pointers with those functions. If those function were operating on iterators that are classes (i.e. if they called hasNext()
instead of != end()
internally), then you wouldn t be able to pass pointers into std::sort and such. In this scenario you would have to wrap everything into class, wasting your time, and losing access to <algorithm>
is not worth minor convenience you d get by adding atEnd()
method to iterator class. That s probably the reason why iterators are compared to the end()
.
对于集装箱而言,没有要求代用人“知道”。 它只能了解和注意在记忆或当前噪音(或适合于在数据结构上重新安装)中加以抵消,而不知道包裹的集装箱。 例如,vector
可以在不了解(本身)矢量达到目的的情况下,作为简单点实施器。
Also, STL algorithms need to work on raw pointers as well, so iterators need to "mimic" pointers.
归根结底,只是在发明了STL(在90年代初通过Steanov)并且后来在C++标准化过程中批准的决定,即一台自动取机将是一个点子。 http://www.sgi.com/tech/stl/stl_introduction.html”rel=“nofollow”http://www.sgi.com/tech/stl/stl_introduction.html:
In the example of reversing a C array, the arguments to reverse are clearly of type
double*
. What are the arguments to reverse if you are reversing a vector, though, or a list? ... The answer is that the arguments to reverse are iterators, which are a generalization of pointers.
主持人认为,点人一般化。 C++标准图书馆(以及在STL之前)理论上可以采用不同的代谢模式,在这种模式中,代号可以是单一代谢器物体,也可以是单一范围物体,而不是由散装机first
和last
的代表。
我认为,业绩会有很大的差异。 现代C++的编纂者肯定有 t。 STL(及其标准图书馆)始终依靠编辑的体面的入手,而这些班级比汇编者在集装箱舱面上已经处理的情况更糟。 提供简单包裹,把一把点子变成一个炉子或圈子也没有任何重大困难。
有些人选择其他电离器模型——James Gosling为一种(或如果不是他,则由谁设计出 Java器)。 一些人更喜欢范围(包括C++方案制定者:因此是Boost.Range)。
我怀疑STL和C++的作者也认为,STL型代号的变压器保留了一种与C的相容性,即你可以采用C算法,使用点码操作(或用户与点子公司指定的其他范围),并将之几乎改成C++算法,该算法使用探测器在集装箱(或其他范围)操作。 这种想法意味着你的新的语言,可以更容易地被现有的用户基础所吸收,而后者是C++早期的目标之一。
因此,例如,“如果我们能提供一种用于测试目的的手段,其特性是短的,其代价是使点人不再成为导师,使探测器更加强大”,那么现在可能不会引起很多兴趣。 但当时的情况是这样,例如,安德烈·亚历山德罗斯库一直在禁飞,而现在他认为这不是最佳选择,幅度比老板好。
主持人的工作方式使你具有就子安排开展工作的灵活性。 页: 1 例如,如果你想与所有具有一定价值的制造商合作,你可以把<条码>平等_range(<>/条码>的回报值用于你的开端和结束。
D语有range,其中既包括导体范围之始末。 还建议C++:
了解贵国的密码<>begin和end
(和rbegin
和rend
肯定是有用的,但你的情况由C++11 s 远程for
-loop处理:
for (auto it: obj)
{
// Do something with *it;
}
在C++11没有撰写这么多的锅炉-的情况下做事会变得非常容易!
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 ...
I have been searching for sample code creating iterator for my own container, but I haven t really found a good example. I know this been asked before (Creating my own Iterators) but didn t see any ...
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 ...
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?
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->...
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, ...
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 ...
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?