Explicit Type Conversion and Multiple Simple Type Specifiers

梦想与她 提交于 2019-11-27 14:29:29
James McNellis

I posted this question to comp.lang.c++.moderated.

Daniel Krügler of the C++ standards committee agreed with the interpretation that unsigned int is a combination of simple type specifiers, and is not itself a simple type specifier.

Concerning the caption of table 7 referenced by Jerry Coffin, Krügler says:

I agree that the header of Table 7 (which is Table 9 in the most recent draft N3000) is somewhat misleading, but the preceeding text in [dcl.type.simple]/2 looks very clear to me, when it says:

Table 7 summarizes the valid combinations of simple-type-specifiers and the types they specify."

(I apologize it took me so long to post this back here from the newsgroup; it completely slipped my mind)

In §7.1.5.2, keep reading down to table 7, which has the full list of what's allowed as a simple specifier (which does include "unsigned int").

Hmm, sometimes you need a typedef. If it doesn't say a diagnostic is required, then it's not incorrect for them to support this. Nevertheless, for portability, you can use a typedef (uint16_t or uint64_t, although those might not be right), or quote the typename with a template:

iterator<void, unsigned long>::value_type( 5 )

How's that for unreasonably verbose?

Edit: Duh, or simply 5ul. That leaves unsigned short, unsigned char, and signed char as the only types you can't easily explicitly construct.

7.1.5.2:

The simple-type-specifiers specify either a previously-declared user-defined type or one of the fundamental types`

This implies that unsigned int i = unsigned int() is legal, since unsigned int is a fundamental type (and thus a simple-type-specifier, see 3.9.1).

same applies for types like:

long double
long long
long long int
unsigned long
unsigned long long int
short int
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!