提示在 boost 中的行为与在标准库中的行为不同?
Hints behave differently with boost than with standard library?
我正在尝试使用提示插入 boost::flat_map
,但明显的语法无法编译,即使当我使用提示插入 std::map
时它确实可以编译。我是否漏掉了一些明显的东西?
#include <boost/container/flat_map.hpp>
#include <map>
int main() {
std::map<int, int> map;
map.emplace_hint(map.begin(), 0, 0); // compiles fine
boost::container::flat_map<int, int> flat_map;
flat_map.insert_or_assign(flat_map.begin(), 0, 0); // does not compile fine
return 0;
}
编译错误为:
g++ -I. -I../boost_1_65_1 -Wall -O3 -Wsign-compare -Wno-strict-aliasing -Wno-parentheses -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -std=c++14 -g -ggdb -c -o main.o main.cpp
In file included from main.cpp:1:0:
../boost_1_65_1/boost/container/flat_map.hpp: In instantiation of ‘boost::container::flat_map<Key, T, Compare, Allocator>::iterator boost::container::flat_map<Key, T, Compare, Allocator>::insert_or_assign(boost::container::flat_map<Key, T, Compare, Allocator>::const_iterator, boost::container::flat_map<Key, T, Compare, Allocator>::key_type&&, M&&) [with M = int; Key = int; T = int; Compare = std::less<int>; Allocator = boost::container::new_allocator<std::pair<int, int> >; boost::container::flat_map<Key, T, Compare, Allocator>::iterator = boost::container::container_detail::vec_iterator<std::pair<int, int>*, false>; boost::container::flat_map<Key, T, Compare, Allocator>::const_iterator = boost::container::container_detail::vec_iterator<std::pair<int, int>*, true>; boost::container::flat_map<Key, T, Compare, Allocator>::key_type = int]’:
main.cpp:9:53: required from here
../boost_1_65_1/boost/container/flat_map.hpp:771:10: error: could not convert ‘boost::container::container_detail::force_copy(const S&) [with D = std::pair<boost::container::container_detail::vec_iterator<std::pair<int, int>*, false>, bool>; S = std::pair<boost::container::container_detail::vec_iterator<boost::container::container_detail::pair<int, int>*, false>, bool>]()’ from ‘std::pair<boost::container::container_detail::vec_iterator<std::pair<int, int>*, false>, bool>’ to ‘boost::container::flat_map<int, int>::iterator {aka boost::container::container_detail::vec_iterator<std::pair<int, int>*, false>}’
);
^
<builtin>: recipe for target 'main.o' failed
make: *** [main.o] Error 1
这是一个known bug that was fixed in the 1.70 release。
我正在尝试使用提示插入 boost::flat_map
,但明显的语法无法编译,即使当我使用提示插入 std::map
时它确实可以编译。我是否漏掉了一些明显的东西?
#include <boost/container/flat_map.hpp>
#include <map>
int main() {
std::map<int, int> map;
map.emplace_hint(map.begin(), 0, 0); // compiles fine
boost::container::flat_map<int, int> flat_map;
flat_map.insert_or_assign(flat_map.begin(), 0, 0); // does not compile fine
return 0;
}
编译错误为:
g++ -I. -I../boost_1_65_1 -Wall -O3 -Wsign-compare -Wno-strict-aliasing -Wno-parentheses -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -std=c++14 -g -ggdb -c -o main.o main.cpp
In file included from main.cpp:1:0:
../boost_1_65_1/boost/container/flat_map.hpp: In instantiation of ‘boost::container::flat_map<Key, T, Compare, Allocator>::iterator boost::container::flat_map<Key, T, Compare, Allocator>::insert_or_assign(boost::container::flat_map<Key, T, Compare, Allocator>::const_iterator, boost::container::flat_map<Key, T, Compare, Allocator>::key_type&&, M&&) [with M = int; Key = int; T = int; Compare = std::less<int>; Allocator = boost::container::new_allocator<std::pair<int, int> >; boost::container::flat_map<Key, T, Compare, Allocator>::iterator = boost::container::container_detail::vec_iterator<std::pair<int, int>*, false>; boost::container::flat_map<Key, T, Compare, Allocator>::const_iterator = boost::container::container_detail::vec_iterator<std::pair<int, int>*, true>; boost::container::flat_map<Key, T, Compare, Allocator>::key_type = int]’:
main.cpp:9:53: required from here
../boost_1_65_1/boost/container/flat_map.hpp:771:10: error: could not convert ‘boost::container::container_detail::force_copy(const S&) [with D = std::pair<boost::container::container_detail::vec_iterator<std::pair<int, int>*, false>, bool>; S = std::pair<boost::container::container_detail::vec_iterator<boost::container::container_detail::pair<int, int>*, false>, bool>]()’ from ‘std::pair<boost::container::container_detail::vec_iterator<std::pair<int, int>*, false>, bool>’ to ‘boost::container::flat_map<int, int>::iterator {aka boost::container::container_detail::vec_iterator<std::pair<int, int>*, false>}’
);
^
<builtin>: recipe for target 'main.o' failed
make: *** [main.o] Error 1
这是一个known bug that was fixed in the 1.70 release。