如何将std :: array转换为std :: tuple?

编程入门 行业动态 更新时间:2024-10-11 03:16:52
本文介绍了如何将std :: array转换为std :: tuple?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在研究一个aux模块,以便在多态对象之间传递值,并且在某个时候已经有了

I am working on a aux module to pass values between polymorphic objects and at some point I have

std::array<void*, N>

并且需要转发

std::tuple<void*, void*, /* N times */>

我可以通过使用 index_sequence 或/和递归来找到一些解决方案,但是所有这些看起来都很笨重且难以阅读.通过标准库,还有其他更直接的方法吗?

I can figure some solution with the use of index_sequence or/and recursions, but all of those look bulky and difficult to read. Is there any more straightforward way to do this by the means of the standard library?

另外,以防万一-我是对的, std :: array 的布局是各个对象的密集集合,因此,等于 void ** 各自的长度,而元组的布局允许有间隙吗?

Also, just in case - am I right that the layout of std::array is a dense set of respective objects, thus equal to, lets say, void** of respective length, whereas the layout of tuple allows gaps?

推荐答案

如果您的实现支持,则可以使用 std :: tuple_cat .在某些实现中,它将尊重元组接口( std :: array 确实这样做)的任意数量的对象连接到单个平面元组中.连接一个类似元组的对象只会产生一个元组,其中包含所述源元组"成员的副本.

If your implementation supports it, you can use std::tuple_cat. Under some implementations it concatenates any number of objects that respect the tuple interface (which std::array does) into a single flat tuple. Concatenating a single tuple like object will just produce a tuple that holds copies of the members of said source "tuple".

std::array<void*, N> a; auto b = std::tuple_cat(a);

另外,以防万一-我是对的, std :: array 的布局是各个对象的密集集合,因此,等于 void ** 各自的长度,而元组的布局允许有间隙吗?

Also, just in case - am I right that the layout of std::array is a dense set of respective objects, thus equal to, lets say, void** of respective length, whereas the layout of tuple allows gaps?

std :: array 是一个聚合,它将在内部保存 void * [N] .因此,是的,元素之间将没有填充.未指定元组元素的布局.

A std::array is an aggregate the will hold a void*[N] internally. So yes, the elements will be without padding in between them. The layout of the tuple's elements is not specified to such an extent.

更多推荐

如何将std :: array转换为std :: tuple?

本文发布于:2023-11-05 18:18:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561527.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   如何将   array   std   tuple

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!