可以在constexpr类中使用std :: array? [英] Can std::array be used in a constexpr class?

查看:125
本文介绍了可以在constexpr类中使用std :: array?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个具有 constexpr 构造函数的类,我想知道我是否可以使用 std :: array 来存储这个类的数据。标准是否明确指定 std :: array 有一个 constexpr 构造函数,并且其内容可以在编译时访问-time?

I am currently creating a class with a constexpr constructor and I wonder if I can use an std::array to store the data of this class. Does the standard explicitly specify that an std::array has a constexpr constructor and that its contents can be accessed at compile-time ?

推荐答案

因为 std :: array< T,N> 是一个聚合,当且仅当底层类型 T constexpr 时,它可以初始化为 c $ c> constexpr 构造函数(当与您提供的每个初始化器一起显示)。

Because std::array<T, N> is an aggregate, it can be initialized as a constexpr if and only if the underlying type T has a constexpr constructor (when presented with each initializer you provide).

这篇关于可以在constexpr类中使用std :: array?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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