glob2-devel
[Top][All Lists]
Advanced

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

[glob2-devel] need help with stl/boost


From: Leo Wandersleb
Subject: [glob2-devel] need help with stl/boost
Date: Fri, 17 Aug 2007 01:35:17 +0200
User-agent: Icedove 1.5.0.12 (X11/20070731)

hi list

Bradley told me to try and use boost::tuple and i ended with the following code:

void Building::subscribeToBringRessourcesStep()
{
        Unit * u=NULL;
        int value=INT_MIN;
        static int thisTurnsResource=0;
        //choose a resource we assign a glob to fetch this turn.
        while ( neededRessource(thisTurnsResource) <= 0)
                thisTurnsResource=(thisTurnsResource+1)%MAX_RESSOURCES;
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
        std::list<boost::tuple<int, Unit *> > sortableUnitList;
        for(int n=0; n<1024; ++n)
        {
                u=owner->myUnits[n];
                value=Score(u,thisTurnsResource);
                if (value > INT_MIN)
                        sortableUnitList.push_back(boost::make_tuple(value,u));
        }
        sortableUnitList.sort();//<============here is the problem (1365)
        std::list<boost::tuple<int, Unit *> >::iterator it = 
sortableUnitList.end();
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        if (it->get<0>() > INT_MIN)
        {
                Unit * chosen=it->get<1>();
                if (verbose) printf(" unit %d choosen.\n", chosen->gid);
                chosen->destinationPurpose=thisTurnsResource;
fprintf(logFile, "[%d] bdp1 destinationPurpose=%d\n", chosen->gid, chosen->destinationPurpose);
                unitsWorking.push_back(chosen);
                chosen->subscriptionSuccess(this, false);
                updateCallLists();//if we did anything, update call lists
        }
}


but then i get:

g++ -o src/Building.o -c -g -DHAVE_CONFIG_H -D_GNU_SOURCE=1 -D_REENTRANT -Ilibgag/include -I. -I/usr/include/SDL src/Building.cpp /usr/include/c++/4.1.3/bits/list.tcc: In member function 'void std::list<_Tp, _Alloc>::merge(std::list<_Tp, _Alloc>&) [with _Tp = boost::tuples::tuple<int, Unit*, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, _Alloc = std::allocator<boost::tuples::tuple<int, Unit*, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >]': /usr/include/c++/4.1.3/bits/list.tcc:257: instantiated from 'void std::list<_Tp, _Alloc>::sort() [with _Tp = boost::tuples::tuple<int, Unit*, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, _Alloc = std::allocator<boost::tuples::tuple<int, Unit*, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >]'
src/Building.cpp:1365:   instantiated from here
/usr/include/c++/4.1.3/bits/list.tcc:222: error: no match for 'operator<' in '__first2. std::_List_iterator<_Tp>::operator* [with _Tp = boost::tuples::tuple<int, Unit*, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>]() < __first1. std::_List_iterator<_Tp>::operator* [with _Tp = boost::tuples::tuple<int, Unit*, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>]()'
scons: *** [src/Building.o] Error 1

what basically complains about a missing operator<. do i really have to define one? i understood bradley that he said no and i thought std::sort would take int::operator< for both int and the pointer.

if i have to define operator<, how would that be done?

greetings and thanx in advance,

Leo Wandersleb




reply via email to

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