alternatego's blog

By alternatego, 13 years ago, In English
In round #85 div 2, question A using this function was very helpful
cout << strcasecmp(a,b) << endl;

Here are some more useful functions found in gnu extensions, but not in standard library
__typeof() 
#define REP(i,n) for (__typeof(n) i = 0; i < n; ++i)

__builtin_popcount(n) - counts the number of set bits in n. Example, for 10 it prints 2.

Are there anymore  gnu extensions which you find useful? And what's codeforces policy on that?
Tags gnu
  • Vote: I like it
  • 0
  • Vote: I do not like it

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

I can't believe this damn REP macro is built-in.Or is it just an example of typeof usage? Anyway, you don't need __ prefix to use it.
  • 13 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    It's an example of __typeof. 
    REP(i,10) 
    REP(i, v.size()) - Iterating over all elements of vector
    REP(i, s.size()) - Iterating over all characters of a string
    You can also write a foreach macro using __typeof() and then iterate over sets, maps etc
    • 13 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      Yes, I know its usage. Actually, there is range-based for in c++11 standard, not sure if it is supported by the codeforces g++ compiler, but it's very likely.