Board index » cppbuilder » vectorizing pairs

vectorizing pairs


2005-07-20 12:03:35 PM
cppbuilder87
I need to sort a vector, and make an index vector which hold the original
positions of the elements. The only way I know is to make a vector of
pairs, then use sort(), and make a function to split the vecotr of pairs to
2 independent vectors again.
Of course it seem obvious that this should be a template function,
//////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename T,typename S>
vector< pair<T,S>>make_vector_pair(vector<T>t,vector<S>s)
{
pair<T,S>p;
vector< pair<T,S>>pvec;
for(int j=0;j<t.size();j++) { // or min(t.size(),s.size()) ,
whatever
p.first=t[j];
p.second=s[j];
pvec.push_back(p);
}
return pvec;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
but this does'nt compile. Help. (The for loop is probably bad STL form, I
know, but
thats not the problem.)
Thanks,
Dave
 
 

Re:vectorizing pairs

Dave D wrote:
Quote
vector< pair<T,S>>
This should be:
vector<pair<T,S>>
You need a space between the less than's in order to prevent it from
being tokenized as a>>operator.
Quote
but this does'nt compile. Help. (The for loop is probably bad STL form, I
know, but
thats not the problem.)
If that doesn't fix it, it would help if you'd let us in on what error
message(s) you're getting.
--
Gillmer J. Derge [TeamB]
 

Re:vectorizing pairs

Oh ... my ...god! This has had me stumped for months.
I can get rid of about 10 overloaded versions now!
Thanks!
Dave
"Gillmer J. Derge [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
Dave D wrote:
>vector< pair<T,S>>

This should be:

vector<pair<T,S>>

You need a space between the less than's in order to prevent it from being
tokenized as a>>operator.

>but this does'nt compile. Help. (The for loop is probably bad STL form, I
>know, but
>thats not the problem.)

If that doesn't fix it, it would help if you'd let us in on what error
message(s) you're getting.

--
Gillmer J. Derge [TeamB]
 

{smallsort}