Connecting Tech Pros Worldwide Forums | Help | Site Map

help regarding syntax

Giuseppe:G:
Guest
 
Posts: n/a
#1: Jul 6 '08
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

Giuseppe:G:
Guest
 
Posts: n/a
#2: Jul 6 '08

re: help regarding syntax


Anybody? please.. :) Is

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

a kind of cast?

cheers
Giuseppe


Giuseppe:G: wrote:
Quote:
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
joseph cook
Guest
 
Posts: n/a
#3: Jul 7 '08

re: help regarding syntax


On Jul 6, 6:30*pm, Giuseppe:G: <lone.nt...@SPAMlibero.itwrote:
Quote:
Anybody? please.. :) Is
>
vector<pair<size_t, size_t& param = (*params)[pid];
>
a kind of cast?
>
cheers
Giuseppe
>
Giuseppe:G: wrote:
Quote:
Hi, any idea on what is this code doing:
>
Quote:
//=================================
1 #include <boost/scoped_ptr.hpp>
>
Quote:
...
>
Quote:
3 typedef std::vector<std::vector<pair<size_t, size_t ParamsType;
>
Quote:
5 /*
6 *Is the following a boost shared pointer to a "ParamsType" object?
7 */
8 shared_ptr<ParamsType>& params;
>
Quote:
...
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];// ??
* * ...
}
//=================================
>
Quote:
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?
>
Quote:
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


Giuseppe:G:
Guest
 
Posts: n/a
#4: Jul 7 '08

re: help regarding syntax


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

joseph cook wrote:
Quote:
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
>
>
Closed Thread