[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


Janitor application acceptance emails are being sent out. Please remember to check your spam box!


[Advertise on 4chan]


File: IMG_5003.png (647 KB, 670x767)
647 KB
647 KB PNG
#include <array>

std::array<int, 3> arr = {1, 2, 3};
>>
of course she has an std
>>
>>107270042
Use case for static typing?
>>
>>107270083
Your compiler will say thank you for not having to do your job.
>>
std::array unironically has no usecase. It's just bloat.
>>
>>107270376
the use case is when you want a fixed size array that has duck type compatibility with other stl containers
>>
>>107270386
What makes you think that duck typing compatibility is a metric?
>>
>>107270386
>introduce bloat
>we need more bloat to support existing bloat
>>
>>107270376
Returning an array from a function

>>107270386
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.
int main() {
int arr[] = {1, 2, 3};
for (int i : arr)
printf("%i\n", i);
}
>>
>>107270042
>aquatroon
shitting up /v/ wasn't enough ?
>>
>>107270376
the 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
>>
>>107270376
The 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 array
return a pointer, jeez
>>
>>107272799
stack-allocated arrays always have known size
sizeof arr / sizeof arr[0]
git gud
>>
>>107270042
it's literally superior to C in every way, same with spans.

cope C shitter.
>>
>>107272872
>return a pointer, jeez
ok, 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.
>>
>>107273151
If 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.
>>
>>107270042
Nigger
>>
>>107272890
>error prone calculation
>stops work due to array decay
C++ won, Rust won. Move the fuck on retard.
>>
>>107272890
>>107273252
const 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.html

Again, strong type-safety is present throughout.
>>
>>107273623
Based and auto pilled.
>>
>>107273991
Heh. 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.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.