asio icon indicating copy to clipboard operation
asio copied to clipboard

Type Deduction with Channels

Open vkhristenko opened this issue 3 years ago • 0 comments

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

  1. Is my understanding correct here?
  2. Is that something of a downside to the baseline channel class template or i'm just doing something wrong?

Thanks!

VK

vkhristenko avatar Jun 22 '22 19:06 vkhristenko