A
Amit
Hello.
I am having some problem organizing a set of vectors. The vectors itself,
could contain a pointer( say integer pointer) or could contain another
object MyClass.
1>So, first of all, is there anyway where I can accomodate both the vector
2>Coming to the compare_func and other things, lets assume this following
set type
set<vector<int*>, compare_func > for simplicity. Right now what I have for
the compare_func, what I have is something that isnt correct( I know that).
template <typename Cont>
struct less_vector
{
bool operator()( const Cont& c1, const Cont& c2)
{
return (c1 < c2);
}
};
and therefore I use set<vector<int*>, less_vector<vector<int*> >.
The problem as evident here is the comparison function compares the two
vector types which would do a lexicographical_compare on the pointers.
But what I really want is another comparison( and a set of comparison
functions that I could overload), which would
1>Do lexicographical compare based on the actual elements of the array that
int* in the vector points to.
2>Sort the vectors based on the addition of the elements in the array that
int* point to
3>blah blah blah...
Is there anyway of doing this ? I know it would mean sending a predicate, to
the less_vector Function Object, but I am not able to get the syntax
correct. The part
where I am confused is how do I use the iterator and the iterator_traits to
do that.
3>Last but not the least, How do I iterate over the set and through the
elements pointed to by the int* of the vector within the set.
Right now I use the for loop,
for(s1::iterator pos = s.begin(); pos != s.end(); pos++)
{
cout << "New Vector" << "\n" ;
transform((*pos).begin(), (*pos).end(), std:stream_iterator<int>(cout,
"\n"),
Dereference());
}
The Dererence just does a derefernce of the int*. For sake of simplicity, I
have assumed that the the int* in the vector points only to one integer, so
you can do *iter in the Dereference and return the value.
What I am looking for is something like a single shot transform function
iterating over the entire thing
transform(s.begin(), s.end(), std:stream_iterator<int>(cout, "\n"),
DereferenceandDisplaythevectorelemnts());
Thanks for reading and Thanks in advance for any solutions.
I am having some problem organizing a set of vectors. The vectors itself,
could contain a pointer( say integer pointer) or could contain another
object MyClass.
1>So, first of all, is there anyway where I can accomodate both the vector
Right now, I am having them as two different set dayatypes.
2>Coming to the compare_func and other things, lets assume this following
set type
set<vector<int*>, compare_func > for simplicity. Right now what I have for
the compare_func, what I have is something that isnt correct( I know that).
template <typename Cont>
struct less_vector
{
bool operator()( const Cont& c1, const Cont& c2)
{
return (c1 < c2);
}
};
and therefore I use set<vector<int*>, less_vector<vector<int*> >.
The problem as evident here is the comparison function compares the two
vector types which would do a lexicographical_compare on the pointers.
But what I really want is another comparison( and a set of comparison
functions that I could overload), which would
1>Do lexicographical compare based on the actual elements of the array that
int* in the vector points to.
2>Sort the vectors based on the addition of the elements in the array that
int* point to
3>blah blah blah...
Is there anyway of doing this ? I know it would mean sending a predicate, to
the less_vector Function Object, but I am not able to get the syntax
correct. The part
where I am confused is how do I use the iterator and the iterator_traits to
do that.
3>Last but not the least, How do I iterate over the set and through the
elements pointed to by the int* of the vector within the set.
Right now I use the for loop,
for(s1::iterator pos = s.begin(); pos != s.end(); pos++)
{
cout << "New Vector" << "\n" ;
transform((*pos).begin(), (*pos).end(), std:stream_iterator<int>(cout,
"\n"),
Dereference());
}
The Dererence just does a derefernce of the int*. For sake of simplicity, I
have assumed that the the int* in the vector points only to one integer, so
you can do *iter in the Dereference and return the value.
What I am looking for is something like a single shot transform function
iterating over the entire thing
transform(s.begin(), s.end(), std:stream_iterator<int>(cout, "\n"),
DereferenceandDisplaythevectorelemnts());
Thanks for reading and Thanks in advance for any solutions.