gpt4 book ai didi

c++ - 结构化绑定(bind)可以使用什么类型的结构

转载 作者:可可西里 更新时间:2023-11-01 17:55:38 31 4
gpt4 key购买 nike

我在这里浏览了关于结构化绑定(bind)的论文 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0144r0.pdf但我无法很好地了解语法允许绑定(bind)到哪些类型的结构。我最好的猜测是结构必须是聚合类型。或者只有公共(public)数据成员的东西。

我对此有什么遗漏吗?

最佳答案

如果您不想为您的类型专门化 std::tuple_sizestd::tuple_elementget,那么 [dcl .decomp] 要求:

Otherwise, all of E’s non-static data members shall be public direct members of E or of the same unambiguous public base class of E, E shall not have an anonymous union member, and the number of elements in the identifier-list shall be equal to the number of non-static data members of E.

所以基本上所有数据成员都需要在同一个类中声明,并且它们都需要是公共(public)的,并且您需要提供与成员数量相同的名称。

关于c++ - 结构化绑定(bind)可以使用什么类型的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40901643/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com