OmaeWaMouShenDeiru's blog

By OmaeWaMouShenDeiru, 11 years ago, In English

Hello programmers,,

I read someones code a couple days earlier and i saw a piece of code using __typeof operator as a shortcut of a for loop. What is this operator and can it be used ?? Thanks :D

»
11 years ago, # |
Rev. 2   Vote: I like it +4 Vote: I do not like it

Before the C++11 standard it was a function in GNU C++, that returns type of argument. For example:


set<pair<set<int>,pair<int,vector<int> > > > because_i_can; typeof(because_i_can.begin()) it=because_i_can.begin(); // set<pair<set<int>,pair<int,vector<int>>>>::iterator

It was removed in C++11 because of auto.


set<pair<set<int>,pair<int,vector<int>>>> because_i_can; auto it=begin(because_i_can); // set<pair<set<int>,pair<int,vector<int> > > >::iterator
  • »
    »
    11 years ago, # ^ |
    Rev. 2   Vote: I like it +9 Vote: I do not like it
    that returns type of argument

    "replace" would be more appropriate word here, because typeof is not a nomral C function. it is more of a pre-compiler replacement (well, like, macros)

  • »
    »
    11 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Actually it was replaced by decltype, not auto.

  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yes i started using auto and it was more practical and easier than iterators Thank you :D

»
11 years ago, # |
  Vote: I like it 0 Vote: I do not like it

adamant seems to have the answer as to what it does. i would like to add that typeof (not __typeof, btw) is not a C/C++ operator, but a compiler extension provided by GCC (which means it does not work on some other compilers).

  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Im using VS 2013 and the syntax is __typeof But the problem is that it keeps telling me that "identifier is undefined" Do you have any explanation ??

    • »
      »
      »
      11 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      i'm not very sure about VS 2013 interface; u can ask others who use it. i use Sublime Text 2 as my editor and Ubuntu Terminal to compile and run the code.

      but i can tell u that in my template (from any of my recent submissions) i have the following line.
      #define TR(i,x) for(typeof(x.begin()) i=x.begin();i!=x.end();i++)
      here u can see that i use typeof() (i should change it to auto from now), not __typeof. this compiles and runs very well.

      • »
        »
        »
        »
        11 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I started using auto like the one you mentioned earlier. Any way auto worked just fine,and there is no need to change it into typeof. Thank you for your help :D

»
11 years ago, # |
  Vote: I like it -22 Vote: I do not like it

namedir oytyan? name bolsa gowy? wiii yatdan cykypdyr son gulerin