As others have pointed out, you can visit all elements types and return the desired variant from there:
template <typename... Types> auto b2std(boost::variant<Types...> const& input) {
return boost::apply_visitor(
[](auto const& v) -> std::variant<Types...> { return v; }, input);
}
When used like this
auto x = b2std(boost::variant<int, std::string, double>{"hello world"});
Then type of x matches the expected:
static_assert(
std::is_same_v<std::variant<int, std::string, double>, decltype(x)>);
Live
See it Live On Coliru
#include <boost/variant.hpp>
#include <variant>
#include <iostream>
template <typename... Types> auto b2std(boost::variant<Types...> const& input) {
return boost::apply_visitor(
[](auto const& v) -> std::variant<Types...> { return v; }, input);
}
int main() {
auto x = b2std(boost::variant<int, std::string, double>{"hello world"});
static_assert(
std::is_same_v<std::variant<int, std::string, double>, decltype(x)>);
}