Access std::variant inside lambda

时间秒杀一切 提交于 2020-06-01 05:49:50

问题


I have the following code:

std::variant<std::uint32_t, std::uint16_t, float> my_variant;

template <typename T>
void my_sub_func(T& value)
{
  // do stuff
};

void my_func(my_variant& value)
{
  [&]()
  {
    my_sub_func(std::get<std::uint32_t>(value));
  };
};

int main()
{
  my_variant t;
  my_func(t);
}

I always get an Unexpected index exception at runtime, why is that and how can I avoid it?

来源:https://stackoverflow.com/questions/61930744/access-stdvariant-inside-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!