I try to store a reference to a std::vector
consisting of std::variant
.
I can create a const std::variant<T>&
to a element of a vector
, but I struggle to store the reference to the whole vector. I guess that the answer is related to this post c++ variant class member stored by reference but I am not able to apply it to my situation.
#include <vector>
#include <variant>
using MType = std::variant<int, double>;
int main()
{
std::vector<int> intVec{ 1,2,3,4 };
std::vector<double> dlVec{ 1.1,2.2,3.3,4.4 };
const MType& refVar = intVec[0];
// const std::vector<MType>& refVec = intVec; // compiler error: not suitable construction
}