Problem regarding QPtrList::findRef
Hi guys,
I'm working on a project where I need to remove Qt libraries and use C++ STL.
I need to replace QPtrList::findRef defined in Qt with C++ STL alternative . But unable to get any solution.
For example
I have used STL's find(InputIterator first, InputIterator last, const T& value) to replace QPtrList::find. The code can be seen as below
Defined in Qt3
Code:
if( -1 == steps.find( s ) )
Alternative in C++ STL
Code:
StepListIterator sIt = find( steps.begin(), steps.end(), s);
if (sIt == steps.end())
{
//not found perform relevant operation
}
Similar way I need to replace Qt's QPtrList::findRef with an C++ STL alternative.
Please help me
Waiting for your reply
Thankx in advance
Problem regarding C++ STL
Hi guys,
I'm working on a project where I need to remove Qt libraries and use C++ STL.
I need to replace QPtrList::findRef defined in Qt with C++ STL alternative . But unable to get any solution.
For example
I have used STL's find(InputIterator first, InputIterator last, const T& value) to replace QPtrList::find. The code can be seen as below
Defined in Qt3
Qt Code:
Code:
if( -1 == steps.find( s ) )
Alternative STL Code:
Code:
StepListIterator sIt = find( steps.begin(), steps.end(), s);
if (sIt == steps.end())
{
//not found perform relevant operation
}
Similar way I need to replace Qt's QPtrList::findRef with an C++ STL alternative.
Please help me
This is really improtant to me
Waiting for your reply
Thankx in advance
Re: Problem regarding C++ STL
What is "s"? If "s" is a pointer, then the implementation you provided is the implementation of findRef and not Find.
Re: Problem regarding C++ STL
Hi, thankx for your reply
Here are the declarations given
in Qt
Code:
typedef QList<SynStep> SynStepList;
typedef QListIterator<SynStep> StepListIterator;
SynStep* s; //where SynStep is a class defined by me
class StepList : public SynStepList
{
};
StepList steps;
if( -1 == steps.find( s ) )
in STL
Code:
typedef std::vector<SynStep*> SynStepList;
typedef std::vector<SynStep*>::iterator StepListIterator;
SynStep* s; //where SynStep is a class defined by me
class StepList : public SynStepList
{
};
StepList steps;
StepListIterator sIt = find( steps.begin(), steps.end(), s);
if (sIt == steps.end())
{
//not found perform relevant operation
}
Ok if that is the implementation for FindRef than can you please tell me how can I
implement Find....
Re: Problem regarding C++ STL
But these declarations are from Qt4 and in the first post you gave Qt3 code.
QPtrList::find compares items referenced by pointers, findRef compares pointers directly, therefore if you want to compare items, you have to convince STL to compare items. I doubt it is directly possible so you'll probably have to subclass or at least create a custom compare functor and tell find() to use it.
Re: Problem regarding C++ STL
There is no difference between find() and findRef() if you have a vector of pointers.
Re: Problem regarding C++ STL
Threads merged.
Please don't ask the same question in different section.
Re: Problem regarding C++ STL
Quote:
Originally Posted by
jacek
There is no difference between find() and findRef() if you have a vector of pointers.
Of course there is.
Diffrenent pointers can point to different objects that have same value.
Re: Problem regarding C++ STL
Quote:
Originally Posted by
bood
Of course there is.
Diffrenent pointers can point to different objects that have same value.
But still, if the value is a pointer, there is no difference, since find() doesn't dereference pointers.
Re: Problem regarding C++ STL
Quote:
Originally Posted by
jacek
But still, if the value is a pointer, there is no difference, since find() doesn't dereference pointers.
I guess that for Qt3 with QPtrList it might make a difference. Of course STL doesn't support dedicated lists for pointers, so to port the same behaviour to STL, one has to provide a custom compare functor.
Re: Problem regarding C++ STL
Quote:
Originally Posted by
wysota
I guess that for Qt3 with QPtrList it might make a difference. Of course STL doesn't support dedicated lists for pointers, so to port the same behaviour to STL, one has to provide a custom compare functor.
Can you please visualize with an example??