不同比例的幅面如何比较视角?# PhotoGear - 摄影器材
p*n
1 楼
The return type of container.size() is size_t. If used as such, however, it
may complicate codes sometimes. See the following example:
size_t sz = container.size();
for(size_t i = 0; i < sz -1; i++){
..... // do something
}
The empty container has to be handled in a different way, perhaps tested
before entering the for loop. Now, if we insist using size_t and empty
container is not a problem, we could still encounter the following problem:
size_t sz = contianer.size();
while( sz > 0 ){
...... // the expression may contain --sz or sz -= 2;
}
Again, the fact that size_t is an unsigned type is a pain in the ass.
I noticed many sample codes posted here suggesting the following usage
int sz = container.size();
Associated is the possibility of overflowing, since size_t is implementation
dependent and is likely larger than int. Of course we could use long long,
but it looks weird.
I wonder what is the best way to handle this problem?
may complicate codes sometimes. See the following example:
size_t sz = container.size();
for(size_t i = 0; i < sz -1; i++){
..... // do something
}
The empty container has to be handled in a different way, perhaps tested
before entering the for loop. Now, if we insist using size_t and empty
container is not a problem, we could still encounter the following problem:
size_t sz = contianer.size();
while( sz > 0 ){
...... // the expression may contain --sz or sz -= 2;
}
Again, the fact that size_t is an unsigned type is a pain in the ass.
I noticed many sample codes posted here suggesting the following usage
int sz = container.size();
Associated is the possibility of overflowing, since size_t is implementation
dependent and is likely larger than int. Of course we could use long long,
but it looks weird.
I wonder what is the best way to handle this problem?