This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.

### 2805. `void` and reference type alternatives in `variant`, `variant<>` and `index()`

Section: 20.7 [variant], 20.7.3 [variant.variant], 20.7.3.2 [variant.ctor] Status: Resolved Submitter: Switzerland Opened: 2016-11-10 Last modified: 2020-09-06

Priority: Not Prioritized

View all issues with Resolved status.

Discussion:

Addresses CH 3, CH 4, CH 5, CH 6, CH 8

1. `variant` allows reference types as alternatives; `optional` explicitly forbids to be instantiated for reference types. This is inconsistent.

2. `variant<int, void>` should be as usable as `variant<int>`.

3. `variant<>` should not have an `index()` function.

4. Clarify the intended behavior of `variant` for alternative types that are references.

5. Clarify `variant` construction.

Proposed change:

1. Consider allowing reference types for both or none.

2. —

3. Consider specifying a specialization for `variant<>` like:

   >     template<>
   >     class variant<>
   >     {
   >     public:
   >       variant() = delete;
   >       variant(const variant&) = delete;
   >       variant& operator=(variant const&) = delete;
   >     };

4. Add a respective note.

5. Add a note that `variant<>` cannot be constructed.

[Issues Telecon 16-Dec-2016]

Resolved by the adoption of P0501R0.

Proposed resolution: