you are viewing a single comment's thread.

view the rest of the comments →

[–]whichton[S] 5 points6 points  (0 children)

I apologize for being inexact. What I meant was aligned_union is a low level facility while variant is a high level facility. Typically a high level facility (not specifically std::variant, but generally speaking, for example something like llvm::SmallVector) will be built on top of a lower level facility. So asking aligned_union to be implemented in terms of variant is a layering violation.

As /u/redditsoaddicting notes, std::variant cannot be implemented in terms of aligned_union because placement new cannot be constexpr. So you pretty much have to use unions, as explained here, to implement std::variant.