I recently faced an issue due the fact that I didn't placed an 'int' before the looping for a vector that was constructed. It works without (int) sometimes but this time It gave warnings. Can someone explain this behavior. Thankyou.
# | User | Rating |
---|---|---|
1 | Benq | 3783 |
2 | jiangly | 3741 |
3 | tourist | 3622 |
4 | Um_nik | 3536 |
5 | maroonrk | 3526 |
6 | inaFSTream | 3477 |
7 | fantasy | 3468 |
8 | ecnerwala | 3454 |
9 | QAQAutoMaton | 3428 |
10 | fivedemands | 3381 |
# | User | Contrib. |
---|---|---|
1 | Um_nik | 185 |
2 | adamant | 178 |
3 | awoo | 177 |
4 | nor | 169 |
5 | maroonrk | 165 |
6 | -is-this-fft- | 164 |
7 | antontrygubO_o | 153 |
8 | ko_osaga | 151 |
9 | dario2994 | 150 |
10 | SecondThread | 149 |
I recently faced an issue due the fact that I didn't placed an 'int' before the looping for a vector that was constructed. It works without (int) sometimes but this time It gave warnings. Can someone explain this behavior. Thankyou.
Name |
---|
The function
size()
's return type issize_t
which is an unsigned int.So, for example, if you do
v.size() - 1
for an empty vector(size = 0) it will not result in -1 but some large number.Maybe you did something similar to this.
This doesn't answer your question, but it's pretty common to define a macro
#define sz(c) int((c).size())
to avoid underflow issues without having to putint()
all over the place. Alternatively, in C++20 you can usessize(c)
(see cppreference), which returns the size in a signed type.