polkovnikov.ph
polkovnikov.ph

Reputation: 6632

boost variant: get reference to the variant by its type

Suppose there is

boost::variant<int, std::string> v;

How do I get a reference x of type std::string & that could be used like

x = "abc";

and would have a behaviour equivalent to

v = "abc";

?

Upvotes: 3

Views: 1946

Answers (1)

Xiaotian Pei
Xiaotian Pei

Reputation: 3260

std::string& x = boost::get<std::string>(v);

Upvotes: 6

Related Questions