For each loop in Native C++

  今天发现 for each 语法居然可以直接编译通过,之前还以为只有开了/clr才可以支持。查了一下资料发现ms从vs2005就已经支持了。虽然不符合标准不过用着确实方便啊,必须记录一下。

  具体看这里,已经有人介绍过了。http://www.codeproject.com/Tips/76166/For-each-loop-in-Native-C

Since Visual Studio 2005, native C++ has had a ‘for each’ loop construct, like C# or Java. Unfortunately it is restricted to collections from the STL library, such as vector. However, it does mean you can write very neat code to iterate through such a collection:

vector<int> data(3);
data[0] = 10;
data[1] = 20;
data[2] = 30;

//instead of this
int total = 0;
for (vector<int>::iterator vi = data.begin(); vi != data.end(); vi++)
{
    int i = *vi;
    total += i;
}
cout << "total: " << total << endl;

// do this:
total = 0;
for each( const int i in data )
    total += i;
cout << "total: " << total << endl;

Now we just need that making part of the C++ standard! If you are writing standard compliant code you will have to use the for_each function [^].
时间: 2024-08-28 08:29:02

For each loop in Native C++的相关文章

RakNet基本教程

官方网址:http://www.jenkinssoftware.com/raknet/manual/tutorialsample3.html Tutorial code sample 3 Remote procedure call setup.  The target of this exercise was to add the following features to sample 2: When the client successfully connects, send a custo

Android Native层Binder.transact()函数调用 Binder.onTransact() 函数失败分析

Q:Android Native层Binder.transact()函数调用 Binder.onTransact() 函数失败? 在Android Native层调用Camera.h中的api实现一个截屏功能的应用时,发现通过gCamera->setListener(new ScreenCaptureListener())设置到Camera的mListener的用于接收Camera预览数据的回调函数没有被调用,导致截屏失败? 注: Camera类文件汇总: libcamera_client.so

事件轮询 event loop

Understanding the node.js event loop The first basic thesis of node.js is that I/O is expensive: So the largest waste with current programming technologies comes from waiting for I/O to complete. There are several ways in which one can deal with the

Eclipse编辑java文件报Unhandled event loop exception错误的解

本人Eclipse版本是"eclipse-jee-kepler-SR2-win32-x86_64" 昨天因为换电脑,所以重装了一下软件,装好eclipse之后eclipse是可以使用的(换电脑之前也一直是用这个版本).后来又装了其他一些软件, 为了工作效率,只有边装软件边coding.后来发现再次在Eclipse中编辑java文件就一直会弹出错误提示框.如图. 点开图下面的"Unhandled event loop exception"查看具体的错误,详细错误如下.

Eclipse的 &quot;Unhandled event loop exception&quot; 问题解决方法

以前从没遇到过这种问题,发现自重装系统后,就开始触发这个bug了. 从error-log等视图里点击打开的java文件或者xml文件时,出现”unhandled event loop exception”错误,出错信息如下: Exception Stack Trace: org.eclipse.swt.SWTError: No more handles at org.eclipse.swt.SWT.error(SWT.java:4387) at org.eclipse.swt.SWT.error

Eclipse发生异常Unhandled event loop exception No more handles

eclipse发生异常: org.eclipse.swt.SWTError: No more handles at org.eclipse.swt.SWT.error(SWT.java:4387) at org.eclipse.swt.SWT.error(SWT.java:4276) at org.eclipse.swt.SWT.error(SWT.java:4247) at org.eclipse.swt.widgets.Widget.error(Widget.java:468) at org

ReactJs和React Native的那些事

介绍 1,React Js的目的 是为了使前端的V层更具组件化,能更好的复用,它能够使用简单的html标签创建更多的自定义组件标签,内部绑定事件,同时可以让你从操作dom中解脱出来,只需要操作数据就会改变相应的dom. 2,React Native的目的 是希望我们能够使用前端的技术栈就可以创建出能够在不同平台运行的一个框架.可以创建出在移动端运行的app,但是性能可能比原声app差一点. 3,ReactJs和React Native的原理是相同的,都是由js实现的虚拟dom来驱动界面view层

【symfoware NATIVE】数据库应用

Symfoware  NATIVE系 [共通]应用程序开发环境开发语言            操作数据库方法  C                   SQL嵌套  C++                 ODBC  C#                  .NET Framework  COBOL               SQL嵌套.ODBC..NET Framework  Java                Java  Visual Basic        ODBC  Visual

工作邮件loop的用法

examples come from native speaker Put john in the loop about this. He will have good advice. Why have I been cut out of the loop? I need to know about this stuff. Who all is 'in the know'? I need to be sure I know so I do not talk to someone out of t