pair and arraySection: 22.3.2 [pairs.pair], 23.3.3 [array] Status: C++20 Submitter: Barry Revzin Opened: 2020-01-27 Last modified: 2021-02-25
Priority: 2
View other active issues in [pairs.pair].
View all other issues in [pairs.pair].
View all issues with C++20 status.
Discussion:
We had this NB ballot issue, to ensure that
std::array could be a NTTP. But after P1907, we still need
some kind of wording to ensure that std::array (and also std::pair) have no extra
private members or base classes.
The class template
pair/arrayhas the data members specified above. It has no base classes or data members other than those specified.
[2020-02 Prioritized as P2 Monday morning in Prague]
Previous resolution [SUPERSEDED]:
This wording is relative to N4849.
Modify 22.3.2 [pairs.pair] as indicated:
-1- Constructors and member functions of
-2- The defaulted move and copy constructor, respectively, ofpairdo not throw exceptions unless one of the element-wise operations specified to be called for that operation throws an exception.pairis a constexpr function if and only if all required element-wise initializations for copy and move, respectively, would satisfy the requirements for a constexpr function. -3- If(is_trivially_destructible_v<T1> && is_trivially_destructible_v<T2>)istrue, then the destructor ofpairis trivial. -?- The class templatepairhas the data members specified above. It has no base classes or data members other than those specified.Modify 23.3.3.1 [array.overview] as indicated:
-1- The header
-2- An<array>defines a class template for storing fixed-size sequences of objects. Anarrayis a contiguous container (23.2.2 [container.requirements.general]). An instance ofarray<T, N>storesNelements of typeT, so thatsize() == Nis an invariant.arrayis an aggregate (9.5.2 [dcl.init.aggr]) that can be list-initialized with up toNelements whose types are convertible toT. -3- Anarraymeets all of the requirements of a container and of a reversible container (23.2 [container.requirements]), except that a default constructedarrayobject is not empty and thatswapdoes not have constant complexity. Anarraymeets some of the requirements of a sequence container (23.2.4 [sequence.reqmts]). Descriptions are provided here only for operations onarraythat are not described in one of these tables and for operations where there is additional semantic information. -?- The class templatearrayhas the data members specified in subclauses 23.3.3.1 [array.overview] and 23.3.3.5 [array.zero]. It has no base classes or data members other than those specified. -4- […]
[2020-02-13, Prague]
Tim Song and Tomasz were trying to come up with general wording that could be reused for both pair and
array (and other types). They suggest that if it should be in scope for C++20, it would be better to
provide non-general wording for pair and array (that is easier to get right).
The type
Tis structurally compatible withsubs, if for the valuest1andt2of typeT:
Tis a structural type (13.2 [temp.param]) if the types of subobjects oft1designated bysubsare all structural types.
t1is template-argument-equivalent (13.6 [temp.type]) tot2, if and only if, for each subject designed bysubs, the value of subobject oft1is template-argument-equivalent to the value of the correponding subobject oft2.
Then changes for array/pair would then look like:
pair<T, U>is structurally compatible (<some-reference>) withfirstandsecond.array<T, N>is structurally compatible with its elements (if any).
[2020-02 Status to Immediate on Friday morning in Prague.]
Proposed resolution:
This wording is relative to N4849.
Modify 22.3.2 [pairs.pair] as indicated:
-1- Constructors and member functions of
-2- The defaulted move and copy constructor, respectively, ofpairdo not throw exceptions unless one of the element-wise operations specified to be called for that operation throws an exception.pairis a constexpr function if and only if all required element-wise initializations for copy and move, respectively, would satisfy the requirements for a constexpr function. -3- If(is_trivially_destructible_v<T1> && is_trivially_destructible_v<T2>)istrue, then the destructor ofpairis trivial. -?-pair<T, U>is a structural type (13.2 [temp.param]) ifTandUare both structural types. Two valuesp1andp2of typepair<T, U>are template-argument-equivalent (13.6 [temp.type]) if and only ifp1.firstandp2.firstare template-argument-equivalent andp1.secondandp2.secondare template-argument-equivalent.
Modify 23.3.3.1 [array.overview] as indicated:
-1- The header
-2- An<array>defines a class template for storing fixed-size sequences of objects. Anarrayis a contiguous container (23.2.2 [container.requirements.general]). An instance ofarray<T, N>storesNelements of typeT, so thatsize() == Nis an invariant.arrayis an aggregate (9.5.2 [dcl.init.aggr]) that can be list-initialized with up toNelements whose types are convertible toT. -3- Anarraymeets all of the requirements of a container and of a reversible container (23.2 [container.requirements]), except that a default constructedarrayobject is not empty and thatswapdoes not have constant complexity. Anarraymeets some of the requirements of a sequence container (23.2.4 [sequence.reqmts]). Descriptions are provided here only for operations onarraythat are not described in one of these tables and for operations where there is additional semantic information. -?-array<T, N>is a structural type (13.2 [temp.param]) ifTis a structural type. Two valuesa1anda2of typearray<T, N>are template-argument-equivalent (13.6 [temp.type]) if and only if each pair of corresponding elements ina1anda2are template-argument-equivalent. -4- […]