C++ boost::循环缓冲区<;独特的_ptr<;T>>;::set_capacity()无法生成
我试图在我的代码中使用C++ boost::循环缓冲区<;独特的_ptr<;T>>;::set_capacity()无法生成,c++,boost,C++,Boost,我试图在我的代码中使用boost::circular\u buffer,如下所示: class EventRegistry { public: EventRegistry() { pendingEvents_.set_capacity(MAX_PENDING_EVENTS); } private: boost::circular_buffer<boost::movelib::unique_ptr<EventData>> p
boost::circular\u buffer
,如下所示:
class EventRegistry
{
public:
EventRegistry()
{
pendingEvents_.set_capacity(MAX_PENDING_EVENTS);
}
private:
boost::circular_buffer<boost::movelib::unique_ptr<EventData>> pendingEvents_;
}
然后它编译得很好。有什么线索吗
更新:这是完整的输出(抱歉长度太长)
boost/build/binaries/include/boost/container/allocator\u traits.hpp:408:51:错误:没有用于初始化'boost::movelib::unique\u ptr'的匹配构造函数
{::new((void*)p,boost_container_new_t())t(::boost::forward(args);}
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boost/build/binaries/include/boost/container/allocator_traits.hpp:353:28:注意:在函数模板专门化的实例化中,此处请求“boost::container::allocator_traits::priv_construct”
分配器特性::priv构造(标志、a、p、::boost::forward(args)…);
^
boost/build/binaries/include/boost/circular\u buffer/details.hpp:439:56:注意:在函数模板专门化的实例化中,这里请求了“boost::container::allocator\u traits::construct”
boost::container::allocator\u traits::construct(a,boost::addressof(*dest),*first);
^
boost/build/binaries/include/boost/circular\u buffer/details.hpp:460:12:注意:在函数模板专门化的实例化中,此处请求“boost::cb\u details::uninitialized\u copy”
返回未初始化的拷贝(第一个、最后一个、目标、a);
^
boost/build/binaries/include/boost/circular\u buffer/details.hpp:470:12:注意:在函数模板专门化的实例化中,如果这里请求了“boost::cb\u details::uninitialized\u move\u,则执行”
如果没有异常impl(first、last、dest、a、tag_t()),则返回未初始化的移动;
^
boost/build/binaries/include/boost/circular\u buffer/base.hpp:880:29:注意:在函数模板专门化的实例化中,此处请求“boost::cb\u details::uninitialized\u move\u if\u noexcept”
cb_详细信息::未初始化的_移动_如果没有异常(b,b+(标准::min)(新的_容量,大小()),buff,m_alloc),
^
…/events/event_registry.cc:22:18:注意:在成员函数“boost::circular_buffer::set_capacity”的实例化中,此处请求
pendingEvents设置容量(每个时间窗口的最大事件数);
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:360:35:注意:候选构造函数不可行:第一个参数('const boost::movelib::unique_ptr')将丢失常量限定符
增强可移动但不可复制(唯一)
^
boost/build/binaries/include/boost/move/core.hpp:242:46:注意:从宏“boost\u MOVABLE\u BUT\u NOT\u COPYABLE”展开
推进、移动、执行、不复制、复制或分配(类型)\
^
boost/build/binaries/include/boost/move/core.hpp:35:7:注意:从宏“boost\u move\u IMPL\u NO\u COPY\u CTOR\u OR\u ASSIGN”展开
类型(类型&)\
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:401:20:注意:候选构造函数不可行:没有已知的第一个参数从“const boost::movelib::unique_ptr”到“bmupd::nullptr_type”(又名“int(boost::move_upd::bool_conversion:::*)())的转换
BOOST_constepr unique_ptr(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type))BOOST_NOEXCEPT
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:527:4:注意:候选构造函数不可行:没有已知的从第一个参数的“const boost::movelib::unique_ptr”到“::boost::rv&”的转换
唯一(增压)增压(增压)RV(增压)REF(唯一)增压(增压)无例外
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:424:13:注意:忽略候选模板:替换失败[with Pointer=boost::movelib::unique_ptr]:boost::move_upd::enable_ptr中没有名为“type”的类型
显式唯一\u ptr(指针p
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:462:4:注意:候选构造函数模板不可行:至少需要2个参数,但提供了1个
唯一\u ptr(指针p,推进\u移动\u种子(删除器\u参数\u类型1)d1
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:500:4:注意:候选构造函数模板不可行:至少需要2个参数,但提供了1个
唯一\u ptr(指针p,推进\u移动\u种子(删除器\u参数\u类型2)d2
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:547:4:注意:忽略候选模板:实例化将按值采用自己的类类型
唯一的(增压器)增压器(增压器)增压器(增压器)增压器(增压器)增压器(增压器)增压器(增压器)增压器(增压器)增压器(增压器)增压器(增压器)增压器(增压器)增压器(增压器)增压器(增压器)增压器
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:390:20:注意:候选构造函数不可行:需要0个参数,但提供了1个
BOOST_CONSTEXPR unique_ptr()BOOST_NOEXCEPT
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:475:4:注意:候选构造函数不可行:需要2个参数,但提供了1个
唯一的\u ptr(BOOST\u MOVE\u DOC0PTR(bmupd::nullptr\u type)、BOOST\u MOVE\u SEEDOC(deleter\u arg\u type1)d1)BOOST\u NOEXCEPT
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:513:4:注意:候选构造函数不可行:需要2个参数,但提供了1个
唯一(BOOST_-ptr(BOOST_-MOVE_-DOC0PTR)(bmupd::nullptr_-type)、BOOST_-MOVE_-SEEDOC(deleter_-arg_-type2)d2)BOOST_-NOEXCEPT
^
生成1个错误。
下面的编译很好
#include <boost/circular_buffer.hpp>
#include <boost/move/unique_ptr.hpp>
class EventRegistry
{
public:
EventRegistry()
{
pendingEvents_.set_capacity(10);
}
private:
boost::circular_buffer<boost::movelib::unique_ptr<int>> pendingEvents_;
};
int main()
{
return 0;
}
#包括
#包括
类事件注册表
{
公众:
EventRegistry()
{
挂起事件设置容量(10);
}
私人:
循环缓冲区挂起事件;
};
int main()
{
返回0;
}
请注意,我将int
放在了EventData
的位置。
您的问题可能与EventData
有关
(我没有足够的观点来评论…)
编辑:哦,检查一下
EventData
有什么类型的构造函数!你有默认的构造函数吗???你包含的错误消息部分没有包含错误,它只是包含了错误
EventRegistry()
: pendingEvents_(MAX_PENDING_EVENTS)
boost/build/binaries/include/boost/container/allocator_traits.hpp:408:51: error: no matching constructor for initialization of 'boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >'
{ ::new((void*)p, boost_container_new_t()) T(::boost::forward<Args>(args)...); }
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boost/build/binaries/include/boost/container/allocator_traits.hpp:353:28: note: in instantiation of function template specialization 'boost::container::allocator_traits<std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > >::priv_construct<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >, boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > >' requested here
allocator_traits::priv_construct(flag, a, p, ::boost::forward<Args>(args)...);
^
boost/build/binaries/include/boost/circular_buffer/details.hpp:439:56: note: in instantiation of function template specialization 'boost::container::allocator_traits<std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > >::construct<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >, boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > >' requested here
boost::container::allocator_traits<Alloc>::construct(a, boost::addressof(*dest), *first);
^
boost/build/binaries/include/boost/circular_buffer/details.hpp:460:12: note: in instantiation of function template specialization 'boost::cb_details::uninitialized_copy<boost::cb_details::iterator<boost::circular_buffer<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >, std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > >, boost::cb_details::nonconst_traits<boost::container::allocator_traits<std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > > > >, boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > *, std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > >' requested here
return uninitialized_copy(first, last, dest, a);
^
boost/build/binaries/include/boost/circular_buffer/details.hpp:470:12: note: in instantiation of function template specialization 'boost::cb_details::uninitialized_move_if_noexcept_impl<boost::cb_details::iterator<boost::circular_buffer<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >, std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > >, boost::cb_details::nonconst_traits<boost::container::allocator_traits<std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > > > >, boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > *, std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > >' requested here
return uninitialized_move_if_noexcept_impl(first, last, dest, a, tag_t());
^
boost/build/binaries/include/boost/circular_buffer/base.hpp:880:29: note: in instantiation of function template specialization 'boost::cb_details::uninitialized_move_if_noexcept<boost::cb_details::iterator<boost::circular_buffer<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >, std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > >, boost::cb_details::nonconst_traits<boost::container::allocator_traits<std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > > > >, boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > *, std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > >' requested here
cb_details::uninitialized_move_if_noexcept(b, b + (std::min)(new_capacity, size()), buff, m_alloc),
^
.../events/event_registry.cc:22:18: note: in instantiation of member function 'boost::circular_buffer<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >, std::allocator<boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> > > >::set_capacity' requested here
pendingEvents_.set_capacity(MAX_EVENTS_PER_TIMEWINDOW);
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:360:35: note: candidate constructor not viable: 1st argument ('const boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >') would lose const qualifier
BOOST_MOVABLE_BUT_NOT_COPYABLE(unique_ptr)
^
boost/build/binaries/include/boost/move/core.hpp:242:46: note: expanded from macro 'BOOST_MOVABLE_BUT_NOT_COPYABLE'
BOOST_MOVE_IMPL_NO_COPY_CTOR_OR_ASSIGN(TYPE)\
^
boost/build/binaries/include/boost/move/core.hpp:35:7: note: expanded from macro 'BOOST_MOVE_IMPL_NO_COPY_CTOR_OR_ASSIGN'
TYPE(TYPE &);\
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:401:20: note: candidate constructor not viable: no known conversion from 'const boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >' to 'bmupd::nullptr_type' (aka 'int (boost::move_upd::bool_conversion::*)()') for 1st argument
BOOST_CONSTEXPR unique_ptr(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) BOOST_NOEXCEPT
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:527:4: note: candidate constructor not viable: no known conversion from 'const boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >' to '::boost::rv<unique_ptr<EventData, default_delete<EventData> > > &' for 1st argument
unique_ptr(BOOST_RV_REF(unique_ptr) u) BOOST_NOEXCEPT
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:424:13: note: candidate template ignored: substitution failure [with Pointer = boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >]: no type named 'type' in 'boost::move_upd::enable_up_ptr<appd::agent::EventData, boost::movelib::unique_ptr<appd::agent::EventData, boost::movelib::default_delete<appd::agent::EventData> >, appd::agent::EventData *, boost::move_upmu::nat>'
explicit unique_ptr(Pointer p
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:462:4: note: candidate constructor template not viable: requires at least 2 arguments, but 1 was provided
unique_ptr(Pointer p, BOOST_MOVE_SEEDOC(deleter_arg_type1) d1
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:500:4: note: candidate constructor template not viable: requires at least 2 arguments, but 1 was provided
unique_ptr(Pointer p, BOOST_MOVE_SEEDOC(deleter_arg_type2) d2
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:547:4: note: candidate template ignored: instantiation would take its own class type by value
unique_ptr( BOOST_RV_REF_BEG_IF_CXX11 unique_ptr<U, E> BOOST_RV_REF_END_IF_CXX11 u
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:390:20: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
BOOST_CONSTEXPR unique_ptr() BOOST_NOEXCEPT
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:475:4: note: candidate constructor not viable: requires 2 arguments, but 1 was provided
unique_ptr(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), BOOST_MOVE_SEEDOC(deleter_arg_type1) d1) BOOST_NOEXCEPT
^
boost/build/binaries/include/boost/move/unique_ptr.hpp:513:4: note: candidate constructor not viable: requires 2 arguments, but 1 was provided
unique_ptr(BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), BOOST_MOVE_SEEDOC(deleter_arg_type2) d2) BOOST_NOEXCEPT
^
1 error generated.
#include <boost/circular_buffer.hpp>
#include <boost/move/unique_ptr.hpp>
class EventRegistry
{
public:
EventRegistry()
{
pendingEvents_.set_capacity(10);
}
private:
boost::circular_buffer<boost::movelib::unique_ptr<int>> pendingEvents_;
};
int main()
{
return 0;
}