尝试在REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
jupyterhub/jupyterhub latest 3726912b8cfc 5 months ago 811.5 MB
<none> <none> 7cdb3c49d61f 2 years ago 4.766 GB
中存储boost::recursive_variant_type
对象时遇到问题。
让我们假设以下代码并假定包含所有必需的头文件:
header.h
boost::unordered_map
source.cpp
// [...]
namespace example_namespace
{
using my_custom_class_t = boost::make_recursive_variant<
bool,
double,
std::string,
std::vector<boost::recursive_variant_>,
boost::unordered_map<std::string, boost::recursive_variant_>
>::type;
using my_custom_map = boost::unordered_map<std::string, my_custom_class_t>;
std::vector<my_custom_map> stack_;
}
只要我不使用// [...]
namespace example_namespace
{
std::pair<std::string, my_custom_class_t> my_pair { "hi", my_custom_class_t(true) };
std::string s = my_pair.first;
my_custom_class_t t = my_pair.second;
// here comes the bad part
my_custom_map my_map;
my_map.emplace(s, t); // <- this is where compilation aborts
stack_.emplace_back(my_map);
}
类(“最糟糕的地方”行上方的所有内容),代码就可以正常编译,但是一旦我要将递归变量类型存储在地图中(例如boost::unordered_map<std::string, my_custom_class_t>
),编译器将引发以下错误:
my_map
是否有可能由于某些原因而无法将递归变体(例如就内存分配而言)存储在1>c:\...\include\xhash(31): error C2440: 'type cast': cannot convert from 'const _Kty' to 'size_t'
1> with
1> [
1> _Kty=std::string
1> ]
1>c:\...\include\xhash(31): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>d:\...\boost\container_hash\extensions.hpp(358): note: see reference to function template instantiation 'size_t stdext::hash_value<T>(const _Kty &)' being compiled
1> with
1> [
1> T=std::string,
1> _Kty=std::string
1> ]
1>d:\...\boost\container_hash\extensions.hpp(357): note: while compiling class template member function 'size_t boost::hash<K>::operator ()(const T &) const'
1> with
1> [
1> K=std::string,
1> T=std::string
1> ]
1>d:\...\boost\unordered\detail\implementation.hpp(2623): note: see reference to function template instantiation 'size_t boost::hash<K>::operator ()(const T &) const' being compiled
1> with
1> [
1> K=std::string,
1> T=std::string
1> ]
1>d:\...\boost\type_traits\is_nothrow_move_assignable.hpp(29): note: see reference to class template instantiation 'boost::hash<K>' being compiled
1> with
1> [
1> K=std::string
1> ]
1>d:\...\boost\unordered\detail\implementation.hpp(2739): note: see reference to class template instantiation 'boost::is_nothrow_move_assignable<H>' being compiled
1> with
1> [
1> H=boost::hash<std::string>
1> ]
1>d:\...\boost\unordered\detail\implementation.hpp(2902): note: see reference to class template instantiation 'boost::unordered::detail::functions<boost::hash<K>,std::equal_to<K>>' being compiled
1> with
1> [
1> K=std::string
1> ]
1>d:\...\boost\unordered\unordered_map.hpp(60): note: see reference to class template instantiation 'boost::unordered::detail::table<boost::unordered::detail::map<A,K,T,H,P>>' being compiled
1> with
1> [
1> A=std::allocator<std::pair<const std::string,example_namespace::my_custom_class_t>>,
1> K=std::string,
1> T=example_namespace::my_custom_class_t,
1> H=boost::hash<std::string>,
1> P=std::equal_to<std::string>
1> ]
1>d:\...\my_model.cpp(47): note: see reference to class template instantiation 'boost::unordered::unordered_map<std::string,example_namespace::my_custom_class_t,boost::hash<K>,std::equal_to<K>,std::allocator<std::pair<const K,T>>>' being compiled
1> with
1> [
1> K=std::string,
1> T=example_namespace::my_custom_class_t
1> ]
s中?