ASIO UDP:std::allocator<void> 类没有名为“construct”的成员
Posted
技术标签:
【中文标题】ASIO UDP:std::allocator<void> 类没有名为“construct”的成员【英文标题】:ASIO UDP: class std::allocator<void> has no member named ‘construct’ 【发布时间】:2017-09-12 02:17:47 【问题描述】:我已关注this example 设置异步 UDP 接收。但编译失败:
g++ -Wall -Wconversion -Wfatal-errors -Wextra -std=c++11 test1.cpp
错误信息:
In file included from /usr/include/c++/5/ext/alloc_traits.h:36:0,
from /usr/include/c++/5/bits/basic_string.h:40,
from /usr/include/c++/5/string:52,
from /usr/include/c++/5/stdexcept:39,
from /usr/include/c++/5/array:38,
from /usr/include/c++/5/tuple:39,
from /usr/include/c++/5/functional:55,
from /usr/include/c++/5/thread:39,
from test1.cpp:1:
/usr/include/c++/5/bits/alloc_traits.h: In instantiation of ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = std::promise<long unsigned int>; _Args = const std::allocator_arg_t&, std::allocator<void>; _Tp = void; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<void>]’:
/usr/include/c++/5/bits/shared_ptr_base.h:522:39: required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = const std::allocator_arg_t&, std::allocator<void>; _Tp = std::promise<long unsigned int>; _Alloc = std::allocator<void>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:617:4: required from ‘std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = std::promise<long unsigned int>; _Alloc = std::allocator<void>; _Args = const std::allocator_arg_t&, std::allocator<void>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:1097:35: required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<void>; _Args = const std::allocator_arg_t&, std::allocator<void>; _Tp = std::promise<long unsigned int>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr.h:319:64: required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<void>; _Args = const std::allocator_arg_t&, std::allocator<void>; _Tp = std::promise<long unsigned int>]’
/usr/include/c++/5/bits/shared_ptr.h:620:39: required from ‘std::shared_ptr<_Tp1> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = std::promise<long unsigned int>; _Alloc = std::allocator<void>; _Args = const std::allocator_arg_t&, std::allocator<void>]’
/usr/include/boost/asio/impl/use_future.hpp:39:56: required from ‘boost::asio::detail::promise_handler<T>::promise_handler(boost::asio::use_future_t<OtherAllocator>) [with Allocator = std::allocator<void>; T = long unsigned int]’
/usr/include/boost/asio/async_result.hpp:62:21: required from ‘boost::asio::detail::async_result_init<Handler, Signature>::async_result_init(Handler&&) [with Handler = const boost::asio::use_future_t<>&; Signature = void(boost::system::error_code, long unsigned int)]’
/usr/include/boost/asio/datagram_socket_service.hpp:410:51: required from ‘typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::datagram_socket_service<Protocol>::async_receive_from(boost::asio::datagram_socket_service<Protocol>::implementation_type&, const MutableBufferSequence&, boost::asio::datagram_socket_service<Protocol>::endpoint_type&, boost::asio::socket_base::message_flags, ReadHandler&&) [with MutableBufferSequence = boost::asio::mutable_buffers_1; ReadHandler = const boost::asio::use_future_t<>&; Protocol = boost::asio::ip::udp; typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type = std::future<long unsigned int>; boost::asio::datagram_socket_service<Protocol>::implementation_type = boost::asio::detail::reactive_socket_service<boost::asio::ip::udp>::implementation_type; boost::asio::datagram_socket_service<Protocol>::endpoint_type = boost::asio::ip::basic_endpoint<boost::asio::ip::udp>; boost::asio::socket_base::message_flags = int]’
/usr/include/boost/asio/basic_datagram_socket.hpp:897:51: required from ‘typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::basic_datagram_socket<Protocol, DatagramSocketService>::async_receive_from(const MutableBufferSequence&, boost::asio::basic_datagram_socket<Protocol, DatagramSocketService>::endpoint_type&, ReadHandler&&) [with MutableBufferSequence = boost::asio::mutable_buffers_1; ReadHandler = const boost::asio::use_future_t<>&; Protocol = boost::asio::ip::udp; DatagramSocketService = boost::asio::datagram_socket_service<boost::asio::ip::udp>; typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type = std::future<long unsigned int>; boost::asio::basic_datagram_socket<Protocol, DatagramSocketService>::endpoint_type = boost::asio::ip::basic_endpoint<boost::asio::ip::udp>]’
test1.cpp:25:28: required from here
/usr/include/c++/5/bits/alloc_traits.h:530:4: error: ‘using allocator_type = class std::allocator<void> aka class std::allocator<void>’ has no member named ‘construct’
__a.construct(__p, std::forward<_Args>(__args)...);
^
代码:
#include <thread>
#include <iostream>
#include <future>
#include <boost/array.hpp>
#include <boost/asio/use_future.hpp>
#include <boost/asio.hpp>
int main()
boost::asio::io_service ioserv;
boost::asio::ip::udp::endpoint ep(boost::asio::ip::udp::v4(),(ushort)1414);
boost::asio::ip::udp::socket mysocket(ioserv,ep);
boost::asio::socket_base::reuse_address option(true);
mysocket.set_option(option);
boost::asio::ip::udp::endpoint sender_ep;
while(1)
std::array<char, 128> recv_buf;
boost::asio::ip::udp::endpoint sender_endpoint;
std::future<std::size_t> recv_length =
mysocket.async_receive_from(
boost::asio::buffer(recv_buf),
sender_endpoint,
boost::asio::use_future); // <<<< line 25: error
// Do other things here while the receive completes.
std::cout.write(
recv_buf.data(),
recv_length.get()); // Blocks until receive is complete.
return 0;
【问题讨论】:
什么(增强)版本?这里很好wandbox.org/permlink/bfl1vg2Cr4xmOyr5 它是Boost version: 1.58.0
。它也会在魔杖盒中产生错误。如何保存在魔杖盒中?
【参考方案1】:
看起来此错误已修复:
https://github.com/chriskohlhoff/asio/commit/503b8bb172240dfd3cf2b986799165c223c02a57看起来它进入了 boost 1.60
【讨论】:
非常感谢。顺便说一句,如何保存在魔杖盒中?我无法获得永久链接。 我使用Share
按钮
我找不到共享按钮。应该登录吗?
使用Run
后出现
这是一个不错的工具。非常感谢。以上是关于ASIO UDP:std::allocator<void> 类没有名为“construct”的成员的主要内容,如果未能解决你的问题,请参考以下文章
g++ 编译错误:std::ctype<char>、std::__detail、std::allocator<Taquart
对“std::vector<int, std::allocator<int>>”类型空指针的引用绑定
使用 std::count_if() 时出现错误“没有从 'std::vector<double, std::allocator<double> >' 到 'double *'