Questions tagged [stdarray]

std::array is a container that encapsulates constant size arrays in C++.

std::array is a part of the C++ Standard Library since C++11.

Reference: https://en.cppreference.com/w/cpp/container/array

433 questions
0
votes
3 answers

Initialization of std::array with std::initializer_list in constructor's initialization list

Consider the following piece of code: struct foo { std::vector v; foo(std::initializer_list L) : v{L} {} }; The code above compiles fine and initializes v as expected. Now consider the following piece of code: struct bar { …
101010
  • 41,839
  • 11
  • 94
  • 168
0
votes
2 answers

Indexing into std::array of std::array

I have some confusion about indexing of an array of arrays in C++: I have: array, SIZE_OUTER> arr; When I do indexing, I assume the following: arr[outer_index][inner_index] So, outer_index into the array with SIZE_OUTER…
Michael
  • 7,407
  • 8
  • 41
  • 84
0
votes
1 answer

Efficient way to convert/reinterpret vector as vector>

I want to call a method (template) that takes a vector>& with the result from another method that returns a vector Is there a efficient (O(1)) way to reinterpret a vector as a vector>? Is it possible / safe to…
b.buchhold
  • 3,837
  • 2
  • 24
  • 33
0
votes
0 answers

Passing 2d std::array to function c++

I'm trying to pass to a constructor class a 2d array std::array, dimension> I do some search, and i tried to use the template.. But doesn't work But, my code produce the following error : Undefined symbols for…
Pusheen_the_dev
  • 2,077
  • 4
  • 17
  • 33
0
votes
1 answer

std::array vs C-array vs std:vector

i thought to replace std::vector with std::array in my program, so i went on testing: template class A{ public: void sub_run(T w){ w[0] = 0.5; w[1] = 1.5; w[2] = 2.5; w[3] = 0.0; for (int…
stkubr
  • 371
  • 1
  • 5
  • 15
0
votes
1 answer

Pr oblems Accessing Certain Class Functions C++ from Vector

I have a vector of type Tab, but when I call class functions on the vector of Tabs I get no output. However, I don't receive any errors either. If you know what an Android launcher is, then this is supposed to be a simple console-based testcase of…
Andrue
  • 688
  • 3
  • 11
  • 27
0
votes
2 answers

Template class in std::array

Is it possible to add a template class inside std::array without specifying the typename? I mean. template class MyClass { ... } std::array arr; The reason is that I have a kind of storage that accepts all classes that…
yayuj
  • 2,194
  • 3
  • 17
  • 29
0
votes
3 answers

Getting the second argument (size) of std::array as a function argument

In the following code, I need to get size of the std::array as a function argument. I preferred std::array to std::vector since the size of the container is not supposed to change. However, the compiler complains as error: ‘n’ is not a constant…
Shibli
  • 5,879
  • 13
  • 62
  • 126
0
votes
2 answers

Initialize std::array with implied length

In C you can do int a[] = {1,2,3,4,5}, but C++11 std::array a = {1,2,3,4,5} will give a "too few template parameters" compile error. Any way around this?
jcai
  • 3,448
  • 3
  • 21
  • 36
0
votes
3 answers

Return 2d array from C++

Inside a function, I make a 2d array that fills itself from a text file and needs to get returned to main. The array stays a constant size through the whole program. I know this is something that gets asked a lot, but I always seem to get one of two…
JTTCOTE
  • 1
  • 1
  • 2
-1
votes
1 answer

Is calling x = std::array () same as declaring std::array x?

I am writing custom move constructor and move assignment operator for class_name. I would like to know if calling std::array as std::array () is correct or not. class_name::class_name(class_name&& other) : mem_A(std::exchange(other.memA,…
-1
votes
1 answer

Error when using a custom function to sort a vector of arrays

This is my code: #include #include #include #include using namespace std; bool compareel (int a[], int b[]) { return (a[2] < b[2]); } int main () { vector < array < int, 3 >> edges = { {1, 2, 3}, {2,…
-1
votes
1 answer

Why can I create a vector of std::array?

I thought that you should always determine what the size of an array is at compile time. I thought this was the case because a specific amount of memory would be allocated for that array. Then, why is this not a…
Daniel Duque
  • 159
  • 9
-1
votes
1 answer

Turn multidimensional c++ std::array into multidimensional vector

I have a multidimensional c++ std::array (i don't know how many dimensions does it have), and i want to turn it into a multidimensional vector. I thought at a function that returns a vector if a std::array is passed, else throws error. I am pretty…
Giuppox
  • 1,393
  • 9
  • 35
-1
votes
1 answer

/usr/include/c++/7.3.0/bits/predefined_ops.h:283:11: error: expression cannot be used as a function

I have the following minimal example: #include #include #include enum my_enum { onething, otherthing }; int main(int argc, char const *argv[]) { std::array a_variable; if…
Max Matti
  • 352
  • 1
  • 4
  • 17
1 2 3
28
29