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

chenjl

  • Guest
eg.
Code: cpp
#include <iostream>
#include <map>
#include <vector>
struct Info
{
string name;
int age;
};

int main()
{
vector<Info*> vecInfos;
Info* p = new Info;
p->name = "account1";
p->age = 28;
vecInfos.push_back(p);
p = new Info;
p->name = "account2";
p->age = 17;
vecInfos.push_back(p);


vector<Info*>::iterator itVec = vecInfos.begin();
while (itVec != vecInfos.end())
{
cout << itVec->name /* at here */
<< itVec->age /* and at here */
<< endl;
}

map<string, Info*> mapInfos;
p = new Info;
p->name = "test1";
p->age = 21;
mapInfos.insert(make_pair(p->name, p));

p = new Info;
p->name = "test2";
p->age = 22;
mapInfos.insert(make_pair(p->name, p));

map<string, Info*>::iterator itMap = mapInfos.begin();
while (itMap != mapInfos.end())
{
cout << itMap->first /* at here */
cout << itMap->second->name /* at here */
}
return 0;
}
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: 5910
  • 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: 5910
  • 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: 5910
  • 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
(*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.