|
|
|
|
|
|
|
浅谈 C# 中的代码协同 (Coroutine) 执行支持3 |
|
|
|
br> 例如上面这段 Ruby 的递归目录处理代码中,就采用了与 C# 2.0 中完全类似的语法实现协同执行支持。 对 C# 1.0 和 C++ 这类不支持协同执行的语言,协同执行过程中的状态迁移或者说执行绪的调度工作,需要由库和使用者自行实现,例如 STL 中的迭代器 (iterator) 自身必须保存了与遍历容器相关的位置信息。例如在 STL 中实现协同执行: 以下内容为程序代码: #include #include #include // The function object multiplies an element by a Factor template class MultValue { private: Type Factor; // The value to multiply by public: // Constructor initializes the value to multiply by MultValue ( const Type& _Val [img]/images/wink.gif[/img] : Factor ( _Val [img]/images/wink.gif[/img] { } // The function call for the element to be multiplied void operator ( [img]/images/wink.gif[/img] ( Type& elem [img]/images/wink.gif[/页码:[1] [2] [3] [4] [5] [6] [7] [8] 第3页、共8页 |
|
|
|
|
设为首页 | 加入收藏 | 广告服务 | 友情链接 | 版权申明
Copyriht 2007 - 2008 © 科普之友 All right reserved |