I'm trying to pass a std::shared_ptr<std::jthread> as a parameter in this lambda, but getting an error with this std::visit. It works fine if I leave out the second parameter in the overload.
The error can be seen here. https://coliru.stacked-crooked.com/a/95b62272fa49335d
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <variant>
template<class... Ts>
struct overload : Ts... {
using Ts::operator()...;
};
template<class... Ts>
overload(Ts...) -> overload<Ts...>;
class ObjA {
int a;
};
class ObjB {
int b;
};
int main()
{
ObjA a;
std::variant<ObjA, ObjB> v;
v = a;
int rc { 0 };// unused here
std::shared_ptr<std::jthread> sp = nullptr;
std::visit(overload {
[&rc](ObjA& objA, std::shared_ptr<std::jthread> thr) {
std::cout << "ObjA!\n";
},
[&rc](ObjB& objB, std::shared_ptr<std::jthread> thr) {
std::cout << "ObjB!\n";
}
}, v);
return 0;
}