help regarding syntax

G

Giuseppe:G:

Hi, any idea on what is this code doing:

//=================================
1 #include <boost/scoped_ptr.hpp>

....

3 typedef std::vector<std::vector<pair<size_t, size_t> > > ParamsType;

5 /*
6 *Is the following a boost shared pointer to a "ParamsType" object?
7 */
8 shared_ptr<ParamsType>& params;

....
14 params.reset(new ParamsType(m_pred_map->size()));
15 for (size_t pid = 0; pid < m_pred_map->size(); ++pid) {
16 vector<pair<size_t, size_t> >& param = (*params)[pid]; // ??
...
}
//=================================

I have problems with lines 14 & 16. First of all, is ParamsType a vector
of vectors of pairs? Then I think params is a pointer to that. Then, we
probably instantiate a new ParamsType and let params point at it. Right?

But then, what's happening in line 16?


Thanks in advance

Giuseppe
 
G

Giuseppe:G:

Anybody? please.. :) Is

vector<pair<size_t, size_t> >& param = (*params)[pid];

a kind of cast?

cheers
Giuseppe
 
J

joseph cook

Anybody? please.. :) Is

vector<pair<size_t, size_t> >& param = (*params)[pid];

a kind of cast?

cheers
Giuseppe

Giuseppe:G: said:
Hi, any idea on what is this code doing:
//=================================
1 #include <boost/scoped_ptr.hpp>

3 typedef std::vector<std::vector<pair<size_t, size_t> > > ParamsType;
5 /*
6 *Is the following a boost shared pointer to a "ParamsType" object?
7 */
8 shared_ptr<ParamsType>& params;
...
14 params.reset(new ParamsType(m_pred_map->size()));
15 for (size_t pid = 0; pid < m_pred_map->size(); ++pid) {
16       vector<pair<size_t, size_t> >& param = (*params)[pid]; // ??
    ...
}
//=================================
I have problems with lines 14 & 16. First of all, is ParamsType a vector
of vectors of pairs? Then I think params is a pointer to that. Then, we
probably instantiate a new ParamsType and let params point at it. Right?
But then, what's happening in line 16?

If you think of it as a 2D matrix of "pair" objects, then this loop is
getting each "row" of of the matrix. The term "param" in most cases
would be used as a reference, because it is easier to read/type than
repeating "(*params)[pid]" everywhere else in the loop. It is just an
alias.

hth,
Joe Cook
 
G

Giuseppe:G:

Thanks Joe! Now I get it. It's as if we're "isolating" single rows ( or
columns) and then managing them through param.

Regards
Giuseppe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top