469 questions
Score of 1
0 answers
220 views
Can std::array of std::byte or unsigned char be used to implicitly create objects and provide storage?
Under https://eel.is/c++draft/intro.object#16 (see below) does the creation of a std::array of std::byte or unsigned char implicitly create objects?
Except during constant evaluation, an operation ...
Score of 0
0 answers
271 views
std::array at function not throwing out of range
While debugging something I stumbled into this behavior on godbolt. When compiling and running the following (godbolt link https://godbolt.org/z/9c5966sbK):
#include <array>
int main()
{
...
Score of 15
4 answers
1256 views
What is the size of std::array<T,0>?
Unlike C array, std::array is allowed to have zero length. But the current implementations differ in how std::array<T,0> is implemented, in particular the sizes of the object are different.
This ...
Score of 1
2 answers
232 views
C++: std::array invalid array assignment [duplicate]
I have the below code. What am I doing wrong that I can't simple assign the array myBar to the 1st index of foo? Using memcpy works but somehow I don't want to use this approach.
#include <array>...
Score of 12
7 answers
2004 views
Construct an std::array at compile time in C++17 using the preprocessor
I am developing a C++17 framework that has optional third-party dependencies and I'd like to construct an std::array that contains the names of the available dependencies.
The CMake file sets ...
Score of 4
1 answer
196 views
Why does template deduction for a nested std::array with one element result in a one dimensional std::array?
The following code compiles successfully with clang and gcc. Naively, I would have expected a2 to have type std::array<std::array<int, 1>, 1>.
#include <array>
auto a1 = std::array{...
Score of 0
2 answers
185 views
Cannot define an `std::array` with `std::string` argument in Visual C++
This code builds successfully with Clang 20.1.10 and with GCC 15.1, but not with Microsoft Visual C++ 2022 version 17.14.0:
#include <array>
#include <string>
int main()
{
static ...
Score of 7
1 answer
262 views
Directly initialize std::array with a fixed count of elements from std::vector [duplicate]
The elements in the array are not default constructible therefore we need to initialize the array directly from elements in std::vector.
#include <array>
#include <vector>
class foo {
...
Score of 9
0 answers
331 views
std::to_array differs from direct initialization
Initially I thought that std::to_array would be equivalent to initializing directly, i.e. a way to avoid having to specify the length of the array in the code, compare:
constexpr auto arr = std::...
Score of 2
1 answer
818 views
Using std::ranges::to with std::array
I would like to have this code with std::vector replaced with std::array, but I presume it can not be done since std::array is not a container std::ranges::to understands.
constexpr auto dice = std::...
Score of 41
1 answer
2644 views
Which feature of C++23 allows converting std::array to std::tuple?
The following code snippet implicitly converts a std::array to a std::tuple:
std::array<int,3> arr = {2,4,6};
std::tuple<int,int,int> tup;
tup = arr; // c++23 or later
The assignment ...
Score of 1
4 answers
273 views
How to split std::array without copying?
I need to access an std::array<double, 9> x by two functions, namely funA and funB. funA only needs the first 6 entries of x and funB the last 3 entries. I am limited to C++14.
I know there are ...
Score of 2
0 answers
63 views
Nested std::array of primitive type initialization to default value
We know std::array<double, N> Can be initialized to all-zero by
std::array<double, N> my_array {}
My question is if I have
std::array<std::array<double, N>, M> my_array {}
...
Score of 15
3 answers
953 views
How to use std::array.size() as a template parameter when a class has a non-constexpr std::array
The following is a toy example
The class student has a std::array<char, 15> called name and an integer age. A student has a member function called encode that calls a global template function ...
Score of 3
2 answers
156 views
initializing std::array with nullptr without template parameters
I am using an API that expects a contiguous block of memory that contains pointers.
the pointers themselves can be nullptr.
Currently, I use C-Arrays:
ID3D11ShaderResourceView* srvs[] = {
...