- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用Boost,我正在尝试 emplace()
一个键/值对到 boost::container::map
。该值需要构造函数的多个参数。据我所知,我需要使用 piecewise_construct
并在 tuples
中传递构造函数参数。这适用于 std::map<K,V>
,但我无法使用 boost::container::map<K,V>
让它工作closest Boost doc我可以找到节目 boost::unordered_multimap<K,V>
,但不是简单的 map<K,V>
.
#include <map>
#include <boost/tuple/tuple.hpp>
#include <boost/container/map.hpp>
#include <boost/unordered_set.hpp>
class A {
public:
/**/ A( int ) { }
bool operator<( const A & ) const { return false; }
} ;
class B {
public:
/**/ B( int, const char * ) { }
} ;
int
main( int, char ** )
{
A a( 100 );
B b( 200, "foo" );
std::map<A,B> mgood;
mgood.emplace( std::piecewise_construct,
std::make_tuple( 100 ),
std::make_tuple( 200, "Hello" ) );
#if 1
boost::container::map<A,B> mbad;
mbad.emplace( boost::unordered::piecewise_construct,
boost::make_tuple( 300 ),
boost::make_tuple( 400, "World" ) );
#endif
}
g++-4.9.2 错误消息令人费解(无论如何对我来说):
make -k tst g++ -DBOOST_LOG_DYN_LINK -g -std=c++11 -c -o tst.o tst.cc In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp: In instantiation of âstatic void boost::container::allocator_traits::priv_construct(boost::move_detail::false_type, Allocator&, T*, Args&& ...) [with T = boost::container::container_detail::pair; Args = {const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Allocator = boost::container::new_allocator, void*, (boost::container::tree_type_enum)0u, true> >; boost::move_detail::false_type = boost::move_detail::integral_constant]â: /usr/local/include/boost/container/allocator_traits.hpp:353:86:
required from âstatic void boost::container::allocator_traits::construct(Allocator&, T*, Args&& ...) [with T = boost::container::container_detail::pair; Args = {const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Allocator = boost::container::new_allocator, void*, (boost::container::tree_type_enum)0u, true> >]â /usr/local/include/boost/container/detail/node_alloc_holder.hpp:167:81: required from âboost::container::container_detail::node_alloc_holder::NodePtr boost::container::container_detail::node_alloc_holder::create_node(Args&& ...) [with Args = {const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Allocator = boost::container::new_allocator >; ICont = boost::intrusive::rbtree_impl, void*, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, void, boost::container::value_to_node_compare, void*, (boost::container::tree_type_enum)0u, true>, boost::intrusive::tree_value_compare, std::less, boost::container::container_detail::select1st >, long unsigned int, true, void>; boost::container::container_detail::node_alloc_holder::NodePtr = boost::container::container_detail::tree_node, void*, (boost::container::tree_type_enum)0u, true>]â /usr/local/include/boost/container/detail/tree.hpp:922:94: required from âstd::pair, Options:: tree_type, Options:: optimize_size>::type::iterator, false>, bool> boost::container::container_detail::tree::emplace_unique(Args&& ...) [with Args = {const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Key = A; T = std::pair; KeyOfValue = boost::container::container_detail::select1st >; Compare = std::less; Allocator = boost::container::new_allocator >; Options = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; typename boost::container::container_detail::intrusive_tree_type, Options:: tree_type, Options:: optimize_size>::type::iterator = boost::intrusive::tree_iterator, void*, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>]â /usr/local/include/boost/container/map.hpp:665:72:
required from âstd::pair, boost::container::container_detail::select1st >, Compare, Allocator, MapOptions>::iterator, bool> boost::container::map::emplace(Args&& ...) [with Args = {const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple}; Key = A; T = B; Compare = std::less; Allocator = boost::container::new_allocator >; MapOptions = boost::container::tree_opt<(boost::container::tree_type_enum)0u, true>; typename boost::container::container_detail::tree, boost::container::container_detail::select1st >, Compare, Allocator, MapOptions>::iterator = boost::container::container_detail::iterator_from_iiterator, void*, (boost::container::tree_type_enum)0u, true>, boost::intrusive::rbtree_node_traits, (boost::intrusive::link_mode_type)0u, boost::intrusive::dft_tag, 3u>, false>, false>]â tst.cc:90:53: required from here /usr/local/include/boost/container/allocator_traits.hpp:408:10: error: no matching function for call to âboost::container::container_detail::pair::pair(const boost::unordered::piecewise_construct_t&, boost::tuples::tuple, boost::tuples::tuple)â { ::new((void)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: candidates are: In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:146:4: note: template boost::container::container_detail::pair::pair(std::pair<_U1, _U2>&&) pair(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) ^ /usr/local/include/boost/container/detail/pair.hpp:146:4: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: types âstd::pair<_T1, _T2>â and âconst boost::unordered::piecewise_construct_tâ have incompatible cv-qualifiers { ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:141:4: note: boost::container::container_detail::pair::pair(std::pair<_T1, _T2>&&) [with T1 = A; T2 = B] pair(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) ^ /usr/local/include/boost/container/detail/pair.hpp:141:4: note: candidate expects 1 argument, 3 provided /usr/local/include/boost/container/detail/pair.hpp:137:4: note: template boost::container::container_detail::pair::pair(const std::pair<_U1, _U2>&) pair(const std::pair& p) ^ /usr/local/include/boost/container/detail/pair.hpp:137:4: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: âconst boost::unordered::piecewise_construct_tâ is not derived from âconst std::pair<_T1, _T2>â { ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:132:4: note: boost::container::container_detail::pair::pair(const std::pair<_T1, _T2>&) [with T1 = A; T2 = B] pair(const std::pair& x) ^ /usr/local/include/boost/container/detail/pair.hpp:132:4: note: candidate expects 1 argument, 3 provided /usr/local/include/boost/container/detail/pair.hpp:126:4: note: template boost::container::container_detail::pair::pair(U&&, V&&) pair(BOOST_FWD_REF(U) u, BOOST_FWD_REF(V) v) ^ /usr/local/include/boost/container/detail/pair.hpp:126:4: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: candidate expects 2 arguments, 3 provided { ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:120:4: note: boost::container::container_detail::pair::pair(const T1&, const T2&) [with T1 = A; T2 = B] pair(const T1 &t1, const T2 &t2) ^ /usr/local/include/boost/container/detail/pair.hpp:120:4: note: candidate expects 2 arguments, 3 provided /usr/local/include/boost/container/detail/pair.hpp:115:4: note: template boost::container::container_detail::pair::pair(boost::container::container_detail::pair&&) pair(BOOST_RV_REF_BEG pair BOOST_RV_REF_END p) ^ /usr/local/include/boost/container/detail/pair.hpp:115:4: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: types âboost::container::container_detail::pairâ and âconst boost::unordered::piecewise_construct_tâ have incompatible cv-qualifiers { ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:110:4: note: template boost::container::container_detail::pair::pair(const boost::container::container_detail::pair&) pair(const pair &p) ^ /usr/local/include/boost/container/detail/pair.hpp:110:4: note: template argument deduction/substitution failed: In file included from /usr/local/include/boost/container/detail/tree.hpp:25:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/allocator_traits.hpp:408:10: note: âconst boost::unordered::piecewise_construct_tâ is not derived from âconst boost::container::container_detail::pairâ { ::new((void*)p, boost_container_new_t()) T(::boost::forward(args)...); } ^ In file included from /usr/local/include/boost/container/detail/tree.hpp:36:0, from /usr/local/include/boost/container/map.hpp:30, from tst.cc:59: /usr/local/include/boost/container/detail/pair.hpp:105:4: note: boost::container::container_detail::pair::pair(boost::container::container_detail::pair&&) [with T1 = A; T2 = B] pair(BOOST_RV_REF(pair) p) ^ /usr/local/include/boost/container/detail/pair.hpp:105:4: note: candidate expects 1 argument, 3 provided /usr/local/include/boost/container/detail/pair.hpp:100:4: note: boost::container::container_detail::pair::pair(const boost::container::container_detail::pair&) [with T1 = A; T2 = B] pair(const pair& x) ^ /usr/local/include/boost/container/detail/pair.hpp:100:4: note: candidate expects 1 argument, 3 provided /usr/local/include/boost/container/detail/pair.hpp:95:4: note: boost::container::container_detail::pair::pair() [with T1 = A; T2 = B] pair() ^ /usr/local/include/boost/container/detail/pair.hpp:95:4: note: candidate expects 0 arguments, 3 provided : recipe for target 'tst.o' failed make: *** [tst.o] Error 1 make: Target 'tst' not remade because of errors.编译在 4 月 2 日星期六 17:11:28 异常退出,代码为 2
你能给我指出一个有用的方向吗? (我不想混合
boost
和std
容器;应该可以将emplace
放入boost::container::map
中,对吧?)
最佳答案
似乎 piecewise_construct
没有为 boost::pair
实现(这是 boost::container::map
条目的类型) )。 参见 .../boost/container/detail/pair.hpp:151
:
//piecewise_construct missing
//template <class U, class V> pair(pair<U, V>&& p);
//template <class... Args1, class... Args2>
// pair(piecewise_construct_t, tuple<Args1...> first_args,
// tuple<Args2...> second_args);
我想这个的实现是很困难的。
关于c++ - boost::container::map::emplace() 的piecewise_construct 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36380214/
大家好,所有rdf/sparql开发人员。这是一个困扰了我一段时间的问题,但是自从发布rdf和sparql规范以来,似乎没人能准确回答这个问题。 为了说明这种情况,RDF定义了几种方法来处理资源的多值
我在我的应用程序中使用 Bootstrap ,现在遇到了一个大问题。问题是 .container 元素在 1360 px 的屏幕上具有 274px 的左右边距,这是相当大的。结果,一切看起来都被挤到了
我在删除Docker容器时遇到问题-当我使用前一个命令时,它不起作用(Docker报告了容器ID,但没有删除它)。后者起作用了。据我所知,Docker语法是相同的: C:\Users\user>doc
std::back_inserter 仅适用于带有 push_back 的容器,因此它不适用于 set 和 map 另一方面,std::inserter 适用于所有容器类型。那么我可以一直使用 std
我正在开发 Spring Boot + Redis 示例。在此示例中,我开发了一些自定义方法,这些方法基于 RoleName 提取详细信息。对于以下方法 userRepository.findByRo
在我的 Swift 应用程序中尝试实现 Google Tag Manager v5 时,我遇到了以下警告,这给我带来了一些麻烦: GoogleTagManager warning: No defaul
安装了新的 Laravel 8 项目并在加载第一个实例时,出现以下错误。这很奇怪,因为我把它放在一边,后来从 Laravel 5.8 -> 6 升级了另一个项目(工作正常),当我去检查网站时遇到了类似
我有以下测试代码,它只创建一个空的 hashmap (containers.map) 并在之后填充它: hashtable = containers.Map('KeyType','char','Va
我对它们之间的差异有一点了解,但是拥有专家意见将是很棒的。 Container-Optimized Google Compute Engine Images Google Container Engi
我会模板化一个函数,以便将它与 vector、set 或任何其他 STL 容器(具有正确的 API...)一起使用 我的函数当前原型(prototype)是: vector> f ( const ve
我正在尝试匹配包含和不包含某些字符串的 Pandas DataFrame 的行。例如: import pandas df = pandas.Series(['ab1', 'ab2', 'b2', 'c
我需要在一个非常庞大的全文索引数据库中找到一些文本,但我不知道在我的查询术语变体中使用什么更好。 我看过一些使用的例子 SELECT Foo.Bar FROM Foo WHERE
Traceback (most recent call last): File "demo.py", line 132, in `result = find_strawberry(image
我正在尝试编写一个函数,其中一列包含一个子字符串并且不包含另一个子字符串。 在下面的示例中,如果我的行包含“某些项目”并且不包含“开销”,我希望我的函数返回 1。 row| example strin
我试图在文本文件中 append 包含给定字符串集的任何行。我创建了一个测试文件,在其中放置了这些字符串之一。我的代码应该将文本文件中包含这些字符串之一的任何行打印在与文本文件中的上一行相同的行上。这
我正在尝试学习如何使用 std.container 中可用的各种容器结构,但我无法理解如何执行以下操作: 1) 如何创建一个空容器?例如,假设我有一个用户定义的类 Foo,并且想要创建一个应该包含 F
$contains: [1, 2] // @> [1, 2] (PG array contains operator) $contained: [1, 2] // <@ [1,
我看到 CSS 中使用了这种“div#container”语法,我想知道它是如何工作的。有人有它的资源吗? 最佳答案 除了作为上面提到的唯一引用之外,ID 还增加了特异性(我强烈建议您阅读这篇文章或一
我有一个生成很多子对象的应用程序,每个子对象都与一些全局应用程序对象一起工作,例如在全局应用程序注册表中注册自己,更新应用程序统计信息等。 应用程序应该如何将访问这些全局对象的能力传递给 child
Here is a Sencha fiddle of my tab panel setup.按钮被动态添加到 vbox 选项卡容器中,该容器是 hbox 布局设置的一部分。选项卡容器的宽度由 flex
我是一名优秀的程序员,十分优秀!