现在,我们已经标准::阵列留下什么用途C风格的数组? [英] Now that we have std::array what uses are left for C-style arrays?

查看:119
本文介绍了现在,我们已经标准::阵列留下什么用途C风格的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的std ::阵列是大大优于C数组。即使我想与传统code互操作,我可以只使用的std ::数组::数据()。是否有任何理由,我愿做一个老派的阵列?

std::array is vastly superior to the C arrays. And even if I want to interoperate with legacy code, I can just use std::array::data(). Is there any reason I would ever want an old-school array?

推荐答案

除非我已经错过了一些东西(我没有遵循最新的标准过于紧密的变化),大多数C风格的数组的用途仍然。 的std ::阵列确实允许静态初始化,但它仍然不会为你算初始化。而且,由于之前的唯一真正采用C风格的数组的的std ::阵列是静态初始化表
沿着线:

Unless I've missed something (I've not followed the most recent changes in the standard too closely), most of the uses of C style arrays still remain. std::array does allow static initialization, but it still won't count the initializers for you. And since the only real use of C style arrays before std::array was for statically initialized tables along the lines of:

MyStruct const table[] =
{
    { something1, otherthing1 },
    //  ...
};

通常使用开始结束模板函数(在通过了


C ++ 11)遍历他们。而没有mentionning大小,这样编译器初始化的数量决定。

using the usual begin and end template functions (adopted in C++11) to iterate over them. Without ever mentionning the size, which the compiler determines from the number of initializers.

编辑:另一件事我忘了:字符串文字仍然是C形式的数组;即用型的char [] 。我不认为任何人会排除使用字符串只是因为我们有的std ::阵列

Another thing I forgot: string literals are still C style arrays; i.e. with type char[]. I don't think that anyone would exclude using string literals just because we have std::array.

这篇关于现在,我们已经标准::阵列留下什么用途C风格的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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