I want to keep variant inside xtensor, but when I try to print the tensor the overload for operator<< is not picked up.
#include <iostream>
#include <xtensor/xarray.hpp>
#include <xtensor/xio.hpp>
#include <xtensor/xview.hpp>
#include <xtensor/xadapt.hpp>
#include <variant>
template<typename T, typename... Ts>
std::ostream &operator<<(std::ostream &os, const std::variant<T, Ts...>& v) {
std::visit([&os](auto &&arg) {
os << arg;
}, v);
return os;
}
void foo() {
xt::xtensor<std::variant<double, std::string>, 2>::shape_type shape = {1,1};
xt::xtensor<std::variant<double, std::string>, 2> ret(shape);
std::variant<double, std::string> a = 2.5;
ret.at(0, 0) =a;
std::cout << a << std::endl; //works
std::cout << ret << std::endl; //doesn`t work
}