Foreach-statement in c ++ and language extension?

微信扫一扫,分享到朋友圈

Foreach-statement in c ++ and language extension?

You can simulate foreach-statement in c++ with macro declaration. I’m using similar syntax for looping arrays in the following way:

int array1[10];
vector array2(10);

fori(array1)
    forj(array2)
        fork(123)
             if(array1[i]==array[j])
                  return true;

What’s your favorite macros for extending c++ language in some way?

EDIT:

Implementation of the macro mentioned in the question is:

#define fori(a) for(int i=0;i<getsize(a);i++)
#define forj(a) for(int j=0;j<getsize(a);j++)
#define foru(a) for(int u=0;u<getsize(a);u++)
#define fork(a) for(int k=0;k<getsize(a);k++)
#define forl(a) for(int l=0;l<getsize(a);l++)

template
int getsize(T& v ){return v.size();}
template
int getsize(T(&v)[N]){return N;}
int getsize(int v){return v;}

微信扫一扫,分享到朋友圈

Foreach-statement in c &plus;&plus; and language extension&quest;

小屏iPhone将再度发售,没有全面屏,苹果如何抢占中低端市场?

上一篇

How can i include mouse over effect for each bar in html 5 chart

下一篇

你也可能喜欢

Foreach-statement in c &plus;&plus; and language extension&quest;

长按储存图像,分享给朋友