Boost logo

Boost Users :

Subject: Re: [Boost-users] [bind] [multi-index] Create type of pointer to overloaded erase method
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-09-10 12:54:39


AMDG

Peter Barker wrote:
> RecordsContainer::size_type (RecordsContainer::*erase)(unsigned int) =
> &RecordsContainer::erase;
>
> but it failed to compile. Visual Studio 2003 gives me the following
> error on the above line:
> <snip>
>

The following compiles for me with msvc 9.0

#include <boost/shared_ptr.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>

namespace bmi = boost::multi_index;

struct RecordBase {
    unsigned int getRecID() const { return(0); }
};

struct SizeAndFit {};

struct LastSizeFitRecord : RecordBase {
    const SizeAndFit& getSizeAndFit() const { return(x); }
    SizeAndFit x;
};

struct RecsByID {};
struct RecsBySizeAndFit {};

typedef boost::multi_index_container<
    boost::shared_ptr<LastSizeFitRecord>,
    bmi::indexed_by<
        bmi::ordered_unique<bmi::tag<RecsByID>,
            bmi::const_mem_fun<RecordBase,unsigned int,
                &RecordBase::getRecID> >,
        bmi::ordered_unique<bmi::tag<RecsBySizeAndFit>,
            bmi::const_mem_fun<LastSizeFitRecord,const SizeAndFit&,
                &LastSizeFitRecord::getSizeAndFit> >
>
> RecordsContainer;

int main() {
    RecordsContainer::size_type (RecordsContainer::*erase)(unsigned int) =
        &RecordsContainer::erase;
}

The parameter type is determined using call_traits, so you can see
what this is for unsigned int.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net