Skip to main content
15 votes
4 answers
1k views

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 ...
Fedor's user avatar
  • 25.1k
1 vote
2 answers
193 views

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>...
Peter VARGA's user avatar
  • 5,351
12 votes
7 answers
2k views

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 ...
Charlie Vanaret - the Uno guy's user avatar
4 votes
1 answer
174 views

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{...
MarkB's user avatar
  • 2,230
0 votes
2 answers
176 views

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 ...
Pietro's user avatar
  • 13.6k
7 votes
1 answer
251 views

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 { ...
 sentientbottleofwine's user avatar
9 votes
0 answers
230 views

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::...
Zitrax's user avatar
  • 20.7k
2 votes
1 answer
544 views

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::...
NoSenseEtAl's user avatar
41 votes
1 answer
3k views

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 ...
Bertwim van Beest's user avatar
1 vote
4 answers
241 views

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 ...
Fredo's user avatar
  • 47
2 votes
0 answers
61 views

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 {} ...
Alex Suo's user avatar
  • 3,177
15 votes
3 answers
938 views

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 ...
timmy george's user avatar
3 votes
2 answers
142 views

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[] = { ...
Raildex's user avatar
  • 5,487
1 vote
1 answer
193 views

std::span works great on std::vectors, std::arrays or c pointers. However, often the contiguous memory has a different type associated to it such as for example a vector of arrays. I'm trying to use a ...
Romain's user avatar
  • 47
4 votes
1 answer
170 views

I'd have expected that if an std::array is an rvalue, then calling operator[] returns an rvalue as well. But it doesn't seem to be the case (cppreference), there are no value-category overloads. For ...
geza's user avatar
  • 30.5k

15 30 50 per page
1
2 3 4 5
32