STL C ++和C#集装箱之间的映射 [英] Mapping between stl C++ and C# containers

查看:126
本文介绍了STL C ++和C#集装箱之间的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能指出与通常的C ++ STL容器如矢量,列表,地图,设置,多重映射之间良好的映射......在C#泛型容器?

Can someone point out a good mapping between the usual C++ STL containers such as vector, list, map, set, multimap... and the C# generic containers?

我习惯了前者的,不管怎样我已经习惯了自己来表达这些容器方面的算法。我有一些很难找到的C#等同于

I'm used to the former ones and somehow I've accustomed myself to express algorithms in terms of those containers. I'm having some hard time finding the C# equivalent to those.

感谢您!

推荐答案

下面是一个粗糙等价:


  1. 词典< K- ,V> < => 的hash_map< K,V>

  2. HashSet的< T> < => 的hash_set< T>

  3. 名单,LT ; T> < => 矢量< T>

  4. 的LinkedList< T> < => 列表< T>

  1. Dictionary<K,V> <=> hash_map<K,V>
  2. HashSet<T> <=> hash_set<T>
  3. List<T> <=> vector<T>
  4. LinkedList<T> <=> list<T>

在.NET BCL(基类库)没有红黑树(STL地图)或优先级队列(make_heap(),push_heap(),pop_heap())。

The .NET BCL (base class library) does not have red-black trees (stl map) or priority queues (make_heap(), push_heap(), pop_heap()).

.NET收藏不要使用迭代器的方式C ++一样。他们都贯彻的IEnumerable< T> ,并可以通过使用的foreach 语句中遍历。如果你想手动控制迭代,你可以称之为的GetEnumerator()的收集它会返回一个的IEnumerator< T> OBJET。 的IEnumerator< T> .MoveNext()大致相当于一个C++++迭代器,与当前的大致相当于指针,尊重运营商(* )。

.NET collections don't use "iterators" the way C++ does. They all implement IEnumerable<T>, and can be iterated over using the "foreach statement". If you want to manually control iteration you can call "GetEnumerator()" on the collection which will return an IEnumerator<T> objet. IEnumerator<T>.MoveNext() is roughly equivalent to "++" on a C++ iterator, and "Current" is roughly equivalent to the pointer-deference operator ("*").

C#确实有所谓的迭代的语言特色。他们是不一样的STL中的迭代器对象,但是。相反,它们是一种语言功能,允许自动执行的IEnumerable的< T> 。请参阅收益回报率产量突破语句以获取更多信息。

C# does have a language feature called "iterators". They are not the same as "iterator objects" in the STL, however. Instead, they are a language feature that allows for automatic implementation of IEnumerable<T>. See documentation for the yield return and yield break statements for more information.

这篇关于STL C ++和C#集装箱之间的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆