mercredi 29 avril 2015

Can I create a new syntax in C++?

I am quite fond of Python generator expression and (ab)use it a lot in Python. Now I am (up to no good) working on implementing generator expression on C++ 11, using macros embedded in macros, lambdas and more obscure things. My aim is to copy all abilities of operator as close as possible. There are some implementations already, but they lack multi-variable support.
Python most complex syntax looks like

generator = i*j for i,j in zip(arr1,arr2) if i>0 and j>0 # Python

This line produces a functor that returns on every successfull call a multiplication of repective values from two arrays. And in my realization syntax now looks like

auto generator = brf_genexpr(i*j,(i,j),zip(arr1, arr2),i>0 && j>0); //C++11

My question is: do you know some way, however exotic, to get rid of those lots of commas and allow me to write

auto generator = brf_genexpr(i*j for i,j in zip(arr1,arr2) if (i>0 && j>0));

I do understand that I can write a preprocessor script that would change syntax for me, but I would love a in-code solution.

Aucun commentaire:

Enregistrer un commentaire