Boost logo

Boost Users :

Subject: Re: [Boost-users] [Multi-index] : code fail to compile with VS2010 and boost 1.46.1. Proposed workaround
From: Mathieu Peyréga (mathieu.peyrega_at_[hidden])
Date: 2011-05-02 08:08:06


Here is an example of the described behaviour
Here, it does not compile with non modified composite_key.hpp file, and
do compile with modified file.

Regards,

Mathieu Peyréga

-----------------------------
test_multi_index.cpp
-----------------------------
#include <string>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/tag.hpp>
#include <boost/multi_index/indexed_by.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/composite_key.hpp>

using namespace boost;
using namespace boost::multi_index;

class GPS_Station
{
public:
    GPS_Station(void);
    GPS_Station(GPS_Station const& station);
    GPS_Station& operator=(GPS_Station const& station);
    ~GPS_Station(void);

    unsigned long m_Id;
    std::string m_Name;
    std::string m_DomeNumber;
    double m_Epoch;
    double m_X_ECEF;
    double m_Y_ECEF;
    double m_Z_ECEF;
};

class CTestMultiIndex
{
public:
       // Tags pour l'utilisation du multi-index container de Boost en
mode "Tag"
    typedef composite_key<GPS_Station,
                          member<GPS_Station,unsigned
long,&GPS_Station::m_Id>,
                         
member<GPS_Station,double,&GPS_Station::m_Epoch> > by_id_and_epoch;

    typedef composite_key<GPS_Station,
                          member<GPS_Station,unsigned
long,&GPS_Station::m_Id>,
                         
member<GPS_Station,double,&GPS_Station::m_Epoch> > by_id_and_epoch;

    typedef composite_key<GPS_Station,
                         
member<GPS_Station,std::string,&GPS_Station::m_Name>,
                         
member<GPS_Station,double,&GPS_Station::m_Epoch> > by_name_and_epoch;

    typedef composite_key<GPS_Station,
                         
member<GPS_Station,std::string,&GPS_Station::m_DomeNumber>,
                         
member<GPS_Station,double,&GPS_Station::m_Epoch> > by_domenumber_and_epoch;

    typedef composite_key<GPS_Station,
                          member<GPS_Station,double,&GPS_Station::m_Epoch>,
                          member<GPS_Station,unsigned
long,&GPS_Station::m_Id> > by_epoch_and_id;

    typedef composite_key<GPS_Station,
                          member<GPS_Station,double,&GPS_Station::m_Epoch>,
                         
member<GPS_Station,std::string,&GPS_Station::m_Name> > by_epoch_and_name;

    typedef composite_key<GPS_Station,
                          member<GPS_Station,double,&GPS_Station::m_Epoch>,
                         
member<GPS_Station,std::string,&GPS_Station::m_DomeNumber> >
by_epoch_and_domenumber;

    typedef multi_index_container<GPS_Station,
                                 
indexed_by<ordered_non_unique<by_id_and_epoch>,
                                           
 ordered_non_unique<by_name_and_epoch>,
                                           
 ordered_non_unique<by_domenumber_and_epoch>,
                                           
 ordered_unique<by_epoch_and_id>,
                                           
 ordered_unique<by_epoch_and_name>,
                                           
 ordered_unique<by_epoch_and_domenumber> >
> DataSetType;

    typedef nth_index<DataSetType,0>::type dataset_by_id_and_epoch;
    typedef nth_index<DataSetType,1>::type dataset_by_name_and_epoch;
    typedef nth_index<DataSetType,2>::type dataset_by_domenumber_and_epoch;
    typedef nth_index<DataSetType,3>::type dataset_by_epoch_and_id;
    typedef nth_index<DataSetType,4>::type dataset_by_epoch_and_name;
    typedef nth_index<DataSetType,5>::type dataset_by_epoch_and_domenumber;

    void fail_to_compile(DataSetType& dataset, std::string const&
stationname, std::string const& prefix);

}; // class CTestMultiIndex

void CTestMultiIndex::fail_to_compile(DataSetType& dataset, std::string
const& stationname, std::string const& prefix)
{
    const dataset_by_name_and_epoch &datasetbynameandepoch =
get<1>(dataset);

    std::pair<dataset_by_name_and_epoch::iterator,
dataset_by_name_and_epoch::iterator> range =
datasetbynameandepoch.equal_range(stationname);
}


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