Anonymous
#cppbookguide
https://www.github.com/mgood7123/PDF/tree/master/C https://www.github.com/mgood7123/PDF/tree/master/C%2B%2B
Anonymous
Hello
Anonymous
I have being trying for a code since 2 hours
Anonymous
It’s passing sample cases but failing for hidden test cases
Anonymous
Can someone over here help me?
Anonymous
Your a beginner
do you know what i've learned and what i haven't?
Anonymous
stop fcking judging by the class im in mate
MRT
🤣
Sandeep
#include <iostream> #include <vector> #include <algorithm> void ForEach(const std::vector<int>& values, void(*func) (int)) { for (int value: values) func(value); } int main() { std::vector<int> values = { 1, 5, 4, 2, 3 }; int a = 5; auto lambda = [=](int value) { std::cout << "Value: " << a << std::endl; }; ForEach(values, lambda); std::cin.get(); }
Anonymous
"I want to learn something stunning"
haven't you ever thought of a program to impress your classmates?
Anonymous
i was just asking for projects ideas m8
Anonymous
A dynamic linker for Musl libc is fairly easy to make A dynamic linker for GNU libc is more difficult
Pavel
For each function is taking a function pointer as parameter..then why cant I pass lambda As a parameter
Lambda is not a function, lambda is a class that has operator(). Lambda that doesn't capture anything can be treated as a function, but in your case you capture a, that means it can't be. Because it now has storage that need to be also passed to the function, and pointer to a function is not enough to pass it Paste some lambda here and see how it looks without syntax sugar https://cppinsights.io/ By the way, it's usually not a very good idea to use default capture list [=] or [&], and better to capture values explicitly when possible, because the default capture lists make it easier to do a mistake that will be difficult to find looking at the code.
Sandeep
Let me guess, you want to take any arbitrary function with any number of arguments?
No..in the tutorial..he was telling how to acces the variable a eventjough it is outside the function
Anonymous
Does it specify that you cannot pass the variable itself to the function?
Sandeep
Does it specify that you cannot pass the variable itself to the function?
It's not a problem.he is he is explaining lambda functions
Anonymous
So basically Using lambda, access a variable ?
Anonymous
Send the link to the tutorial
Sandeep
So basically Using lambda, access a variable ?
Should I send you the video..I didn't understand it that
Pavel
No..in the tutorial..he was telling how to acces the variable a eventjough it is outside the function
You can pass it as std::function<void(int)> type (you need to include <functional>), instead of function pointer
Sandeep
https://youtu.be/mWgmBBz0y8c
Sandeep
https://stackoverflow.com/questions/28746744/passing-capturing-lambda-as-function-pointer
Anonymous
https://youtu.be/mWgmBBz0y8c
6:57 he actually specifies that you are MEANT to get that error, then he SHOWS you how to fix it
Sandeep
Lambdas are just classes with operator() overloaded? - Stack Overflow https://stackoverflow.com/questions/45831371/lambdas-are-just-classes-with-operator-overloaded
J
Does anyone benchmark c++ code? I am searching a tool to do benchmark breakdown. Google benchmark is very cool, but it can only time a single event. Is there anything, similar as google benchmark, can track multiple function calls individually?
Nameful
How would I copy a std::string into a std::u16string?
Nameful
Not byte for byte
Nameful
And if not that, how would I read from stdin and put that data into a std::u16string?
Nameful
std::cin doesn't seem to work?
Nameful
https://www.cplusplus.com/reference/string/basic_string/assign/
Nameful
Looking here it looks like I should just be able to do .assign() with the std::string, but it tells me there's no known conversion from const string* to std::initializer_list<char64_t>
Nameful
And of course, the minute I send a message here some random asks me to do their exam
Anonymous
I dont know how to get rid of the templates tho ;-;
Sandeep
I dont know how to get rid of the templates tho ;-;
Use standard functions like @gameraccoon said
Anonymous
them templates doing magic
Anonymous
the best i have is this ;-; void (*lambdaCFP)(void*, int) = (void(*)(void*, int)) lambda_ptr_exec<void, &lambdaC>; error: insufficient contextual information to determine type
Anonymous
ah well the template version magically works so no reason to decypher it :)
Anonymous
Thankyou
credits to this magical god https://stackoverflow.com/a/33047781
Pavel
Like lambdas in general or lambda in my code
As they said in the answer by the link you sent, if lambda captures something, it can't be converted to function pointer. In general.
Pavel
Yeah got it...can you explain more about the overloaded () thing
You can overload operators (you can read about operator overloading). You can overload operator() for your class, so you can call it on objects of your class so it will look like you call them as a function. std::function and lambdas do that, and you can make a similar to std::function class yourself if you want.
Anonymous
Yep, that can be done in C
I know it works. I did this as a joke when I first learned C in the early 1980s.
Shahar
Can someone give a concrete example to the need of using __ (double-underscore prefix) prefix?
Pavel
Can someone give a concrete example to the need of using __ (double-underscore prefix) prefix?
It is for compiler internal stuff, if you are making a compiler and want to make sure your internal things never collide with user code, then you can use double underscore as a prefix for them. If then some programmer try to define their stuff with this prefix and it will collide with your stuff, it's the problem of the programmer, not yours, because they should never use this prefix in normal code.
Cris
Hi all :)
Akshay
/get
Hanz
/get
Hanz
/get Rose's Heart
Yasas
/notes
Yasas
/get imhacker
Yasas
/get cp
z
/get mcve
Yasas
/get cpp
Yasas
/thanks
z
/get gcc9
z
/get goodgoogling
Talula
I know it works. I did this as a joke when I first learned C in the early 1980s.
Cool, in 1980s wtf I thought I was older… how old are you?
Rakesh
-cbook
Anonymous
Which is very powerful language C or c++
Anonymous
And which is toughest language
Cris
And which is toughest language
they are both "tough" languages. c++ deals with more details and offers you different ways to approach a problem (imperative, oop, functional...) but c has a wider support especially for small electronics devices. IMO they should not be seen as competitors, but as two different tools that you can use to solve a specific problem. if I may, why the question?