字符数字['0'...'9']需要具有连续的数字值吗? [英] Are the character digits ['0'..'9'] required to have contiguous numeric values?

查看:169
本文介绍了字符数字['0'...'9']需要具有连续的数字值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须使用C ++实现将chars'0' - '9'设置为具有连续的数值,即:

Must a C++ implementation set the chars '0'-'9' to have contiguous numeric values, i.e. so that:

'0' -> 0+n
'1' -> 1+n
 m  -> m+n
'9' -> 9+n



我找不到在 isdigit ([classification](22.3.3.1字符分类)) *
也不能在locale文档中找到它(但也许我看起来不够强)。

I cannot find it mentioned in the documentation of isdigit ([classification] (22.3.3.1 Character classification)) *, nor can I find it in the locale documentation (but maybe I did not look hard enough).

在2.3个字符集中,我们发现

In 2.3 Character sets, we find that


基本源字符集由96个字符组成:空格字符,表示
水平制表符,垂直制表符,换页符和换行符的控制字符,以及以下91个图形字符

The basic source character set consists of 96 characters: the space character, the control characters representing horizontal tab, vertical tab, form feed, and new-line, plus the following 91 graphical characters

但它没有提到任何顺序(但也许我没有看起来很难)。

But it doesn't mention any ordering (but maybe I did not look hard enough).

* :有趣的脚注:


在循环中使用时,缓存ctype<> facet并直接使用它(而不是isdigit()等,end comment],或使用ctype<> :: is的向量形式。

When used in a loop, it is faster to cache the ctype<> facet and use it directly [instead of isdigit() et al, end comment], or use the vector form of ctype<>::is.


推荐答案

确实没有看起来很难:在2.3。字符集,项目3:

Indeed not looked hard enough: In 2.3. Character sets, item 3:


在源和执行基本字符集中,十进制数字列表之上的
应为 上一个的值一个
b $ b

In both the source and execution basic character sets, the value of each character after 0 in the above list of decimal digits shall be one greater than the value of the previous.

这是上面的小数位数列表:

And this is above list of decimal digits:

0 1 2 3 4 5 6 7 8 9

因此,实现必须使用字符集十进制数字具有连续的表示。因此,您依赖此属性的优化是安全的;然而,您依赖于其他数字(例如'a'..'z')的一致性的优化是不是便携式w.r.t.到标准(另见标题< cctype> )。如果这样做,请确保声明该属性。

Therefore, an implementation must use a character set where the decimal digits have a contiguous representation. Thus, optimizations where you rely on this property are safe; however, optimizations where you rely on the coniguity of other digits (e.g. 'a'..'z') are not portable w.r.t. to the standard (see also header <cctype>). If you do this, make sure to assert that property.

这篇关于字符数字['0'...'9']需要具有连续的数字值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆