gpt4 book ai didi

c++ - 将 std::map 复制/插入到 boost::bimap

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:38:12 26 4
gpt4 key购买 nike

我尝试将 std::map 的元素复制到 boost::bimap 中。我无法让 std::copy 工作(boost 文档似乎表明 bimap 应该与 std::copy 兼容)。

我尝试了以下方法:

std::map<K, T> curves;

boost::bimap<boost::bimaps::set_of<K>,
boost::bimaps::multiset_of<T>> m_curves;

... // some initialisation of curves

std::copy(curves.begin(), curves.end(), std::inserter(m_curves,
m_curves.end())); // This fails

m_curves.insert(curves.begin(), curves.end()); // This fails too !

错误信息很长,开头是:

1>C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include\xutility(2266) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const std::pair<_Ty1,_Ty2>' (or there is no acceptable conversion)
1> with
1> [
1> _Ty1=const K,
1> _Ty2=std::string
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include\iterator(129): could be 'std::insert_iterator<_Container> &std::insert_iterator<_Container>::operator =(const boost::bimaps::relation::mutant_relation<TA,TB,Info,force_mutable> &)'
1> with
1> [
1> _Container=Focus::BMpCrvKeyToName,
1> TA=boost::bimaps::tags::tagged<const K,boost::bimaps::relation::member_at::left>,
1> TB=boost::bimaps::tags::tagged<const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,boost::bimaps::relation::member_at::right>,
1> Info=boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,
1> force_mutable=false
1> ]

最佳答案

双图本身与 map 签名不兼容,但左 View 是。尝试插入 m_curves.left:

m_curves.left.insert(curves.begin(), curves.end());

关于c++ - 将 std::map 复制/插入到 boost::bimap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12178067/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com