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?

Aleksandr Tukallo
  • 1,299
  • 17
  • 22

2 Answers2

5

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

Ralph Tandetzky
  • 22,780
  • 11
  • 73
  • 120
  • 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? – Aleksandr Tukallo Dec 22 '16 at 14:44
  • 1
    @AleksandrTukallo: Simply with download, configure; make; make install. Works perfect! – Klaus Dec 22 '16 at 14:55
  • @Klaus thanks! But what problems may I encounter when using it before release? Is it ok? – Aleksandr Tukallo Dec 22 '16 at 14:56
  • 1
    @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! – Klaus Dec 22 '16 at 15:00
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.

user2393256
  • 1,001
  • 1
  • 15
  • 26