#12680 closed Bugs (fixed)

Inheriting constructors from Boost.Variant should be possible

Reported by: djh Owned by: Antony Polukhin
Milestone: Boost 1.64.0 Component: variant
Version: Boost 1.62.0 Severity: Problem
Keywords: Cc:


Suppose users want a strong typedef for their sumtypes. Instead of creating a weak type alias for a boost::variant the user should be able to inherit from the variant inheriting its constructors, too.

using TreeBase = boost::variant<Leaf, boost::recursive_wrapper<Node>>;

struct Tree : TreeBase {
  using TreeBase::TreeBase;

  // ...

Here is the full small self-contained example

GCC crashing on this is ticketed upstream

Creating a new type for this use-case provides the user with type safety and should be the recommended way of using variant in any non-trivial code. Unfortunately, inheriting from Boost.Variant is not possible at the moment. The code example above does not compile.

In the Boost IRC channel Agustín Bergé told me this might be related to inheriting constructors with default arguments and that there are quirks related to SFINAE before C++17.

Attachments (1) (473 bytes) - added by djh 15 months ago.

Download all attachments as: .zip

Change History (3)

Changed 15 months ago by djh

Attachment: added

comment:1 Changed 13 months ago by Antony Polukhin

Milestone: To Be DeterminedBoost 1.64.0
Owner: changed from ebf to Antony Polukhin
Status: newassigned

Fixed by Mikhail Maximov in 217ee7f9. Fix will be marged to master, as soon as all the tests will cycle.

comment:2 Changed 10 months ago by Antony Polukhin

Resolution: fixed
Status: assignedclosed

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Antony Polukhin.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.