title: ASIO UDP: class std::allocator<void> has no member named ‘construct’
body: <p>I have followed <a href="https://stackoverflow.com/questions/22965899/#22967714">this example</a> to set up an asynchronous UDP receive. But it fails on compilation:</p>
  
  <pre><code>g++ -Wall -Wconversion -Wfatal-errors -Wextra -std=c++11 test1.cpp
  </code></pre>
  
  <p>Error message:</p>
  
  <pre><code>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&lt;std::allocator&lt;_CharT&gt; &gt;::construct(std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::allocator_type&amp;, _Up*, _Args&amp;&amp; ...) [with _Up = std::promise&lt;long unsigned int&gt;; _Args = {const std::allocator_arg_t&amp;, std::allocator&lt;void&gt;}; _Tp = void; std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::allocator_type = std::allocator&lt;void&gt;]’:
  /usr/include/c++/5/bits/shared_ptr_base.h:522:39:   required from ‘std::_Sp_counted_ptr_inplace&lt;_Tp, _Alloc, _Lp&gt;::_Sp_counted_ptr_inplace(_Alloc, _Args&amp;&amp; ...) [with _Args = {const std::allocator_arg_t&amp;, std::allocator&lt;void&gt;}; _Tp = std::promise&lt;long unsigned int&gt;; _Alloc = std::allocator&lt;void&gt;; __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&lt;_Lp&gt;::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&amp;, _Args&amp;&amp; ...) [with _Tp = std::promise&lt;long unsigned int&gt;; _Alloc = std::allocator&lt;void&gt;; _Args = {const std::allocator_arg_t&amp;, std::allocator&lt;void&gt;}; __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&lt;_Tp, _Lp&gt;::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&amp;, _Args&amp;&amp; ...) [with _Alloc = std::allocator&lt;void&gt;; _Args = {const std::allocator_arg_t&amp;, std::allocator&lt;void&gt;}; _Tp = std::promise&lt;long unsigned int&gt;; __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&lt;_Tp&gt;::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&amp;, _Args&amp;&amp; ...) [with _Alloc = std::allocator&lt;void&gt;; _Args = {const std::allocator_arg_t&amp;, std::allocator&lt;void&gt;}; _Tp = std::promise&lt;long unsigned int&gt;]’
  /usr/include/c++/5/bits/shared_ptr.h:620:39:   required from ‘std::shared_ptr&lt;_Tp1&gt; std::allocate_shared(const _Alloc&amp;, _Args&amp;&amp; ...) [with _Tp = std::promise&lt;long unsigned int&gt;; _Alloc = std::allocator&lt;void&gt;; _Args = {const std::allocator_arg_t&amp;, std::allocator&lt;void&gt;}]’
  /usr/include/boost/asio/impl/use_future.hpp:39:56:   required from ‘boost::asio::detail::promise_handler&lt;T&gt;::promise_handler(boost::asio::use_future_t&lt;OtherAllocator&gt;) [with Allocator = std::allocator&lt;void&gt;; T = long unsigned int]’
  /usr/include/boost/asio/async_result.hpp:62:21:   required from ‘boost::asio::detail::async_result_init&lt;Handler, Signature&gt;::async_result_init(Handler&amp;&amp;) [with Handler = const boost::asio::use_future_t&lt;&gt;&amp;; 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&lt;typename boost::asio::handler_type&lt;WriteHandler, void(boost::system::error_code, long unsigned int)&gt;::type&gt;::type boost::asio::datagram_socket_service&lt;Protocol&gt;::async_receive_from(boost::asio::datagram_socket_service&lt;Protocol&gt;::implementation_type&amp;, const MutableBufferSequence&amp;, boost::asio::datagram_socket_service&lt;Protocol&gt;::endpoint_type&amp;, boost::asio::socket_base::message_flags, ReadHandler&amp;&amp;) [with MutableBufferSequence = boost::asio::mutable_buffers_1; ReadHandler = const boost::asio::use_future_t&lt;&gt;&amp;; Protocol = boost::asio::ip::udp; typename boost::asio::async_result&lt;typename boost::asio::handler_type&lt;WriteHandler, void(boost::system::error_code, long unsigned int)&gt;::type&gt;::type = std::future&lt;long unsigned int&gt;; boost::asio::datagram_socket_service&lt;Protocol&gt;::implementation_type = boost::asio::detail::reactive_socket_service&lt;boost::asio::ip::udp&gt;::implementation_type; boost::asio::datagram_socket_service&lt;Protocol&gt;::endpoint_type = boost::asio::ip::basic_endpoint&lt;boost::asio::ip::udp&gt;; boost::asio::socket_base::message_flags = int]’
  /usr/include/boost/asio/basic_datagram_socket.hpp:897:51:   required from ‘typename boost::asio::async_result&lt;typename boost::asio::handler_type&lt;WriteHandler, void(boost::system::error_code, long unsigned int)&gt;::type&gt;::type boost::asio::basic_datagram_socket&lt;Protocol, DatagramSocketService&gt;::async_receive_from(const MutableBufferSequence&amp;, boost::asio::basic_datagram_socket&lt;Protocol, DatagramSocketService&gt;::endpoint_type&amp;, ReadHandler&amp;&amp;) [with MutableBufferSequence = boost::asio::mutable_buffers_1; ReadHandler = const boost::asio::use_future_t&lt;&gt;&amp;; Protocol = boost::asio::ip::udp; DatagramSocketService = boost::asio::datagram_socket_service&lt;boost::asio::ip::udp&gt;; typename boost::asio::async_result&lt;typename boost::asio::handler_type&lt;WriteHandler, void(boost::system::error_code, long unsigned int)&gt;::type&gt;::type = std::future&lt;long unsigned int&gt;; boost::asio::basic_datagram_socket&lt;Protocol, DatagramSocketService&gt;::endpoint_type = boost::asio::ip::basic_endpoint&lt;boost::asio::ip::udp&gt;]’
  test1.cpp:25:28:   required from here
  /usr/include/c++/5/bits/alloc_traits.h:530:4: error: ‘using allocator_type = class std::allocator&lt;void&gt; {aka class std::allocator&lt;void&gt;}’ has no member named ‘construct’
    { __a.construct(__p, std::forward&lt;_Args&gt;(__args)...); }
      ^
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;thread&gt;
  #include &lt;iostream&gt;
  #include &lt;future&gt;
  #include &lt;boost/array.hpp&gt;
  #include &lt;boost/asio/use_future.hpp&gt;
  #include &lt;boost/asio.hpp&gt;
  
  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&lt;char, 128&gt; recv_buf;
          boost::asio::ip::udp::endpoint sender_endpoint;
          std::future&lt;std::size_t&gt; recv_length =
              mysocket.async_receive_from(
                  boost::asio::buffer(recv_buf),
                  sender_endpoint,
                  boost::asio::use_future); // &lt;&lt;&lt;&lt; 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;
  }
  </code></pre>