On 8/16/07, Leo Wandersleb <[EMAIL PROTECTED]> wrote:
>
> 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
Read boost docs. boost::tuple operators are defined in another header, i
think its tuple_operator.hpp but i'm not sure. I include it in a couple
places in my own code, just grep "boost" *.h or grep "boost" *.cpp
--
Extra cheese comes at a cost. Bradley Arsenault.
_______________________________________________
glob2-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/glob2-devel