kphmd's blog

By kphmd, 15 years ago, In English
#define foreach(ite,sets) for(__typedef(sets.begin()) ite=sets.begin();ite!=sets.end();ite++)
Do you like this code?
gl & hf
  • Vote: I like it
  • -17
  • Vote: I do not like it

15 years ago, hide # |
 
Vote: I like it +11 Vote: I do not like it
15 years ago, hide # |
 
Vote: I like it +10 Vote: I do not like it
Do people enjoy living in the past? Why do you need a macro for something which has been part of the language for a while now?

int my_array[5] = {1, 2, 3, 4, 5};
for (int &x: my_array) {
    x *= 2;
}


15 years ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

If one feels necessity of such constructions, may be it is time to change to java?

Surely there are far more languages, I just suppose that java syntax would not be radically new to C++ programmer and performance decrease would not be radical too... Note that I am not against C++ (I use it for more than 10 years already), but sometimes I feel that there is too much plus-pluses for one poor programmer... ;-)
  • 15 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it
    Remember that such constructions are read-only in Java
    int[] a = {1, 2, 3, 4, 5};
    for (int x : a) {
        x *= 2; // actually elements of array don't change
    }