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
Anonymous
Anonymous
you might also use const auto & sometimes to avoid accidentally changing the value
Tomay
I lost internet for an hour.
Anonymous
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
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?
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
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;
}
Kishan
Anonymous
Goodday Esteemed members anyone who is good at c++ kindly inbox
klimi
Kishan
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
Ojong
Ojong
Anonymous
anyone needs help in c/c++ write me dm
ꍏꈤꀸ
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?
Vikas
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.
Vikas
L0ʀᴅ Lᴜᴄ1ғ3ʀ ༗
Robert lafore c++ how is it?
L0ʀᴅ Lᴜᴄ1ғ3ʀ ༗
Anyone
Anonymous
klimi
Anonymous
klimi
klimi
if you want it line by line, take each line, put it into manual, read what it does...
K
😅
Anonymous
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
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 ?
Apk
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
L0ʀᴅ Lᴜᴄ1ғ3ʀ ༗
yyrr
Who konw how to write menu in c?
Anonymous
Hello