bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gcc 3.2 - sort vector that contains objects with predicate


From: Nikko
Subject: gcc 3.2 - sort vector that contains objects with predicate
Date: Fri, 11 Oct 2002 18:08:20 +0200

Hi,
I think this is a bug :
To have a sort with predicate working on a vector<MyClass>, I had to
transorm everything to pointers: vector<MyClass*> (although I know it is not
standard, it worked before change under VC++).

Below are the error messages I had before changes (sorry they're in French,
but even when you're French it's ununderstandable).

After all my debug wandering, I *think* :
. sort works on vector of objects without predicate (using object's operator
<)
. sort works on vector of pointers with any predicate, either default < or a
use defined function "predicate(Pointer1, Pointer2)."
. sort does not on vector of objects with predicate which is not < on . No
matter if the predicate takes reference parameters or value parameters.

Best,

Nikko



SOURCE CODE

    //  NamespaceRepository repTemp; FT 11Oct2002 PB GCC -> store pointers
in vector instead
    NamespaceRepository* pRepTemp = NULL;
    const int iSchemaListLength = pIdomSchemaList->getLength();

    for(i=0; i<iSchemaListLength; ++i) {
        DOMNode* pIdomNode = pIdomSchemaList->item(i);
        if( pIdomNode->getNodeType() != DOMNode::ELEMENT_NODE)   continue;
  DOMElement* pIdomSchema = static_cast<DOMElement*>(pIdomNode);

        EwString16 sSchemaIndex =
pIdomSchema->getAttribute(EwString16("schemaID").getBuffer());
        pRepTemp = new NamespaceRepository;
        pRepTemp->m_nSchemaIndex = sSchemaIndex.getAsInt32();
        pRepTemp->m_sURI =
pIdomSchema->getAttribute(EwString16("targetNamespace").getBuffer());
//         repTemp.m_nSchemaIndex = sSchemaIndex.getAsInt32();
//         repTemp.m_sURI =
pIdomSchema->getAttribute(EwString16("targetNamespace").getBuffer());
//      m_Namespaces.push_back(repTemp);

        m_Namespaces.push_back(pRepTemp);
    }

    sort(m_Namespaces.begin(), m_Namespaces.end(), sortNamespaceRepository);
....

Predicate definition (after correction)
bool sortNamespaceRepository(EwSchemaRepository::NamespaceRepository* A,
                             EwSchemaRepository::NamespaceRepository* B)
{
    return A->m_sURI < B->m_sURI;
}







ERROR MESSAGES

Dans le fichier inclus à partir de
/usr/include/c++/3.2/bits/stl_algo.h:2147:

/usr/include/c++/3.2/bits/stl_algo.h:

Dans function « const _Tp& std::__median(const _Tp&, const _Tp&, const

_Tp&, _Compare) [with _Tp = EwSchemaRepository::NamespaceRepository,
_Compare = bool (*)(EwSchemaRepository::NamespaceRepository&,
EwSchemaRepository::NamespaceRepository&)] »:

/usr/include/c++/3.2/bits/stl_construct.h:78: instancié à partir de «void
std::__introsort_loop(_RandomAccessIter, _RandomAccessIter, _Size,_Compare)
[with _RandomAccessIter
=__gnu_cxx::__normal_iterator<EwSchemaRepository::NamespaceRepository*,std::
vector<EwSchemaRepository::NamespaceRepository,std::allocator<EwSchemaReposi
tory::NamespaceRepository> > >, _Size =

int, _Compare = bool
(*)(EwSchemaRepository::NamespaceRepository&,EwSchemaRepository::NamespaceRe
pository&)] »

/usr/include/c++/3.2/bits/stl_algo.h:2209: instancié à partir de «

void std::sort(_RandomAccessIter, _RandomAccessIter, _Compare)
[with_RandomAccessIter
=__gnu_cxx::__normal_iterator<EwSchemaRepository::NamespaceRepository*,std::
vector<EwSchemaRepository::NamespaceRepository,std::allocator<EwSchemaReposi
tory::NamespaceRepository> > >, _Compare =

bool
(*)(EwSchemaRepository::NamespaceRepository&,EwSchemaRepository::NamespaceRe
pository&)] »../../src/EwSchemaRepository.cpp:154: instancié à partir d'ici
/usr/include/c++/3.2/bits/stl_algo.h:124: ne peut convertir « __a » vers«
EwSchemaRepository::NamespaceRepository& »

/usr/include/c++/3.2/bits/stl_algo.h:125: ne peut convertir « __b » vers
«  EwSchemaRepository::NamespaceRepository& »

/usr/include/c++/3.2/bits/stl_algo.h:127: ne peut convertir « __a » vers
«  EwSchemaRepository::NamespaceRepository& »

/usr/include/c++/3.2/bits/stl_algo.h:131: ne peut convertir « __a » vers «
EwSchemaRepository::NamespaceRepository& »

/usr/include/c++/3.2/bits/stl_algo.h:133: ne peut convertir « __b » vers« Ew
SchemaRepository::NamespaceRepository& »

../../src/EwSeqNode.h: Dans constructor « EwSeqNode::EwSeqNode(const
IEwModelGroup*, IEwNode*) »:






reply via email to

[Prev in Thread] Current Thread [Next in Thread]