[Patch] Implement std::experimental::variant

Ville Voutilainen ville.voutilainen@gmail.com
Fri Aug 5 12:39:00 GMT 2016


On 5 August 2016 at 14:08, Jonathan Wakely <jwakely@redhat.com> wrote:
> This is some truly impressive code, I'm not sure I understand all of
> it yet!
>
> As before, my only reservation is that this fails to compile, but
> should work (because the selected constructor for the chosen
> alternative is constexpr):
>
>  #include <variant>
>
>  struct literal {
>   constexpr literal() = default;
>  };
>
>  struct nonliteral {
>   nonliteral() { }
>  };
>
>  using namespace std;
>  constexpr variant<literal, nonliteral> v{};
>  constexpr variant<literal, nonliteral> v1{in_place_type<literal>};
>  constexpr variant<literal, nonliteral> v2{in_place_index<0>};
>
>
> However, I think we could commit this for now as it's 99% complete.
> What do you think?


Well, the implementation uses placement-new, so it can't be constexpr.
Gaining the ability to
use placement-new in constant expressions is unlikely to appear any
time soon, so if this
implementation approach is fundamentally incompatible with the
constexpr requirements
of variant, I find committing it rather problematic, as I don't see a
simple way to fill in
the constexpr parts without more or less rewriting variant. There are
other variant implementations
written in C++17 that provide full conformance, so I think our variant
should do so too.



More information about the Libstdc++ mailing list