I searched to see if I find a solution to this problem but I was not able to see an answer. The problem that I’m having is while my code compiles, I don’t get intellisense
if I’m receiving a parameter (or declaring a variable) such as this with template T :
unique_ptr<vector<unique_ptr<T>>> & dataSets;
intellisense finds dataSets.get() but it does not find dataSets.get()->clear(); however, it compiles fine if I do it.
However, if it not a template, it seems to work fine.
CODE:
template <typename T>
void mtsql::MTMySQL<T>::executePrepareStatement(const string & sqlText,const unique_ptr<vector<SQLDataType>> & argList,unique_ptr<vector<unique_ptr<T>>> & dataSets)
{
dataSets.get()->clear();
unique_ptr<sql::ResultSet> rs;
for (auto iter = argList->cbegin(); iter != argList->cend() ; ++iter)
{
auto ps = this->createPreparedStatment(sqlText,args);
rs.reset(ps->execute());
dataSets.get()->insert(std::move(rs));
ps.release();
}
}
I’m new at c++11 so I may be doing extra steps or steps that may be wrong (for example, I think ps.release() is not needed… my point was to delete it, but since is a smart point)
Thanks for the help!
EDIT 1:
Thanks to the help, my code looks much nicer and without possible leakage.
Thank you!
dataSets->clear();
for (auto iter = argList->cbegin(); iter != argList->cend() ; ++iter)
{
auto ps = this->createPreparedStatment(sqlText,args);
dataSets->push_back(std::move(rs));
}
C++ is not a simple language to parse and semantic. Therefore you can’t expect IntelliSense to work perfectly with complicated types.
As for your code, you could simplify the code to do:
(And if
dataSetsis really aunique_ptr<vector<unique_ptr<T>>>I think you should usedataSets->push_backinstead ofinsert.)Edit: MSVC 2010 does not support range-based for. It does support lambdas though: