This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.
tuple_element
/variant_alternative
Section: 22.3.4 [pair.astuple], 22.6.4 [variant.helper] Status: C++20 Submitter: Agustín K-ballo Bergé Opened: 2017-06-10 Last modified: 2021-02-25
Priority: Not Prioritized
View all other issues in [pair.astuple].
View all issues with C++20 status.
Discussion:
Instantiating tuple_element
with an out-of-bounds index requires a diagnostic for tuple
and array
,
but not for pair
. The specification requires an out-of-bounds index for pair
to go to the base template
instead, which is undefined.
variant_alternative
with an out-of-bounds index violates a requirement, but it is not
required to be diagnosed.
[2017-06-12, Moved to Tentatively Ready after 5 positive votes on c++std-lib]
Proposed resolution:
This wording is relative to N4659.
Modify 22.2.1 [utility.syn], header <utility>
synopsis, as indicated:
[…] // 22.3.4 [pair.astuple], tuple-like access to pair template <class T> class tuple_size; template <size_t I, class T> class tuple_element; template <class T1, class T2> struct tuple_size<pair<T1, T2>>; template <size_t I, class T1, class T2> struct tuple_element<I, pair<T1, T2>>;template <class T1, class T2> struct tuple_element<0, pair<T1, T2>>; template <class T1, class T2> struct tuple_element<1, pair<T1, T2>>;[…]
Modify 22.3.4 [pair.astuple] as indicated:
tuple_element<0, pair<T1, T2>>::type
-1- Value: The typeT1
.tuple_element<1, pair<T1, T2>>::type
-2- Value: The typeT2
.tuple_element<I, pair<T1, T2>>::type-?- Requires:
-?- Value: The typeI < 2
. The program is ill-formed ifI
is out of bounds.T1
ifI == 0
, otherwise the typeT2
.
Modify 22.6.4 [variant.helper] as indicated:
variant_alternative<I, variant<Types...>>::type-4- Requires:
-5- Value: The typeI < sizeof...(Types)
. The program is ill-formed ifI
is out of bounds.TI
.