本文介绍了为什么运行时大小的数组和std :: dynarray在C ++ 14?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 草案C ++ 14包括运行时大小的数组和 std :: dynarray 容器。从我可以告诉,两者之间唯一的真正的区别是 std :: dynarray 有一个STL接口(例如, begin , end , size 等),而运行时大小的数组不会。 我知道运行时大小的数组是核心语言的一部分,而 std :: dynarray 是标准库的一部分,但 std :: dynarray 的建议清楚地表明,作者希望编译器在许多情况下为 std :: dynarray ,以便它可以尽可能高效,即与运行时大小的数组一样高效。因此,再次,为什么C ++ 14需要两个运行时大小的数组和这样的语言/库区分似乎有些人为的。 ?由于 std :: dynarray 有一个更丰富的(STLified)接口,为什么不放弃运行时大小的数组,假设 std :: dynarray 可以以相同的运行时效率实现? 澄清 当我谈到运行时大小的数组时,我指的是一个新的C ++ 14核心语言功能,在 N3639 ,而不是传统的C数组或VLA或C ++ 11中的任何内容。解决方案 N3639 建议将自动存储持续时间的本地运行时大小的数组添加到C ++。 N2648 说,为了遵循C ++实践, std :: dynarray 可用于不仅仅是自动变量。但是为了利用效率堆栈分配,我们希望在用作自动变量时使 dynarray 可优化。 简而言之,C11风格的运行时大小的数组被限制存储在堆栈中。 dynarray 不是,但是可以优化存储在堆栈上,以像C11样式的运行时大小的数组一样高效(或者是目标)。 C11样式的运行时大小的数组可能是一个有用的语法,并且增加与C的可编译性的成本不高:该机制必须实现高效自动 dynarray 无论如何。此外,C11风格的运行时大小的数组是一流的公民,并且不管程序员使用 std 库是否存在。 实际的C11运行时大小的数组和C ++ 1y C11样式的运行时大小的数组之间有重要的区别,其中最小的是运行时 sizeof 实际的C11运行时大小的数组支持。 请注意,最后,不会在C ++ 14中添加。 Draft C++14 includes both runtime-sized arrays and the std::dynarray container. From what I can tell, the only real difference between the two is that std::dynarray has an STL interface (e.g., begin, end, size, etc.), while runtime-sized arrays do not. So why does C++14 need them both?I understand that runtime-sized arrays are part of the core language, while std::dynarray is part of the standard library, but the proposal for std::dynarray makes clear that the authors expect compilers, in many cases, to offer special support for std::dynarray so that it can be as efficient as possible, i.e., as efficient as a runtime-sized array. As such, the language/library distinction seems somewhat artificial.So, again, why does C++14 need both runtime-sized arrays and std::dynarray? And given that std::dynarray has a richer (STLified) interface, why not just drop runtime-sized arrays, assuming that std::dynarray can be implemented with equal runtime efficiency?ClarificationWhen I talk about "runtime-sized arrays," I'm referring to a new C++14 core language feature that's described in N3639, not to traditional C arrays or VLAs or anything in C++11. 解决方案 N3639 proposes to add local runtime-sized arrays with automatic storage duration to C++.N2648 says that in keeping with C++ practice, std::dynarrays are usable with more than just automatic variables. But to take advantage of the efficiency stack allocation, we wish to make dynarray optimizable when used as an automatic variable.In short, C11 style runtime-sized arrays are restricted to being stored on the stack. dynarray is not, but can be optimized when stored on the stack to be as efficient as C11 style runtime-sized arrays (or so is the goal).C11 style runtime-sized arrays can be a useful syntax still, and the cost to increase intercompilability with C isn't high: the mechanism would have to be implemented for efficient automatic dynarray anyhow. In addition, C11 style runtime-sized arrays are first class citizens, and exist regardless of use of std libraries by the programmer.There are important differences between actual C11 runtime-sized arrays and C++1y C11-style runtime-sized arrays, not the least of which is the runtime sizeof that actual C11 runtime-sized arrays support. But basic use of it may be compatible.Note that in the end, neither where added in C++14. 这篇关于为什么运行时大小的数组和std :: dynarray在C ++ 14?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-19 05:10