我需要初始化std::array
中所有元素的值,就像使用std::vector
可以做到的那样。
#include <vector>
#include <array>
int main()
{
std::vector<int> v(10, 7); // OK
std::array<int, 10> a(7); // does not compile, pretty frustrating
}
有没有一种优雅的方式来做到这一点?
现在我正在使用这个:
std::array<int, 10> a;
for (auto & v : a)
v = 7;
但我希望避免使用明确的代码进行初始化。