开发者

enumurator or Iterator?

I am very new to Windows. While I was working with WMI, I saw there was no use of the term iterator rather enum or enumurator has been used for the same purpose. Do they really have iterators ? or they replace the term, iterator with enum or enum, E开发者_开发知识库numVariant etc ..... Or I am missing some thing about iterator and enumurator. As far I knew Traditionally the term enum is not same as iterator. Am I wrong ?


Enum is both a thing (a list of possible values) and an action (stepping through each item in a list). The Windows API uses both terms, relying on context to differentiate them.

As a general rule, function and interface names with "Enum" in their name mean enumerate, e.g. EnumWindows means enumerate windows and IEnumUnknown (a COM interface) means enumerate unknown [objects].

The Windows API has no single enumeration methodology. EnumWindows implements the loop internally and repeatedly calls you back via a handler function while IEnumUnknown requires the caller to write the loop using a Next() function.

So, on Windows, an enumerator is a broad class of solutions to the problem of walking through a list of elements.

Iterators are the C++ standard library concept of an enumerator. Choosing 'iterator' instead of 'enumerator' was probably done intentionally to avoid confusion with the existing enum language concept.

Unlike Windows, the C++ standard library iterator concept is very well defined: all iterators work like pointers; all iterators require the caller to write the loop, etc. There are a few classes of iterators in the C++ standard library that allow accessing elements linearly, in reverse, or randomly.


The term enumerator is often used as a synonym for iterator.

An enum, or enumeration, is something else altogether.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜