Author Topic: When I use std::map or std::vector iterator,it can not remind...  (Read 2453 times)

Offline chenjl

  • Single posting newcomer
  • *
  • Posts: 1
eg.
Code: C++
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. struct Info
  5. {
  6.         string name;
  7.         int age;
  8. };
  9.  
  10. int main()
  11. {
  12.         vector<Info*> vecInfos;
  13.         Info* p = new Info;
  14.         p->name = "account1";
  15.         p->age = 28;
  16.         vecInfos.push_back(p); 
  17.         p = new Info;
  18.         p->name = "account2";
  19.         p->age = 17;
  20.         vecInfos.push_back(p);
  21.        
  22.        
  23.         vector<Info*>::iterator itVec = vecInfos.begin();
  24.         while (itVec != vecInfos.end())
  25.         {
  26.                 cout << itVec->name                     /* at here      */
  27.                         << itVec->age                   /* and at here  */
  28.                         << endl;
  29.         }
  30.        
  31.         map<string, Info*> mapInfos;
  32.         p = new Info;
  33.         p->name = "test1";
  34.         p->age = 21;
  35.         mapInfos.insert(make_pair(p->name, p));
  36.        
  37.         p = new Info;
  38.         p->name = "test2";
  39.         p->age = 22;
  40.         mapInfos.insert(make_pair(p->name, p));
  41.        
  42.         map<string, Info*>::iterator itMap = mapInfos.begin();
  43.         while (itMap != mapInfos.end())
  44.         {
  45.                 cout << itMap->first                    /* at here      */
  46.                 cout << itMap->second->name     /* at here      */
  47.         }
  48.         return 0;
  49. }
  50.  
the codeCompletion can't display 'first','second',and the Members of struct Info.
If there are a lot of members for struct or class;
I'll feel Coding difficult;
« Last Edit: April 22, 2015, 11:08:09 am by MortenMacFly »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 4909
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: When I use std::map or std::vector iterator,it can not remind...
« Reply #1 on: May 03, 2015, 04:10:50 pm »
This is a known bug of our CC, it can't handle the template related code very well.
Currently, you can use the clang based code completion plugin. Or help us by supplying patches ;)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline jat1

  • Single posting newcomer
  • *
  • Posts: 5
Re: When I use std::map or std::vector iterator,it can not remind...
« Reply #2 on: May 24, 2015, 02:02:46 am »
Is anyone currently working on improving the template related code? If not, I'll work on it and come up with a solution for this issue.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 4909
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: When I use std::map or std::vector iterator,it can not remind...
« Reply #3 on: May 24, 2015, 03:06:33 am »
Is anyone currently working on improving the template related code? If not, I'll work on it and come up with a solution for this issue.
Hi, jat1. I think currently no one is working on the template related part of the parser and the codecompletion. It was two or three years ago that someone like blueshake, me, loaden worked on that parts. It is quite complex as I know, so if any question, ask here. Thanks.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline padget

  • Single posting newcomer
  • *
  • Posts: 2
Re: When I use std::map or std::vector iterator,it can not remind...
« Reply #4 on: May 28, 2015, 08:22:25 pm »
Indeed, with the new standart (11 and 14), the template is better than before. The code completion for template is very important for me (I use exclusively template :D).
 jat1, Thanks in advance if you work on that subject !

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 4909
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: When I use std::map or std::vector iterator,it can not remind...
« Reply #5 on: June 19, 2015, 04:16:27 pm »
Good news: with revision 10339, I commit jat1's great patch to handle template related code completion(see the test file added in this revision). Many thanks to Jat1!!!

To handle the iterator related code completion, we may need to improve the parser on how to parse a statement.
Code: [Select]
(*it).|      code suggestion here

Now, we need some operator precedence parser. (currently, we can only handle some pattern like AAA::BBB().CCC). In the above statement, we may have three steps:
1. solve the "it" -> result1
2, solve the operator * of result1 -> result2
3, list all the children of result2 -> result3

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline jat1

  • Single posting newcomer
  • *
  • Posts: 5
Re: When I use std::map or std::vector iterator,it can not remind...
« Reply #6 on: June 19, 2015, 06:16:46 pm »
Thanks ollydbg. This issue as well as code refactoring are my next projects. I'll start looking into these.