Tomay
I am new here,
Tomay
But I have one question for the moment,
Tomay
I don't get the differences between auto, auto& and auto&&, and what it is used for for loop iterators? Can you explain it to me in a more easy way (Because I don't get the cppreference.com web ones).
Mar!o
auto&& allows perfect forwarding for example consider: #include <vector> int main() { std::vector<bool> v(10); for (auto& e : v) e = true; } This doesn't compile because rvalue vector<bool>::reference returned from the iterator won't bind to a non-const lvalue reference. But this will work: #include <vector> int main() { std::vector<bool> v(10); for (auto&& e : v) e = true; }
Mar!o
auto& is just a reference while only auto is working with copies
Anonymous
How to insertion and deleting operation in "linked list" using 'c'
Anonymous
I don't get the differences between auto, auto& and auto&&, and what it is used for for loop iterators? Can you explain it to me in a more easy way (Because I don't get the cppreference.com web ones).
you won't really use auto && inside a for loop. either auto is used or auto &. auto when the type is small and copying is better (example - built-in types such as int, float), auto & when the type is larger (example - std::vector).
Anonymous
you might also use const auto & sometimes to avoid accidentally changing the value
Tomay
I lost internet for an hour.
Tomay
Thank you guys for the answers, but could you please agree on something!
Tomay
Here is what I understood: 1 - To deal with types by copy, like the small ones : bool, int, float, double... I simply use "auto". 2 - To deal with types by reference, like the ones std::string, std::vector... I should use "auto&", but if the compiler complains about it, then I should use "const auto&" UNLESS I want to modify the reference content, then in this case I should finally use "auto&&". @pinsrq and @chandradeepdey, correct me please I am wrong.
Jaime
Good night
Anonymous
I don't get the differences between auto, auto& and auto&&, and what it is used for for loop iterators? Can you explain it to me in a more easy way (Because I don't get the cppreference.com web ones).
If you are familiar with templates, then this would be a perfect analogy template<typename T> void fun(T param) The deduction of type of param based on some argument to fun would be what is deduced by auto a = arg; //auto deduces the same type //as deduced for param when //called like fun(arg) template<typename T> void fun(T& param) auto& a = arg; //auto deduces the same type //as deduced for param when //called like fun(arg) template<typename T> void fun(T&& param) auto&& a = arg; //auto deduces the same type //as deduced for param when //called like fun(arg) The last case is when perfect forwarding happens. There is one scenario where auto and template type deduction differs. It is when you pass a braced initializer list but that is a corner case.
Anonymous
Here is what I understood: 1 - To deal with types by copy, like the small ones : bool, int, float, double... I simply use "auto". 2 - To deal with types by reference, like the ones std::string, std::vector... I should use "auto&", but if the compiler complains about it, then I should use "const auto&" UNLESS I want to modify the reference content, then in this case I should finally use "auto&&". @pinsrq and @chandradeepdey, correct me please I am wrong.
The usage for auto and auto& is almost correct. The usage for auto&& is not when you want to deal with what is left. It is used when you want perfect forwarding. Like for example if you write a function that passes it's arguments to some other functions and you want to preserve the type information, then you use auto&&. So when called with an lvalue auto&& will deduce a lvalue type and a rvalie type otherwise.
Vikas
How to sort an array in descending order?
Apk
How to sort an array in descending order?
a simple google search would answer that
Vikas
a simple google search would answer that
Thanks, I found this on Google sort(arr, arr + n, greater<int>());
king king
Hello dear friends. I'm working with c for about 5 months. And I'm looking for recommendations to a good book for advanced/intermidate (Only C(89), not C++)
ꍏꈤꀸ
Can somebody add me to English chats about WinAPI?
P
Hello guys , I got stuck with a question The problem follows like this given an array of numbers, for example a[]=[ 24, 67, 90, 8 ]we need to find the sum of the numbers in a array which are obtained by multiplying the digits[ 2*4, 6*7,9*0, 8] the result should be 58 (8+42+0+8=58)
Kishan
https://www.hackerrank.com/challenges/crush/problem?h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen
Kishan
https://www.hackerrank.com/challenges/crush/problem?h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen
I wrote a solution for that and it gave me some points, but few testcase, testcase 7 to 13 are failing due to TLE
Kishan
long arrayManipulation(int n, vector<vector<int>> queries) { vector<long> arr(n); long maxe=INT_MIN; long qsize=queries.size(); for(long i=0; i<qsize; i++) { for(long j=queries[i][0]; j<=queries[i][1]; j++) { arr[j-1]+= queries[i][2]; maxe=max(maxe, arr[j-1]); } } return maxe; }
Anonymous
Goodday Esteemed members anyone who is good at c++ kindly inbox
Anonymous
cpp has different stl (header name)
Anonymous
which to learn
Anonymous
msvc or gcc
Mar!o
gcc
Anonymous
why
Anonymous
should I build unix like environment in windows
Anonymous
or change a plateform directly
ꍏꈤꀸ
Can ODBC be used without a DB connection? (I need to operate over .mdb files without connection and even installation of a DB)
olli
msvc or gcc
It shouldn't matter, ideally your code is standard c++ so it can be compiled using different compilers
Kishan
Can u Share?
you want code or logic?
Ojong
Anonymous
anyone needs help in c/c++ write me dm
ꍏꈤꀸ
anyone needs help in c/c++ write me dm
we have a whole group for it)
Tomay
@SilhouetteInDark I just realized that my problem is with "Forwarding References" which is new to me and not with "auto" itself. I have to dig a little bit more.
Anonymous
Please can someone explain the logic of this code to me? //convert a string to integer //ex. String “ryutfg477” //returns 477 int main(char *s) { unsigned int num = 0; s = “good89” while (*s++) { if (*s >= ‘0’ && *s <= ‘9’) num=(num*10) + (*s-‘0’); else if(num > 0) break; } return (num); }
Vikas
How to initialize 2d array in c++ with 1?
Pavel
How to initialize 2d array in c++ with 1?
How your 2d array is defined? "1" you mean so every element equals to 1?
Pavel
Yes. int arr[5][5];
you can do two for loops one inside another, I think that may be the easiest way in this case.
L0ʀᴅ Lᴜᴄ1ғ3ʀ ༗
Robert lafore c++ how is it?
L0ʀᴅ Lᴜᴄ1ғ3ʀ ༗
Anyone
klimi
if you want it line by line, take each line, put it into manual, read what it does...
K
😅
Anonymous
if you want it line by line, take each line, put it into manual, read what it does...
This line is what I don’t understand num=(num*10) + (*s-‘0’);
Anonymous
*s - ‘0’ ??
Yasin
Hello, I hope everyone’s doing well. Is there anyone here using Geany with C programming language? I need help for this.
Anonymous
*s - ‘0’ ??
https://en.cppreference.com/w/c/language/character_constant
Anonymous
if *s is '9' then doing *s - '0' will give you 9 as result (in encodings such as ASCII and Unicode)
Anonymous
'9' and 9 are different. the former is a character constant which might have some integral value that may or may not be 9
Anonymous
Robert lafore c++ how is it?
https://accu.org/bookreviews/2002/glassborow_1745/
Anonymous
stick to the stackoverflow list mentioned in the pinned message
Anonymous
Ok thanks
Manu
How i star CP ? IDK HOW TO START AND FROM WHERE ?
Manu
Codechef codeforces etc
I don't know the basics ?
Anonymous
I don't know the basics ?
try hackerrank, it is newbie friendly
Anonymous
no, it's a website
klimi
It looks like copyrighted book
L0ʀᴅ Lᴜᴄ1ғ3ʀ ༗
I want it
L0ʀᴅ Lᴜᴄ1ғ3ʀ ༗
Damm sorry
klimi
I want it
https://www.amazon.com/Object-Oriented-Programming-4th-Robert-Lafore/dp/0672323087 here you go
yyrr
Who konw how to write menu in c?
Anonymous
Hello