Related (but not the problem), I am trying to get a UPnP library to work. It appears to be targeted to Boost 1.71.0. However, my project uses Boost 1.74.0. So I thought it should be fairly easy to migrate.
But it seems that something significant changed with asio's executors in Boost 1.74.0. It's not clear to me what changed or how to migrate from 1.73.x to 1.74.0. I intend to use Boost Asio for additional parts of the project so I need to understand what is happening here.
I think I have trimmed it down to a minimal reproducible code snippet. This snippet compiles fine with Boost 1.73.0 and GCC 5.5.
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/executor.hpp>
namespace net = boost::asio;
using tcp = net::ip::tcp;
void foo(net::executor exec)
{
tcp::resolver r{exec};
}
However, when I change the library to Boost 1.74.0 I then get a compiler error that describes an issue with the executor.
The error appears to be related to the executor changes. If I try to instantiate a tcp::socket or udp::socket or even a local::stream_protocol::socket, they all result in the same error describing executors.
I did a brief search on cpplang slack. One comment thread seemed to suggest to use bind_executor. I don't know what that is, but it didn't solve the problem either. Another comment suggested that the execution_context was needed which also didn't work. There was a lot of discussion about using any_executor but that also doesn't seem to work.
So I thought maybe the release notes might include some instructions for migration.
I saw a paper P0443R13. Maybe I'll read that later but it's far too dense material to get a quick solution.
I also saw two papers P1348R0 and P1393R0 both of which are very terse but doesn't appear to be related to the problem I'm encountering.
The compiler error is described below:
source>:9:25: error: no matching function for call to 'boost::asio::ip::basic_resolver<boost::asio::ip::tcp>::basic_resolver(<brace-enclosed initializer list>)'
tcp::resolver r{exec};
^
I understand that the resolver object can't be constructed. The error goes on with several notes and related substitution failure messages
This one clearly describes that it can't convert an execution context to a resolver r-value reference. Makes sense.
/opt/compiler-explorer/libs/boost_1_74_0/boost/asio/ip/basic_resolver.hpp:141:3: note: candidate: boost::asio::ip::basic_resolver<InternetProtocol, Executor>::basic_resolver(boost::asio::ip::basic_resolver<InternetProtocol, Executor>&&) [with InternetProtocol = boost::asio::ip::tcp; Executor = boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0> > >] basic_resolver(basic_resolver&& other) ^ /opt/compiler-explorer/libs/boost_1_74_0/boost/asio/ip/basic_resolver.hpp:141:3: note: no known conversion for argument 1 from 'boost::asio::executor' to 'boost::asio::ip::basic_resolver<boost::asio::ip::tcp>&&' /opt/compiler-explorer/libs/boost_1_74_0/boost/asio/ip/basic_resolver.hpp:122:12:This one describes a template substitution failure. It appears to be related to the executor. I don't understand what the failure is.
/opt/compiler-explorer/libs/boost_1_74_0/boost/asio/ip/basic_resolver.hpp:122:12: note: candidate: template<class ExecutionContext> boost::asio::ip::basic_resolver<InternetProtocol, Executor>::basic_resolver(ExecutionContext&, typename std::enable_if<std::is_convertible<ExecutionContext&, boost::asio::execution_context&>::value>::type*) explicit basic_resolver(ExecutionContext& context, ^ /opt/compiler-explorer/libs/boost_1_74_0/boost/asio/ip/basic_resolver.hpp:122:12: note: template argument deduction/substitution failed: /opt/compiler-explorer/libs/boost_1_74_0/boost/asio/ip/basic_resolver.hpp: In substitution of 'template<class ExecutionContext> boost::asio::ip::basic_resolver<InternetProtocol, Executor>::basic_resolver(ExecutionContext&, typename std::enable_if<std::is_convertible<ExecutionContext&, boost::asio::execution_context&>::value>::type*) [with ExecutionContext = boost::asio::executor]': <source>:9:25: required from here /opt/compiler-explorer/libs/boost_1_74_0/boost/asio/ip/basic_resolver.hpp:122:12: error: no type named 'type' in 'struct std::enable_if<false, void>'This one also appears to be related to the executor but it can't convert the
boost::asio::executorto aboost::asio::execution::any_executorwith a bunch of template vomit. This is the constructor that I think should be valid but apparently is not./opt/compiler-explorer/libs/boost_1_74_0/boost/asio/ip/basic_resolver.hpp:108:12: note: candidate: boost::asio::ip::basic_resolver<InternetProtocol, Executor>::basic_resolver(const executor_type&) [with InternetProtocol = boost::asio::ip::tcp; Executor = boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0> > >; boost::asio::ip::basic_resolver<InternetProtocol, Executor>::executor_type = boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0> > >] explicit basic_resolver(const executor_type& ex) ^ /opt/compiler-explorer/libs/boost_1_74_0/boost/asio/ip/basic_resolver.hpp:108:12: note: no known conversion for argument 1 from 'boost::asio::executor' to 'const executor_type& {aka const boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0> >, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0> > >&}'
I see Asio does decribe "This new name may break existing code that directly uses the old polymorphic wrapper, executor."