Excellent. I explored this feature about 12 months ago but was working with legacy code since so no chance to dive back in. The code; return { to_string(param)... }; is the part that caught my eye. (param)... those dots! :) I'll continue on with this series, its exactly whats needed to get this stuff understood (for me anyways). Watching compile time, symbol table and exe size, glaringly obvious but not something I have observed. Its now in my box of tools! :) Thank YOU!
Year and a half late, I could go for a 2-4 point increase in editor font. Otherwise great stuff, concise, good explanation, and nice pace. So many other videos either run through so fast your mind is occupied just attempting to unpack the words or they go off into the weeds and waste a bunch of time on trivial aspects often barely touching on the fundamental components.
About the increase in size of exe when using generic lambdas, cud it be due to every function call having local copy of lambda object, what if we passed that lambda by reference to generic to_string.
Something that seems overlooked in the standard is when using the 'using' keyword. You can't use the ... expansion operator on the variadic list when you want to expose for example a specific function which is available in all the types of the variadic template list.
This cast is indeed strange but needed. @@sinanlin7471 You get this error: "error: 'class std::basic_ostream' has no member named 'str'". Incredible :-/
You'll be amazed at the power of the vim force. With some tinkering and some basic vim knowledge of running shell commands from inside vim one can execute commands and redirect the output to split windows. vim.fandom.com/wiki/Display_output_of_shell_commands_in_new_window
You mean to say that if we are calling to_string_impl with 5 different parameters, then 5 different lambdas will be created? I have read somewhere that 'auto' uses the template deduction itself, so sort of makes sense. And obviously it won't show up in the symbol table unlike normal template function because it's inside the function scope.
that was good, particularly not having a canned response before you started. I find variadics and fold expressions very confusing, much more difficult to understand than C's original vararg idiom. I haven't tried this myself yet, but how does the compiler manage to return a vector of strings without apparently doing any allocations or push_backs?
@@SonaliProgrammingHub sorry, I didn't find that at all useful. It didn't tell me anything that I don't already know and it was mostly reiterating very basic concepts. Good luck.
@@treyquattro This is Part1 of variadic template function, I still I haven't completed this feature, might be when u go through part2 & part2, you might be finding useful.Thank you for feedback
I’m a beginner so I may be hugely misunderstanding the question and take my response with a grain of salt, but 1) return { whatever }; is shorthand for return ReturnType{ whatever }; 2) std::vector has a constructor accepting an std::initializer_list, which I’m assuming (???) is what is being called here. I don’t think it’s any different than typing something like std::vector{ 3, 5, 9 } or std::vector a = {‘a’, ‘n’}. You typically only need push_back when you want to populate your vector after construction. Otherwise, many std::vector constructor overloads exist to populate the vector right as its constructed.
This allows you to preserve the reference-qualification of parameters as they are passed in originally. Lvalues will be passed as lvalues and rvalues as rvalues.
nm has an option '-C' which automatically demangles the C++ names.
Excellent. I explored this feature about 12 months ago but was working with legacy code since so no chance to dive back in. The code;
return { to_string(param)... };
is the part that caught my eye. (param)... those dots! :) I'll continue on with this series, its exactly whats needed to get this stuff understood (for me anyways). Watching compile time, symbol table and exe size, glaringly obvious but not something I have observed. Its now in my box of tools! :)
Thank YOU!
Year and a half late, I could go for a 2-4 point increase in editor font. Otherwise great stuff, concise, good explanation, and nice pace.
So many other videos either run through so fast your mind is occupied just attempting to unpack the words or they go off into the weeds and waste a bunch of time on trivial aspects often barely touching on the fundamental components.
Variadic Templates Function in C++11:
ua-cam.com/video/bHoQBOjW_8k/v-deo.html
About the increase in size of exe when using generic lambdas, cud it be due to every function call having local copy of lambda object, what if we passed that lambda by reference to generic to_string.
This is so cool ! Thanks Jason !
Variadic Templates Function in C++11:
ua-cam.com/video/bHoQBOjW_8k/v-deo.html
Very useful, glad I stumbled upon this video
Something that seems overlooked in the standard is when using the 'using' keyword. You can't use the ... expansion operator on the variadic list when you want to expose for example a specific function which is available in all the types of the variadic template list.
That was added in C++17 ua-cam.com/video/1gNzhE-Tn40/v-deo.html
c++17 one-liner without lambdas:
_template_
_const auto to_string(const Param& ... param)_
_{_
_return std::vector{ (std::stringstream()
why it is compilable to cast an rvalue to a reference type? my mind exploded
This cast is indeed strange but needed. @@sinanlin7471 You get this error: "error: 'class std::basic_ostream' has no member named 'str'". Incredible :-/
Have any application for variadic templates in development , thank you !
g++ 7.2 produces less executable size with generic lambda ...
Would it be possible to use any ide, so you can see your code errors right away instead of wasting so much time to switch between vim and terminal.
But vim is so cool
You'll be amazed at the power of the vim force. With some tinkering and some basic vim knowledge of running shell commands from inside vim one can execute commands and redirect the output to split windows. vim.fandom.com/wiki/Display_output_of_shell_commands_in_new_window
Or just, ya know, another terminal window...
Possibly the creation of the different functor classes for the generic lambda resulted in the increased program size?
You mean to say that if we are calling to_string_impl with 5 different parameters, then 5 different lambdas will be created? I have read somewhere that 'auto' uses the template deduction itself, so sort of makes sense. And obviously it won't show up in the symbol table unlike normal template function because it's inside the function scope.
Nice explanation, can you please post a session for factory design patterns in c++ ?
Variadic Templates Function in C++11:
ua-cam.com/video/bHoQBOjW_8k/v-deo.html
Thanks for the great video. Did you know nm -C will demangle C++ for you?
Variadic Templates Function in C++11:
ua-cam.com/video/bHoQBOjW_8k/v-deo.html
that was good, particularly not having a canned response before you started. I find variadics and fold expressions very confusing, much more difficult to understand than C's original vararg idiom. I haven't tried this myself yet, but how does the compiler manage to return a vector of strings without apparently doing any allocations or push_backs?
Variadic Templates Function in C++11:
ua-cam.com/video/bHoQBOjW_8k/v-deo.html
@@SonaliProgrammingHub sorry, I didn't find that at all useful. It didn't tell me anything that I don't already know and it was mostly reiterating very basic concepts. Good luck.
@@treyquattro This is Part1 of variadic template function, I still I haven't completed this feature, might be when u go through part2 & part2, you might be finding useful.Thank you for feedback
I’m a beginner so I may be hugely misunderstanding the question and take my response with a grain of salt, but
1) return { whatever }; is shorthand for return ReturnType{ whatever };
2) std::vector has a constructor accepting an std::initializer_list, which I’m assuming (???) is what is being called here. I don’t think it’s any different than typing something like std::vector{ 3, 5, 9 } or std::vector a = {‘a’, ‘n’}. You typically only need push_back when you want to populate your vector after construction. Otherwise, many std::vector constructor overloads exist to populate the vector right as its constructed.
Please, tell me, what is this font you're using in this terminal? Looks awesome! I couldn't find it by myself.
It's probably source-code-pro from Adobe
@@cppweekly thank you.
Thanks, very helpful, although it took me some additional reading on Stack Overflow to understand the recursion.
Variadic Templates Function in C++11:
ua-cam.com/video/bHoQBOjW_8k/v-deo.html
I just revisited this old video and your series was cool back then too. Doesn't your long template perform an unnecessary copy in each recursion?
yea, basically this function has O(n^2) complexity
Thanks!
Thank you.
You're welcome!
Thank you
very clear, thanks.
Very Good Video sir...... Lekin kuuch samjh nahi aya....
I think newer version of nm or gcc lambdas are symbols
Very helpful.
what is use of forward(param)... ?
This allows you to preserve the reference-qualification of parameters as they are passed in originally. Lvalues will be passed as lvalues and rvalues as rvalues.
Thanks
I can't believe that I wasted brain cells learning this shit early in my programming career.
very good example . though i have seen this earlier but again its still cool
Variadic Templates Function in C++11:
ua-cam.com/video/bHoQBOjW_8k/v-deo.html
Java is betr
Java vs. C++? ...You really have no idea what you're talking about.
i guess you are talking about the Java island .. isn´t ?
u must be android developer. lol
@@raducusmir9059 i was joking lol
Java is an amazing coffee.