jeudi 27 octobre 2016

Compiling boost::multi_index with std::shared_ptr with GCC

This code compiles with visual studio 2015.

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/key_extractors.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/random_access_index.hpp>

#include <memory>

namespace bmi = boost::multi_index;

class Link {};

typedef std::shared_ptr<Link> Link_Ptr;


struct ByRnd {};
struct ByPtr {};

typedef boost::multi_index_container<Link_Ptr,
    bmi::indexed_by<
        bmi::random_access<
            bmi::tag<ByRnd>
        >,
        bmi::hashed_unique<
            bmi::tag<ByPtr>,
            bmi::const_mem_fun<Link_Ptr, Link*, &Link_Ptr::get>
        >
    >
> Store;
Store store;

int main() {}

However, on Ubuntu I am using GCC 6.2 and boost 1.62. And I get the following error:

error: could not convert template argument ‘&std::__shared_ptr::get’ to ‘Link* (std::shared_ptr::*)() const’ bmi::const_mem_fun

and clang 3.8: error: non-type template argument of type 'Link (std::__shared_ptr::)() const noexcept' cannot be converted to a value of type 'Link (std::shared_ptr::)() const' bmi::const_mem_fun

If I use boost::shared_ptr instead, GCC compiles fine too.

Aucun commentaire:

Enregistrer un commentaire