New drinking game: Take a shot everytime Cherno tells us he will cover it in a future video. :D
@iamk56865 жыл бұрын
I'd be falling out of my fucking chair.
@geiger215 жыл бұрын
I know it's quite funny, maybe little annoying but really, he can't cover everything in one video. We should be thankful for him even making those videos for free, for us. Hope you guys understand him.
@matanshtepel12304 жыл бұрын
ahhaha it's a suicide pact
@seditt51464 жыл бұрын
@@geiger21 Yeah it ain't no big deal to me man, I completely get it. Can't speak for others of course. I just thought it was funny and figured I would make light of it is all.
@matt-g-recovers4 жыл бұрын
I know right! It is comical and want to give him hell but I know how complicated this is and impossible to cover in a few minutes. I have to say he has covered quite a lot
@LordVysh7 жыл бұрын
Doesn't really matter what the size is. template void printArray(array a) { for (auto &i : a) { cout
@Dhruvpatel-gb4pv2 жыл бұрын
we can also use "auto&" in the function parameter.
@greysonyu56262 жыл бұрын
@@Dhruvpatel-gb4pv I actually don't know using auto in a parameter of a function is good or not, that sounds dangerous.
@Adam_Lyskawa2 жыл бұрын
@@Dhruvpatel-gb4pv I'm surprised, but it works. I just guess the compiler treats it as a kind of template. As long as you don't call it in the code, it doesn't check if the argument has a size function. Or if it provides [] operator. If you pass something that, when substituted for auto is not valid you just get a compiler error. I've just checked it - it behaves exactly like a template. I tried to create a header file and definition file containing a function with auto argument - it works only when it's defined in the header. So - you can use a proper template instead, or just leave auto. Compiler doesn't seem to care, however VS autocomplete prefers a template over auto.
@Sergeant_Mahdi Жыл бұрын
@@Dhruvpatel-gb4pv didn't work for me, I don't know why
@jiranmo894 Жыл бұрын
@@Dhruvpatel-gb4pv I tried at first. But it doesn't work. Visual Studio threw an error.
@dXXPacmanXXb7 жыл бұрын
The hardest part in C++ is deciding which thing to use
@iamk56865 жыл бұрын
So true man. I guess it just comes with practice.
@geiger215 жыл бұрын
that was big problem for me when I tried OpenGL. So I gave it a try in C. The difference is huge. I no longer need to decide whether to use std::vector, regular array, something else, I just need to use malloc and then eventually realloc. I like that simplicity.
@67hutch2 жыл бұрын
^^^^^^^^
@sophiacristina Жыл бұрын
@@geiger21 Well, you can write C++ codes without using STL stuffs...
@khatharrmalkavian33063 жыл бұрын
It's worth noting that the size() function is also constexpr, so it doesn't actually return 5, but rather the compiler will just replace the function call itself with 5, so something like: int s = ary.size(); literally becomes int s = 5; with no function call at runtime.
@bbx5617 Жыл бұрын
Thanks for the elaboration.
@toao_rainys Жыл бұрын
what’s the difference between inline and constexpr then?
@AndreiSokolov-k7j10 ай бұрын
thanks bro from steins gate
@khatharrmalkavian330610 ай бұрын
@@toao_rainyssorry for the delayed response. I didn't get a notification for this comment. inline means "please copy this code body into the places that call it instead of having it be an actual function call" and constexpr means "please calculate this out at compile time instead of figuring it out at runtime". This is strongly preferred to declaring constants with #define, etc. These days you don't really need to tell the compiler to inline, as it will do so when appropriate, and if it's not appropriate then it will ignore the directive even if you use it.
the best solution in my opinion is this: template void PrintArray(const std::array& data) { for(int i = 0; i < data.size(); ++i) { } }
@alanyoung70455 жыл бұрын
will not work, replace it with
@fluffypinkpanda285 жыл бұрын
@@alanyoung7045 Why so? Can you explain a bit more? I'm interested.
@rysiexo5 жыл бұрын
template void printArray(T(&arr)[size]) { } I know, I digged your comment up, yeay a golden shovel for me.
@CacheTaFace24 жыл бұрын
@@rysiexo Hey, I'm new to templates. What is this syntax you are you using in the printArray parameters list (T(&arr)[size])?
@t0msa4 жыл бұрын
@@alanyoung7045 or just call it template, since size_t is just a typedef of unsigned integer
@yusinwu7 ай бұрын
I think there is one crucial thing to note: Bounds checking with std::array [] operator is not guaranteed in debug mode. If anyone wants to make sure that they have bounds checking, they should use the .at() instead of the [] operator to access array elements since bounds checking with .at() method is required by c++ standard, but it is not the case for the [] operator. Bounds checking is always enabled with .at() method, regardless of the build type of your program, meaning it's built into the program even when compiling in release mode with compiler optimization. For MSVC, as @cherno has shown, the [] operator supports bounds checking and disables it during release builds. But for the compiler I am using, which is GCC, bounds checking is completely none-existent with [] operator. Anyways, thanks for your awesome videos. I have learned a lot from your content and your videos are with all seriousness life-changing to me.
@imankalyanmaity5 жыл бұрын
template void PrintArray(std::array& arr) { for (int i = 0; i < arr.size(); i++) { std::cout
@Cheddar20125 жыл бұрын
Imankalyan maity To improve on this, you could just use N in your for loop instead of arr.size(). This way, you do not incur any runtime cost of evaluating the size() function and instead just use an int literal.
@valizeth40735 жыл бұрын
@@Cheddar2012 You should always used unsigned integers to keep the size, but nevertheless this was pretty much the solution.
@traywor5 жыл бұрын
@@Cheddar2012 I bet arr.size() is a constexpr, so no runtime cost anyway.
@Nick-kq8pg4 жыл бұрын
@@valizeth4073 Is there a cpu cost difference between signed and unsigned, or are you just saying out of principle?
@serkratos12164 жыл бұрын
That doesn't work for me.
@ToyMachine221224 жыл бұрын
Without checking if this compiles, I think the answer to the question at 4:00 is template void PrintArray(const array& data) { // Do Stuff } Amirite?
@cockoroach4 жыл бұрын
This is what I came up with, too. Unless we wanted to modify the array, but that’s an easy fix lol
@Sergeant_Mahdi Жыл бұрын
explanation to your question: We use template to get the data and size template void print( const std::array & Data) { for ( T i : Data) std::cout
@Katniss2184 жыл бұрын
"Stacks are stored in the arrays" - Cherno 2018. Well.. He *almost* said it.
@expurple4 жыл бұрын
As most of the guys here have guessed, the correct way to print an std::array is to use a template function. Hohewer, I need to show off, so here's a function to print any iterable collection passing its begin() and end() . template void printCollection(Iterator first, Iterator last) { for (auto it = first; it < last; ++it) { std::cout
@VarunSingh0004 жыл бұрын
that's like . . . pythonic? idk
@expurple4 жыл бұрын
@@VarunSingh000 I don't know Python much, but this reminds me of C#'s methods for working with any IEmumerable collections. It's better than C++ STL way like in my example, as from the outside you just pass a collection itself, not these two separate "begin" and "end" things. And this collection later provides means to iterate over itself, but this happens INSIDE of a method. So iterators are hidden, as all implementation details should be. Python is a beautuful language, by the way. I just prefer typed languages
@kzm19343 жыл бұрын
I think the best solution to the array size function parameter function is to make use of auto declarations as function arguments from C++20. The below compiles perfectly (tested on gcc): #include #include void PrintArray(const auto& data) { std::cout
@mario_luis_dev2 жыл бұрын
you may want to reconsider using unnecessary if-else statements, as those seriously slow down your code.
@@germanassasin1046This is mostly untrue. If/else statements are nearly ALWAYS more performant if written branchless. The branch prediction will do most of the heavy lifting, but an if/else nearly always ends up as a test/je/jnz. In the above example the predictor is only "warming up" on such a small array so branchless will out perform if/else. On a larger array, well, now you start to get a win/break-even with branchless because the condition only occurs at the end of the array. But start to use variable sized arrays and branchless will always will however good your optimizing compiler is. The downside to branchless is really the complexity and understandable logic.
@thewelder3538 Жыл бұрын
I dislike this C++20 feature badly. Now you completely obscure what the incoming argument type is. It's one stage away from writing ... auto i = 0 and use auto everywhere.
@TheHeadHunter1057 жыл бұрын
Have you considered making a tutorial on CMake? It might come in very useful for people looking to do cross-platform projects
@pedrocalorio16553 жыл бұрын
what is cross-platform projects? is it the same as mixing languages in a project?
@danielji27423 жыл бұрын
@@pedrocalorio1655 cross platform = windows, mac or linux + others
@felipebonilla76792 жыл бұрын
@@pedrocalorio1655 It reffers than you don't depend on the IDE+OS to have a proper portable project. Due to Make is cross platform, and some IDEs are too (like VSCode), you can set up an environment of c++, make and visual studio code in any OS.
@thewelder3538 Жыл бұрын
CMake is just for people who aren't good enough to write a proper makefile.
@עומרפריאל4 жыл бұрын
In 4:17, You can use Template
@AdityaKumar-xw2yx10 ай бұрын
Great!! so sensible. I would like to add two point, hope you will be aligned with me. 1. Usage of static_assert and assert Functions with std::array: static_assert and other assertion functions work effectively with std::array because its result is a compile-time constant, and conditions are evaluated at compile time. Since std::array has a fixed size known at compile time, it is suitable for use in compile-time checks like static_assert. 2. Applicability of constexpr with std::array and std::vector: constexpr can be effectively used with std::array as it is resolved at compile time and its size is known at compile time. On the other hand, std::vector is a runtime container, and its size is determined at runtime. Therefore, it is not suitable for use in constexpr contexts.
@DrAuraHxC7 жыл бұрын
using gsl::span of the Guidelines Support Library (is a Microsoft implementation of some of the types and functions described in the C++ Core Guidelines)
4:03 I was randomly trying stuff, and the one that executed without compile time error was to make the printArray() function a template with size and types as parameters like so: template printArray(const std::array &array) {}
@TuanAnh-oj4ps5 жыл бұрын
template void PrintArray(T& a) { for (int i = 0; i < a.size(); i++) { std::cout
@koungmeng5 жыл бұрын
you can use initializer list just like array: eg: std::array arr{1,2,3,4,5}; or: std::array arr = {1,2,3,4,5};
@callingpizza3 жыл бұрын
4:20 solution: template void PrintArray(std::array data) { for (int i = 0; i < _Size; i++) std::cout
@fireballgfx Жыл бұрын
template void foo(std::array){...}
@jannesopanen80324 ай бұрын
For regular arrays, you can increase its size by one and add one special character at the end of it. Inside printArray() just loop until you hit special character and voila you have the correct size. You must use the type of the array element to calculate the correct size. Its not very fast I think but it works.
@jannesopanen80324 ай бұрын
Or you can assign the size of the array to the first element of array.
@vikramkumarbathala54326 жыл бұрын
template void print(array&array){ int size = array.size(); for (int i = 0; i < size; i++){ cout
@Erebus20755 жыл бұрын
awesome series. you should edit out the "challenges". not many watches youtube guides to be told to google or find another vid explaining the details of the vid you are watching to learn the details ;) but awesome c++ series ^^
@bingusiswatching63359 ай бұрын
You can get the size of an array by dividing the total size by the size of one element which works cuz its contiguous memory: int size = sizeof(arr)/sizeof(arr[0])
@DenysYeroshenko3 жыл бұрын
Thank you, i am grateful that there is person such you. It really helps to figure out in c++
@harshkn7 жыл бұрын
Solution to pass the size as param when using STL Array. Pass the size as a template. Example template void PrintArray(std::array& data) { /* do something* / }
@alexkiecker41757 жыл бұрын
Here is one ^^
@VanYang-eq5ub Жыл бұрын
template void func(const std::array& arr) { cout
@aryanwolfox63903 жыл бұрын
Answer is by template : template void printArray(const std::array< T, size >&data) { // now we don’t need to pass type and size explicitly }
@169mayan5 жыл бұрын
My Solution: template // cant use int instead of size_t because the size of container(std::array) is in *size_t* void printData(std::array& data1) { for(auto val : data1) std::cout
@michaelswahla4927 Жыл бұрын
I attempted the challenge using a template function and extra feature for type of the array too: template void printArray(const std::array& arr) { for(dataType& value : arr) { std::cout
@egor.okhterov4 жыл бұрын
Iterator mimics pointer arithmetic, so std::array iterators are not an advantage over usual c++ array, but a way to get closer in functionality to the usual c++ array. All standard algorithms, like sort(), work on bare c++ arrays: int a[] = {3, 2, 1}; sort(a, a + 3); // it works
@kitlaw24945 жыл бұрын
You could write it using a template: This has the drawbacks of longer compile time (not that noticeable) and the exe file would be slightly larger because every different variant of that function needs to be created and compiled. Right? template void PrintArray(const std::array& data)
@avocadopeel75363 жыл бұрын
To the people suggesting templates with std::array, why not template void PrintArray(int *array) { for(int i=0; i
@ashrafrasulov43532 ай бұрын
my version of the answer to the question is: what if I recreate it whenever I use or change it every time, like a static variable. creating a new pointer and pointing to the new pointer then removing an array old version.
@PythonPlusPlus6 жыл бұрын
To get around the problem of not knowing the size of the array, you can add a template to your function which asks for the array size.
@swackyduk Жыл бұрын
then of course use a for(auto& element : array) loop
@Deeredman42 жыл бұрын
I think that if you don't know the size, you can either use a template or a macro but I think you have explicitly said that macros are mostly bad except for debugging and too much templating can become dubious. Based on my current knowledge I would probably use a template.
@skipdrill3732 жыл бұрын
Yes!
@mamertvonn4 жыл бұрын
3:50 so does anyone know the answer? Pls enlighten me. Is it just templates?
4 жыл бұрын
My solution would be a bit more general purpose: template void PrintArray(const std::array& array) { for(auto& x : array) std::cout
@RiverBeard4 жыл бұрын
can we just print until we hit the terminating zero? 4:20
@kishanthakur__78134 ай бұрын
template void PrintData(const std::array& data) { for(int i = 0; i < data.size(); ++i) { std::cout
7 жыл бұрын
I think you should make qt and qt-opengl tutorial.
@munjalparmar845510 ай бұрын
can we have template there.
@goldenlava10194 жыл бұрын
Templates (: template void PrintArray(const std::array& data) { for (int i = 0; i < data.size(); i++) std::cout
@bessermt4 жыл бұрын
It is quite easy to get the size of a standard C array by sizeof(array)/sizeof(array[0]) or there's a C++ standard library method if you prefer.
@bessermt3 жыл бұрын
@Ralph Reilly A decayed array is not an array so your comment is a non sequitur.
@yannisgoogleapps924918 күн бұрын
Oh god, you put me on the spot with the question xD Maybe with templates?
@tamriel_x5 жыл бұрын
something strange is happening here.. when i turn on subtitles it only allows russian, when i change it to auto gen russian to >>English, the only subtitle that comes up is "high five i have beyonce and funding"+"intensive and accessories and frill"+ "new style extract"+"whats the trouble"+ "he contracted st"+"bad girl i like slow mo guys"
@CriticRoshun3 жыл бұрын
template void PrintArray(const T& arr){ for (int i=0; i
@OneShot_cest_mieux5 жыл бұрын
How do writing template void PrintArray(const std::array& data) {...} and then PrintArray(data); will work ? I thought it should be wrote like that: PrintArray(data); Sorry if my english is bad I am french
@zlfu30205 жыл бұрын
As far as I understand, value of size is deduced before compiling, so you dont have to specify.
@Luca-hn2ml4 жыл бұрын
Class template argument deduction (CTAD) (since C++17): As Zhuolin Fu said, in THIS case the compiler is going to deduce the template argument from the type of "data".
@vivekkumar-bq2ln3 жыл бұрын
Isn't adding too many std::array with varying sizes (say for the same data type) will increase the size of program memory (code segment)? The size stored as a literal in the compiled program and that template is for every size type at the cost of program size.
@KillzoneKid7 жыл бұрын
template void PrintArray(std::array array)...
@voidnull73294 жыл бұрын
Make a video on naming conventions for c++ like function name ,class ,private member,..etc
@ashrafrasulov43532 ай бұрын
Thank you for your lesson, it perfect. Super...
@MartialBarts7 жыл бұрын
When can we expect a video on namespaces? They seem like such a powerful tool especially when wanting to optionally include libraries. I am sure there are many other uses beyond just code structure. Other topic I would like to see is the exploration of extern "C" to prevent name mangling. Why is this used so much? What benefits/drawbacks does it provide. Thanks for the vids. Been a good supplement to my learning by providing good context to concepts.
@The_Codemaster144k2 жыл бұрын
Not sure if you still have this problem 4 years later, but he has a dedicated video in the learning C++ series that you should take a look at. Coming from C# namespaces used to confuse me in C++
@milosorevic927 Жыл бұрын
void PrintArray(const auto& data) { for (const auto& value : data) { std::cout
@valizeth40735 жыл бұрын
Just gonna mention that the size is almost impossible to determain for a pointer, there are tricks but they are definitivly not guaranteed to reveal the size. That's why you always write: (int argc, char** argv). The argv is just an array of string, but the size is unknown, so argc is passed as the size for argv.
@misana776 жыл бұрын
You're not right. You can use standard algorithms with C-style array. For begin iterator you use a name of an array and for the end one - name + size. To use differently sized std::array's in one function you need to make this function a template one like this: template void func(const std::array arr); But you can use it for C-style arrays either: template void func(int arr[size]); But yeah, the debugging layout is useful
@CoolDude9115 жыл бұрын
Arrays should be constant at compile time so whatever size the array is should be tied to some constant.
@rakeshtm27504 жыл бұрын
We can use "auto" in function parameter as of C++14 instead of mentioning the type name and array size.
@aryesegal19887 жыл бұрын
Cherno, bruh, correct me if I'm wrong but isn't returning 5 actaully means the function stores this constant internally as an int? So yeah, it is not a variable in the sense that you can not change its value, but still, it must store this value somewhere. (Perhaps as a 'const int'.) I mean, what does a compiler do when it encounters a constant like 5 through code? Doesn't it store it somewhere? Thanks for all the effort you're taking to share with us. This channel is awesome! And fix that AC! ;)
@Tom-um7zd6 жыл бұрын
It is just CPU instruction, so its hard-coded in your binary file. It wont be stored in memory at all. compiler gives you just assembly code, something like: add ax, 42 (add 42 (2E) to accumulator) which looks in binary file like this (HEX): 05 2A 00
@jovialcupid9687 Жыл бұрын
Challenge accepted: Use for each or just calculate size of the array. I'm I stupid and I'm not understanding something or what? Void printArray( int* arr) { for (auto i: arr) serial.println(i); // or For (int I = 0; I < sizeof(arr) / sizeof(int); i++) //Int is default cuz this is parameter type, u can make template out of it }
@gage25607 жыл бұрын
template void func(std::array& array) { std::cout
@nathanm9887 жыл бұрын
THAT IS GENIUS!
@PythonPlusPlus6 жыл бұрын
This would work, however you should probably use something other than T because is is meant for Type names.
@misana776 жыл бұрын
And yeah, it's not necessary to pass the template argument to a template function, because the compiler calculates it itself at the compile time. However, you have to pass template arguments, when you create an object of a template class. So, the function call like this - func(testing) - will work just fine.
@stavroscho77982 жыл бұрын
You can set the size with a template
@venkateswarans10125 жыл бұрын
We should use template to pass STL array with size to function in C++11 or we can use auto keyword in C++17
@creatork9994 жыл бұрын
template void Print(std::array& arr) { for (int i = 0; i < Size; i++) { println(arr[i]); } }
@skewbinge61572 жыл бұрын
templates right away answer thanks to you man
@mattt26846 жыл бұрын
4:18 maybe try using a void* to the reference of the array and then go from there...
@Netrole5 жыл бұрын
Go how far though? That is the question, and also why we need the length
@platin21487 жыл бұрын
You should probably use complier explorer for showing code that is compiled. Real difference between an Fixed size array and a pool allocator?
@LucidStew7 жыл бұрын
10mins is a good length. Didn't feel short.
@cocbuilds6 жыл бұрын
To answer 4:20, would you just not specify the size in the angular brackets? Or perhaps you'd make PrintArray a function taking a template argument?
@tomhaswell62834 жыл бұрын
template is correct. Otherwise your code would get pretty messy.
@benjitigg34904 жыл бұрын
my solution is: template void PrintArray(const std::array & data) { for (int i= 0; i < N; I++) { std::cout
@rcookie51287 жыл бұрын
nice overview once again! ^^
@matrix9140 Жыл бұрын
Solution to your question: #include #include template void Print(const std::array& arr) { for (int i = 0; i < arr.size(); i++) { std::cout
Yeah, thanks) Fixed it. I forgot that *value_type* of *std::set* is Key in constructor. But *std::map* needs additional processing anyway.
@Ghasakable11 ай бұрын
Passing as a const int for the size as const int size = 5; void print_std_array(std::array my_array) { for (size_t i = 0; i < my_array.size(); i++) { std::cout
@maga82893 жыл бұрын
You can pass the address of std::array as void* ptr in function argument and by knowning the offset of size inside array class you can find it like this: int size = *(int*)(uintptr_t(ptr) + *size_offset*)
@ДмитроПрищепа-д3я2 жыл бұрын
you surely can, but why? You can just make that a template function and pass a reference to the array and make the compiler infer the size.
@maga82892 жыл бұрын
@@ДмитроПрищепа-д3я Да, меня что-то понесло. Можно и так)
@thewelder3538 Жыл бұрын
@@ДмитроПрищепа-д3яYou could do this, but the problem is that you're relying on the internal structure of the array object. Now whilst this might work, if you used a different compiler that lays out the object structure differently, it'll break badly. I'm not objecting completely because using a pointer is easily the most efficient way of passing the array object. The problem really is that inside the function, you have to cast it back and as a void pointer, you don't know its actual type. A template is a good idea, but it's only really the same as having a function take an array and size argument.
@OneShot_cest_mieux5 жыл бұрын
I do have questions about performances: 1/ Imagine you want to create 1000 array with differents size. Because of the template behavior, wouldn't it copy theses 500 lines of code every time and makes your executable much much larger ? 2/ When you do data.size() in the for loop, because it is not an "inline" function doesn't it makes a function call every time it reaches data.size(), making your code slower ? Same question with the operator[] which is a not inline function Thank you for thoses who will answer me and sorry for my bad english, I am french and I try to improve myself.
@valrossenOliver7 жыл бұрын
My solution looks like something like this: (in this case its always ints, but you could do a typename version too) template void PrintArraySize(const std::array& data) { for (size_t i = 0; i < data.size(); i++) { std::cout
@valrossenOliver7 жыл бұрын
For a version that takes any type we could write: template void PrintArraySize(const std::array& data) { for (size_t i = 0; i < data.size(); i++) { std::cout
@tommymuir67506 жыл бұрын
I realise this video is 10 months old, but I wanted to point out you can just use the auto keyword, no template needed: void PrintArray(const auto& data) { for (int i = 0; i < data.size(); i++) { cout
@gravity58986 жыл бұрын
@@tommymuir6750 I too tried this but msvc says that 'auto' keyword isn't allowed here.
@JimitRupani5 жыл бұрын
@@tommymuir6750 why constant I mean why not without constant. Anyway array will be in local scope so why to use constant in particular
@mario_luis_dev2 жыл бұрын
I don’t think std::arrays do bounds checking using the overloaded [] operator. You would have to use the `at(i)` method instead of [i].
@Nick-tv5pu4 жыл бұрын
4:15 Using a template?
@samiam40397 жыл бұрын
obj c stl array constructs allow for compile time checking for array sizes and types in its functions.
So i figured i could use void PrintArray(auto array) { ... } to print any array. However... I'm not sure why, but this seems to have problems as my IDE marks it as error and my compiler yells at me for using it even so the code compiled and worked just fine. Compiler said: 'warning: use of 'auto' in parameter declaration only available with -fconcepts'
@breakmon2187 жыл бұрын
Are you going to talk about linked list? :))
@paragggoyal1552 Жыл бұрын
but the issue is we should know the size at compile time, if we don't know the size at compile time, we cannot specify the size in template argument.
@VanYang-eq5ub Жыл бұрын
so let's use template!by using template,we can do it when we creat it,not in complie stage
@KGhary5 жыл бұрын
passing array as const pointer its like passing const char pointer and its mean string array
@yufang91094 жыл бұрын
A solution to handle both value type and array size template void printArray(const std::array& array) { for (int i = 0; i < N; i++) { std::cout
@valforeststorm69085 жыл бұрын
I know this video is oldish but I will still do the challenge. I tried using "auto" it works but I still get a warning though. did I win???
@valforeststorm69085 жыл бұрын
//never mind I used a template template void print(size& data){ for(int i = 0; i< data.size(); i++){ std::cout
@Ghasakable11 ай бұрын
How about without using templates, we pass as const int variable, which can passed to the function easily: like ``` const int size = 5; std::array my_array{1, 2, 3, 4, 5}; for (size_t i = 0; i < my_array.size(); i++) { std::cout
@cactusmamelu3133 жыл бұрын
Forty degree, finally a sane person that doesn't use square feet by crate inch type of unit !
@rishimenon56325 жыл бұрын
Since its a template, it produces different copies, right? So would the intermediate object file and/or the executable file occupy more space?
@gooseman55785 жыл бұрын
on tests vector show same performance as array
@VanYang-eq5ub Жыл бұрын
it totally can work pretty well。
@alltheway994 жыл бұрын
@Cherno : please do a STL container comparison video
@meer_kat51583 жыл бұрын
Hi, if std::array is stored on stack, how is this code valid? std::array f() { return std::array {1, 2, 3}; }
@_Omni3 жыл бұрын
You create a copy..
@cisimon73 жыл бұрын
late to the party, but I'd go about the problem as below: template void printArray(std::array& data) { for (int i = 0; i
@Zero-yi5gw4 жыл бұрын
Are you using visual studio? If so, how is yours running so fast, mine takes like 4 seconds to realize there is an error somewhere. Whereas yours seems to highlight it in red immediately. How did you make it run so fast?
@Artem Katerynych It's pretty important that I specify I use visual STUDIO, not visual studio CODE, which is way faster because its more lightweight. Maybe that's what hes using, with a few extensions...
@Zero-yi5gw4 жыл бұрын
@Artem Katerynych Very weird. How the fuck is a laptop faster than my pc...
@tralamysamy84653 жыл бұрын
The best solution with C++ 20 ➡ void PrintArray (const std::span& data) { for (auto& : data) { std::cout
@perajarac Жыл бұрын
hope u got aircondition after 5 years of hard work