With C++14, I'm using boost::variant
as a way of compile-time polymorphism:
using MyType = boost::variant<A, B>;
Both classes have a method sayHello()
. I'd like to call:
MyType obj = ...; // either A() or B()
boost::visit([](auto&& o) { o.sayHello();}, obj);
I know the static_visitor
way, but I find it cumbersome. Is there a boost::visit
like std::visit
that I'm missing? If not, why doesn't it exist?
Minimal example here.
There is, but it's called boost::apply_visitor
. Its behavior in relation to boost::variant
is the as std::visit
's to std::variant
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With