boost :: interprocess :: map编译器错误“无法重载”

时间:2017-06-14 20:57:17

标签: c++ boost boost-interprocess

我在尝试使用boost :: interprocess:map时遇到编译错误,我不明白错误。

声明地图及其分配器

using namespace boost::interprocess;

struct Order {
    uint64_t id = 0;
    uint64_t val = 0;
};

typedef std::pair<const uint64_t, Order> ValueType;
typedef allocator<ValueType, 
                  managed_shared_memory::segment_manager> OrderMapAllocator;
typedef map<const uint64_t, 
            Order, 
            std::less<const uint64_t>, 
            OrderMapAllocator> OrderMap;

示例用法,编译器错误指出第120行,它是下面函数的第一行:

OrderMap * _orders;

void addOrder(Order order) {
    if(_orders->find(order.id) != _orders->end()){
        /* stuff */
    } else {
        (*_orders)[order.id] = order;
    }
}

注意,我之前使用std :: map成功运行了代码,键是非const而不是const。我将密钥切换到const uint64_t,因为boost中的类型断言失败了。

获取下面无法解释的编译器错误

为简洁起见,第一个结束:

boost::container::map<Key, T, Compare, Allocator, Options>::nonconst_value_type = std::pair<const long unsigned int, Order>]’ cannot be overloaded
std::pair<iterator,bool> insert(const nonconst_value_type& x)

-

In file included from include/boost/interprocess/containers/map.hpp:23:0,
                 from src/app/SharedOrderBook.h:7,
                 from src/app/futures_feed.cpp:20:
include/boost/container/map.hpp: In instantiation of ‘class boost::container::map<const long unsigned int, Order, std::less<const long unsigned int>, boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >’:
src/app/SharedOrderBook.h:120:19:   required from here
include/boost/container/map.hpp:541:29: error: ‘std::pair<typename boost::container::container_detail::tree<Key, std::pair<const Key, T>, boost::container::container_detail::select1st<std::pair<const Key, T> >, Compare, Allocator, MapOptions>::iterator, bool> boost::container::map<Key, T, Compare, Allocator, Options>::insert(const nonconst_value_type&) [with Key = const long unsigned int; T = Order; Compare = std::less<const long unsigned int>; Allocator = boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; MapOptions = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; typename boost::container::container_detail::tree<Key, std::pair<const Key, T>, boost::container::container_detail::select1st<std::pair<const Key, T> >, Compare, Allocator, MapOptions>::iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, false>; boost::container::map<Key, T, Compare, Allocator, Options>::nonconst_value_type = std::pair<const long unsigned int, Order>]’ cannot be overloaded
    std::pair<iterator,bool> insert(const nonconst_value_type& x)
                             ^~~~~~
include/boost/container/map.hpp:530:29: error: with ‘std::pair<typename boost::container::container_detail::tree<Key, std::pair<const Key, T>, boost::container::container_detail::select1st<std::pair<const Key, T> >, Compare, Allocator, MapOptions>::iterator, bool> boost::container::map<Key, T, Compare, Allocator, Options>::insert(const value_type&) [with Key = const long unsigned int; T = Order; Compare = std::less<const long unsigned int>; Allocator = boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; MapOptions = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; typename boost::container::container_detail::tree<Key, std::pair<const Key, T>, boost::container::container_detail::select1st<std::pair<const Key, T> >, Compare, Allocator, MapOptions>::iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, false>; boost::container::map<Key, T, Compare, Allocator, Options>::value_type = std::pair<const long unsigned int, Order>]’
    std::pair<iterator,bool> insert(const value_type& x)
                             ^~~~~~
include/boost/container/map.hpp:574:29: error: ‘std::pair<typename boost::container::container_detail::tree<Key, std::pair<const Key, T>, boost::container::container_detail::select1st<std::pair<const Key, T> >, Compare, Allocator, MapOptions>::iterator, bool> boost::container::map<Key, T, Compare, Allocator, Options>::insert(boost::container::map<Key, T, Compare, Allocator, Options>::value_type&&) [with Key = const long unsigned int; T = Order; Compare = std::less<const long unsigned int>; Allocator = boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; MapOptions = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; typename boost::container::container_detail::tree<Key, std::pair<const Key, T>, boost::container::container_detail::select1st<std::pair<const Key, T> >, Compare, Allocator, MapOptions>::iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, false>; boost::container::map<Key, T, Compare, Allocator, Options>::value_type = std::pair<const long unsigned int, Order>]’ cannot be overloaded
    std::pair<iterator,bool> insert(BOOST_RV_REF(value_type) x)
                             ^~~~~~
include/boost/container/map.hpp:552:29: error: with ‘std::pair<typename boost::container::container_detail::tree<Key, std::pair<const Key, T>, boost::container::container_detail::select1st<std::pair<const Key, T> >, Compare, Allocator, MapOptions>::iterator, bool> boost::container::map<Key, T, Compare, Allocator, Options>::insert(boost::container::map<Key, T, Compare, Allocator, Options>::nonconst_value_type&&) [with Key = const long unsigned int; T = Order; Compare = std::less<const long unsigned int>; Allocator = boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; MapOptions = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; typename boost::container::container_detail::tree<Key, std::pair<const Key, T>, boost::container::container_detail::select1st<std::pair<const Key, T> >, Compare, Allocator, MapOptions>::iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, false>; boost::container::map<Key, T, Compare, Allocator, Options>::nonconst_value_type = std::pair<const long unsigned int, Order>]’
    std::pair<iterator,bool> insert(BOOST_RV_REF(nonconst_value_type) x)
                             ^~~~~~
include/boost/container/map.hpp:619:13: error: ‘boost::container::map<Key, T, Compare, Allocator, Options>::iterator boost::container::map<Key, T, Compare, Allocator, Options>::insert(boost::container::map<Key, T, Compare, Allocator, Options>::const_iterator, const nonconst_value_type&) [with Key = const long unsigned int; T = Order; Compare = std::less<const long unsigned int>; Allocator = boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; MapOptions = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; boost::container::map<Key, T, Compare, Allocator, Options>::iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, false>; boost::container::map<Key, T, Compare, Allocator, Options>::const_iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, true>; boost::container::map<Key, T, Compare, Allocator, Options>::nonconst_value_type = std::pair<const long unsigned int, Order>]’ cannot be overloaded
    iterator insert(const_iterator p, const nonconst_value_type& x)
             ^~~~~~
include/boost/container/map.hpp:586:13: error: with ‘boost::container::map<Key, T, Compare, Allocator, Options>::iterator boost::container::map<Key, T, Compare, Allocator, Options>::insert(boost::container::map<Key, T, Compare, Allocator, Options>::const_iterator, const value_type&) [with Key = const long unsigned int; T = Order; Compare = std::less<const long unsigned int>; Allocator = boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; MapOptions = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; boost::container::map<Key, T, Compare, Allocator, Options>::iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, false>; boost::container::map<Key, T, Compare, Allocator, Options>::const_iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, true>; boost::container::map<Key, T, Compare, Allocator, Options>::value_type = std::pair<const long unsigned int, Order>]’
    iterator insert(const_iterator p, const value_type& x)
             ^~~~~~
include/boost/container/map.hpp:628:13: error: ‘boost::container::map<Key, T, Compare, Allocator, Options>::iterator boost::container::map<Key, T, Compare, Allocator, Options>::insert(boost::container::map<Key, T, Compare, Allocator, Options>::const_iterator, boost::container::map<Key, T, Compare, Allocator, Options>::value_type&&) [with Key = const long unsigned int; T = Order; Compare = std::less<const long unsigned int>; Allocator = boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; MapOptions = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; boost::container::map<Key, T, Compare, Allocator, Options>::iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, false>; boost::container::map<Key, T, Compare, Allocator, Options>::const_iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, true>; boost::container::map<Key, T, Compare, Allocator, Options>::value_type = std::pair<const long unsigned int, Order>]’ cannot be overloaded
    iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
             ^~~~~~
include/boost/container/map.hpp:598:13: error: with ‘boost::container::map<Key, T, Compare, Allocator, Options>::iterator boost::container::map<Key, T, Compare, Allocator, Options>::insert(boost::container::map<Key, T, Compare, Allocator, Options>::const_iterator, boost::container::map<Key, T, Compare, Allocator, Options>::nonconst_value_type&&) [with Key = const long unsigned int; T = Order; Compare = std::less<const long unsigned int>; Allocator = boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; MapOptions = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; boost::container::map<Key, T, Compare, Allocator, Options>::iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, false>; boost::container::map<Key, T, Compare, Allocator, Options>::const_iterator = boost::container::container_detail::iterator_from_iiterator<boost::intrusive::tree_iterator<boost::intrusive::bhtraits<boost::container::container_detail::tree_node<std::pair<const long unsigned int, Order>, boost::interprocess::offset_ptr<void>, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits<boost::interprocess::offset_ptr<void>, true>, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, true>; boost::container::map<Key, T, Compare, Allocator, Options>::nonconst_value_type = std::pair<const long unsigned int, Order>]’
    iterator insert(const_iterator p, BOOST_RV_REF(nonconst_value_type) x)
             ^~~~~~
In file included from include/boost/interprocess/segment_manager.hpp:33:0,
                 from include/boost/interprocess/detail/managed_memory_impl.hpp:30,
                 from include/boost/interprocess/managed_shared_memory.hpp:25,
                 from src/app/SharedOrderBook.h:6,
                 from src/app/futures_feed.cpp:20:
include/boost/interprocess/detail/named_proxy.hpp: In instantiation of ‘void boost::interprocess::ipcdetail::CtorArgN<T, is_iterator, Args>::construct(void*, boost::interprocess::ipcdetail::false_, const boost::container::container_detail::index_tuple<IdxPack ...>&) [with int ...IdxPack = {0, 1}; T = boost::container::map<const long unsigned int, Order, std::less<const long unsigned int>, boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; bool is_iterator = false; Args = {std::less<long unsigned int>, boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0ul>, 0ul>, boost::interprocess::iset_index> >&}; boost::interprocess::ipcdetail::false_ = boost::interprocess::ipcdetail::bool_<false>]’:
include/boost/interprocess/detail/named_proxy.hpp:71:10:   required from ‘void boost::interprocess::ipcdetail::CtorArgN<T, is_iterator, Args>::construct_n(void*, std::size_t, std::size_t&) [with T = boost::container::map<const long unsigned int, Order, std::less<const long unsigned int>, boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; bool is_iterator = false; Args = {std::less<long unsigned int>, boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0ul>, 0ul>, boost::interprocess::iset_index> >&}; std::size_t = long unsigned int]’
src/app/futures_feed.cpp:170:1:   required from here
include/boost/interprocess/detail/named_proxy.hpp:83:7: error: no matching function for call to ‘boost::container::map<const long unsigned int, Order, std::less<const long unsigned int>, boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >::map(std::less<long unsigned int>, boost::interprocess::allocator<std::pair<const long unsigned int, Order>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >&)’
    {  ::new((void*)mem, boost_container_new_t())T(boost::forward<Args>(get<IdxPack>(args_))...); }

如果我摆脱了const uint64_t并使用uint64_t作为密钥,我会收到以下错误:

include/boost/container/map.hpp:150:7: error: static assertion failed: (container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value)
       BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));

0 个答案:

没有答案