Title
Provide a trait that returns the underlying type of an enumeration type
Status
resolved
Section
[meta.trans.other]
Submitter
Alisdair Meredith

Created on 2009-03-12.00:00:00 last changed 170 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Add a new row to the table in [meta.trans.other]:

Table 41 -- Other transformations
Template Condition Comments
template< class T > struct enum_base; T shall be an enumeration type ([dcl.enum]) The member typedef type shall name the underlying type of the enum T.
Date: 2010-11-20.00:05:46

[ 2009-10 Santa Cruz: ]

NAD EditorialResolved. Solved by N2984.

Date: 2010-10-21.18:28:33

[ Addressed in N2947. ]

Date: 2009-05-23.00:00:00

[ 2009-05-23 Alisdair adds: ]

Just to confirm that the BSI originator of this comment assumed it did indeed imply a compiler intrinsic. Rather than request a Core extension, it seemed in keeping with that the type traits interface provides a library API to unspecified compiler features - where we require several other traits (e.g. has_trivial_*) to get the 'right' answer now, unlike in TR1.

Date: 2010-10-21.18:28:33

[ Batavia (2009-05): ]

Pete observes (and Tom concurs) that the proposed resolution seems to require compiler support for its implementation, as it seems necessary to look at the range of values of the enumerated type. To a first approximation, a library solution could give an answer based on the size of the type. If the user has specialized numeric_limits for the enumerated type, then the library might be able to do better, but there is no such requirement. Keep status as Open and solicit input from CWG.

Date: 2012-10-21.13:19:07

Addresses UK 98 [CD1]

It would be useful to be able to determine the underlying type of an arbitrary enumeration type. This would allow safe casting to an integral type (especially needed for scoped enums, which do not promote), and would allow use of numeric_limits. In general it makes generic programming with enumerations easier.

History
Date User Action Args
2010-11-19 19:04:45adminsetstatus: nad editorial -> resolved
2010-10-21 18:28:33adminsetmessages: + msg519
2010-10-21 18:28:33adminsetmessages: + msg518
2010-10-21 18:28:33adminsetmessages: + msg517
2010-10-21 18:28:33adminsetmessages: + msg516
2010-10-21 18:28:33adminsetmessages: + msg515
2009-03-12 00:00:00admincreate