asio
asio copied to clipboard
Type Deduction with Channels
Hello,
Below is the code snippet. problem description is below. boost 1.78 from conan central. gcc11
#include <string>
#include <boost/asio.hpp>
#include <boost/asio/experimental/channel.hpp>
//#define USE_TYPE_ALIAS
#ifndef USE_TYPE_ALIAS
template<typename T>
struct Channel : public boost::asio::experimental::channel<void(boost::system::error_code, T)> {
using boost::asio::experimental::channel<void(boost::system::error_code, T)>::channel;};
#else
template<typename T>
using Channel = boost::asio::experimental::channel<void(boost::system::error_code, T)>;
#endif
template<
template<typename...> typename Variant,
typename... Ts
>
void foo(std::shared_ptr<Channel<Variant<Ts...>>> v1) {}
void Test0() {
auto ctx = boost::asio::io_context{};
auto v1 = std::make_shared<Channel<std::variant<int, double, std::string>>>(ctx, 10);
foo(v1);
}
int main() {
Test0();
return 0;
}
This might be more of a c++ ignorance on my part. When trying to compile this with -DUSE_TYPE_ALIAS, I see
note: candidate template ignored: couldn't infer template argument 'Variant'
I think this is because of trying to use type deduction in non-deduced context, namely
channel<void(error_code, T)> which has a signature of a function call.
The problem is that i can not clearly see if my understanding is correct or not. e.g. checking here: https://en.cppreference.com/w/cpp/language/template_argument_deduction
- Is my understanding correct here?
- Is that something of a downside to the baseline
channelclass template or i'm just doing something wrong?
Thanks!
VK