这个简单的测试似乎与MSVC2015编译器有问题,但我不确定为什么
#include <boost\container\flat_map.hpp>
TEST_METHOD(TestMap) {
// Map declaration
boost::container::flat_map<std::string, float> map2;
// This works
map2.insert(std::make_pair<std::string, float>("foo", 1.0F));
// This errors
map2.insert(std::make_pair("foo", 1.0F));
// This (my preferred solution) also errors with same error as previous line
map2.insert({"foo", 1.0F});
// This works fine but is less efficient so I don't want to do this
map2["foo"] = 1.0F;
}
错误是
unittest1.cpp(54): error C2668: 'boost::container::flat_map<std::string,float,std::less<Key>,boost::container::new_allocator<std::pair<std::string,float>>>::insert': ambiguous call to overloaded function
1> with
1> [
1> Key=std::string
1> ]
1> h:\users\mushfaque.cradle\documents\cpp\include\boost\container\flat_map.hpp(847): note: could be 'void boost::container::flat_map<std::string,float,std::less<Key>,boost::container::new_allocator<std::pair<std::string,float>>>::insert(std::initializer_list<std::pair<std::string,float>>)'
1> with
1> [
1> Key=std::string
1> ]
1> h:\users\mushfaque.cradle\documents\cpp\include\boost\container\flat_map.hpp(752): note: or 'std::pair<boost::container::container_detail::vec_iterator<Pointer,false>,bool> boost::container::flat_map<std::string,float,std::less<Key>,boost::container::new_allocator<std::pair<std::string,float>>>::insert(boost::container::container_detail::pair<Key,T> &&)'
1> with
1> [
1> Pointer=std::pair<std::string,float> *,
1> Key=std::string,
1> T=float
1> ]
1> h:\users\mushfaque.cradle\documents\cpp\include\boost\container\flat_map.hpp(737): note: or 'std::pair<boost::container::container_detail::vec_iterator<Pointer,false>,bool> boost::container::flat_map<std::string,float,std::less<Key>,boost::container::new_allocator<std::pair<std::string,float>>>::insert(std::pair<std::string,float> &&)'
1> with
1> [
1> Pointer=std::pair<std::string,float> *,
1> Key=std::string
1> ]
1> h:\users\mushfaque.cradle\documents\cpp\include\boost\container\flat_map.hpp(722): note: or 'std::pair<boost::container::container_detail::vec_iterator<Pointer,false>,bool> boost::container::flat_map<std::string,float,std::less<Key>,boost::container::new_allocator<std::pair<std::string,float>>>::insert(const std::pair<std::string,float> &)'
1> with
1> [
1> Pointer=std::pair<std::string,float> *,
1> Key=std::string
1> ]
我不明白为什么类型演绎不起作用,我必须每次都明确说明。
答案 0 :(得分:3)
问题是make_pair("Foo", 1.0f)
会返回std::pair<const char*, float>
,std::pair<std::string, float>
不是flat_map
,而是可以转换为。{/ p>
同时,
insert
&#39; movable_value_type&&
有movable_value_type
的非标准额外重载,其中boost::container::container_detail::pair<std::string, float>
是std::pair<const char*, float>
,显然,它也可以用// create a new taxonomy
register_taxonomy(
'Category',
'projects',
array(
'labels' => array(
//'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
'name' => __('Skills'),
'singular_name' => __('skills'),
'edit_item' => __('Edit Skill'),
'update_item' => __('Update Skill'),
'new_item_name' => __('New Skill Name'),
'all_items' => __('All Skill Name'),
'add_new_item' => __('Add New Skill'),
'search_items' => __('Seacrh Skill Name'),
'popular_items' => __('Popular Skill'),
'separate_items_with_comments' => __('Separate Items With Comments'),
'add_or_remove_items' => __('Add Or Remove Items'),
'choose_from_most_used' => __('Choose From Most Used'),
),
'public' => TRUE,
'rewrite' => array(
'slug' => 'skills',
'with_front' => TRUE
),
'hierarchical' => TRUE,
)
);
构建。
所有用户定义的转换都同样好,编译器不知道要选哪一个,所以它会抱怨。