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

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

问题描述

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

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 是一个聚合,所以可以初始化为一个 constexpr 当且仅当基础类型 T 具有 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天全站免登陆