#include <array>std::array<int, 3> arr = {1, 2, 3};
of course she has an std
>>107270042Use case for static typing?
>>107270083Your compiler will say thank you for not having to do your job.
std::array unironically has no usecase. It's just bloat.
>>107270376the use case is when you want a fixed size array that has duck type compatibility with other stl containers
>>107270386What makes you think that duck typing compatibility is a metric?
>>107270386>introduce bloat>we need more bloat to support existing bloat
>>107270376Returning an array from a function>>107270386Range-based functions work on c-style arrays as well, because std::end/std::begin have overloads for themFor range-based for, you don't even need to include anything.int main() { int arr[] = {1, 2, 3}; for (int i : arr) printf("%i\n", i);}
int main() { int arr[] = {1, 2, 3}; for (int i : arr) printf("%i\n", i);}
>>107270042>aquatroonshitting up /v/ wasn't enough ?
>>107270376the use-case is that when you copy a class/struct with an std::array it will automatically copy the array as well without having to define your own copy constructor
>>107271032>Range-based functions work on c-style arrays as well, because std::end/std::begin have overloads for them>For range-based for, you don't even need to include anything.That only works when you have arrays with a know size yes, but try passing that into another function and then use a ranged for loop on it
>>107270376The fact that it always knows it's own size (unlike the brain-dead C array) is MORE than enough of a """usecase""".
>>107271032>returning an arrayreturn a pointer, jeez
>>107272799stack-allocated arrays always have known sizesizeof arr / sizeof arr[0]git gud
>>107270042it's literally superior to C in every way, same with spans.cope C shitter.
>>107272872>return a pointer, jeezok, where do you return size info? what happens when you accidentally return a stack allocated pointer?in c++auto func() -> std::array<Type, Size> just works as well. no need to have inout's or any other C shitter cope. NRVO is also a thing so it isn't even inefficient.
>>107273151If you absolutely need to return the size (which you don’t, write better code), then just create a struct that stores that size with a pointer and return it. But again, you don’t need to do this unless your code is shit.
>>107270042Nigger
>>107272890>error prone calculation >stops work due to array decayC++ won, Rust won. Move the fuck on retard.
>>107272890>>107273252const int BOOBS_SIZE = 2;int boobs[BOOBS_SIZE] = { 1, 2 };int *booba = (int*)malloc(BOOBS_SIZE * sizeof (int));void motorboat(int *pBoobs, int count);niggers
>>107273252>error prone>stops work (ESL lol)A bad craftsman blames his tools.
>>107273151>auto func() -> std::array<Type, Size>You don't even typically need to know even that much information for strongly-typed returns to work in C++, Anon.auto func(auto arr) -> decltype(arr){...}...int main(){ std::array<int, 3> arr{1, 2, 3}; auto foo = func(arr);}https://en.cppreference.com/w/cpp/language/decltype.htmlAgain, strong type-safety is present throughout.
auto func(auto arr) -> decltype(arr){...}...int main(){ std::array<int, 3> arr{1, 2, 3}; auto foo = func(arr);}
>>107273623Based and auto pilled.
>>107273991Heh. It kinda took them till C++17 until you could use it this fluidly everywhere, but they did get it done in the end. Also AFAICT almost all the companies I know of are using C++17 as well now, so yeah.