Using std::variant in g++
Asked Answered
A

2

6

How can I use std::variant in g++? Why isn't there std::variant in std::experimental (though std::optional is)? What version of g++ do I need? I prefer not to use boost and I'd like to use standard library only.

Edit: it seems like only g++ 7 supports std::variant. Then my question is: when will it be released and what problems may I encounter when using its experimental version?

Ashjian answered 22/12, 2016 at 13:5 Comment(4)
You should use the very latest version of g++Joy
@BasileStarynkevitch what is the version number? How can I get it?Ashjian
Run g++ -v or g++ --version in a terminalJoy
@BasileStarynkevitch I know my version number. I have g++-6.2 and g++-5.4. They do not have variant unfortunatelyAshjian
F
5

This page says, that GCC 7 has std::variant.

Fraktur answered 22/12, 2016 at 13:50 Comment(4)
Yep, I see. How can I install it on Ubuntu? Or as I found out, GCC 7 has not been released yet, when will it be?Ashjian
@AleksandrTukallo: Simply with download, configure; make; make install. Works perfect!Fretwork
@Fretwork thanks! But what problems may I encounter when using it before release? Is it ok?Ashjian
@AleksandrTukallo: It is in stage 3 which means that there are a number of open bugs which should be fixed in the next days. Maybe you run into one of them. But I believe that you even run faster in a unfixed bug of an older gcc version as in a new one from current pre release branch. Short answer: Give it a chance! You can have as many versions in parallel as you want. If it do not work: Write a bug report. It will help others!Fretwork
T
2

GCC has an info page where you can check which language feature was implemented with which version. It looks like variant is not yet implemented.

Tumefaction answered 22/12, 2016 at 13:10 Comment(3)
According to the table std::optional is also not implemented, though I can use it in my g++ 5.4: experimental optional.Ashjian
There is always Boost.VariantNimbus
@Tumefaction Does the link list standard library status or only core language features?Fraktur

© 2022 - 2024 — McMap. All rights reserved.