<i id='arQAw'><tr id='arQAw'><dt id='arQAw'><q id='arQAw'><span id='arQAw'><b id='arQAw'><form id='arQAw'><ins id='arQAw'></ins><ul id='arQAw'></ul><sub id='arQAw'></sub></form><legend id='arQAw'></legend><bdo id='arQAw'><pre id='arQAw'><center id='arQAw'></center></pre></bdo></b><th id='arQAw'></th></span></q></dt></tr></i><div id='arQAw'><tfoot id='arQAw'></tfoot><dl id='arQAw'><fieldset id='arQAw'></fieldset></dl></div>

        <bdo id='arQAw'></bdo><ul id='arQAw'></ul>
      <legend id='arQAw'><style id='arQAw'><dir id='arQAw'><q id='arQAw'></q></dir></style></legend>
      <tfoot id='arQAw'></tfoot>
    1. <small id='arQAw'></small><noframes id='arQAw'>

      1. 嵌套的 std::arrays 中的数据是否保证是连续的?

        时间:2023-09-15

          <legend id='f35ti'><style id='f35ti'><dir id='f35ti'><q id='f35ti'></q></dir></style></legend>

        1. <tfoot id='f35ti'></tfoot>
          • <i id='f35ti'><tr id='f35ti'><dt id='f35ti'><q id='f35ti'><span id='f35ti'><b id='f35ti'><form id='f35ti'><ins id='f35ti'></ins><ul id='f35ti'></ul><sub id='f35ti'></sub></form><legend id='f35ti'></legend><bdo id='f35ti'><pre id='f35ti'><center id='f35ti'></center></pre></bdo></b><th id='f35ti'></th></span></q></dt></tr></i><div id='f35ti'><tfoot id='f35ti'></tfoot><dl id='f35ti'><fieldset id='f35ti'></fieldset></dl></div>

              • <bdo id='f35ti'></bdo><ul id='f35ti'></ul>
                1. <small id='f35ti'></small><noframes id='f35ti'>

                    <tbody id='f35ti'></tbody>
                  本文介绍了嵌套的 std::arrays 中的数据是否保证是连续的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  std::array, M> 中的数据是否保证连续?例如:

                  Is the data in std::array<std::array<T,N>, M> guaranteed to be contiguous? For example:

                  #include <array>
                  #include <cassert>
                  
                  int main()
                  {
                      enum {M=4, N=7};
                      typedef std::array<char,N> Row;
                      typedef std::array<Row, M> Matrix;
                      Matrix a;
                      a[1][0] = 42;
                      const char* data = a[0].data();
                  
                      /* 8th element of 1D data array should be the same as
                         1st element of second row. */
                      assert(data[7] == 42);
                  }
                  

                  断言是否保证成功?或者,换句话说,我可以依靠 Row 的末尾没有填充吗?

                  Is the assert guaranteed to succeed? Or, to put it another way, can I rely on there being no padding at the end of a Row?

                  为了清楚起见,对于这个例子,我希望整个矩阵的数据是连续的.

                  Just to be clear, for this example, I want the data of the entire matrix to be contiguous.

                  推荐答案

                  不,在这种情况下不保证连续性.

                  No, contiguity is not guaranteed in this case.

                  std::array 保证是一个聚合,并以这样一种方式指定,即用于存储的底层数组必须是该类型的第一个数据成员.

                  std::array is guaranteed to be an aggregate, and is specified in such a way that the underlying array used for storage must be the first data member of the type.

                  但是,没有要求sizeof(array) == sizeof(T) * N,也没有要求最后没有未命名的填充字节对象或 std::array 除了底层数组存储之外没有数据成员.(不过,包含额外数据成员的实现充其量是不寻常的.)

                  However, there is no requirement that sizeof(array<T, N>) == sizeof(T) * N, nor is there any requirement that there are no unnamed padding bytes at the end of the object or that std::array has no data members other than the underlying array storage. (Though, an implementation that included additional data members would be, at best, unusual.)

                  这篇关于嵌套的 std::arrays 中的数据是否保证是连续的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:解密 Chromium cookie 下一篇:给定宽度和高度,如何调整对象的 2D 矢量大小

                  相关文章

                  最新文章

                  <i id='SG80Y'><tr id='SG80Y'><dt id='SG80Y'><q id='SG80Y'><span id='SG80Y'><b id='SG80Y'><form id='SG80Y'><ins id='SG80Y'></ins><ul id='SG80Y'></ul><sub id='SG80Y'></sub></form><legend id='SG80Y'></legend><bdo id='SG80Y'><pre id='SG80Y'><center id='SG80Y'></center></pre></bdo></b><th id='SG80Y'></th></span></q></dt></tr></i><div id='SG80Y'><tfoot id='SG80Y'></tfoot><dl id='SG80Y'><fieldset id='SG80Y'></fieldset></dl></div>

                      <small id='SG80Y'></small><noframes id='SG80Y'>

                      • <bdo id='SG80Y'></bdo><ul id='SG80Y'></ul>

                      <tfoot id='SG80Y'></tfoot>

                    1. <legend id='SG80Y'><style id='SG80Y'><dir id='SG80Y'><q id='SG80Y'></q></dir></style></legend>