DEV Community

Discussion on: The big STL Algorithms tutorial: modifying sequence operations - turn things around

Collapse
 
gapry profile image
Gapry

Hi, Sandor Dargo

I think the code snippets

std::vector<int> numbers {1, 2, 3, 4, 5, 6, 7, 8, 9};
const std::vector<int> reversedNumbers = reverse_const_copy(numbers);

is changed to as following by adopted keyword auto is better.

auto numbers         = std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9};
auto reversedNumbers = reverse_const_copy(numbers); 

what do you think about this?

Best regards, Gapry.

Collapse
 
sandordargo profile image
Sandor Dargo

Thanks for your comment @gapry .

I think that in the second case, it's better and if you are looking for a direct replacement, I would go with const auto. If you'd change the return type of reverse_const_copy(), there would be nothing to do on the caller side.

In the first case, I don't think it's any better. If you want to change the type, you have to update it anyway and using auto in fact just makes the code more verbose without adding any benefits.

It's debatable that it would make the code more uniform, without any benefits and with a few extra chars, let's say it's a matter of personal preference/project guidelines.

Thanks for your ideas!

Collapse
 
gapry profile image
Gapry

Hi, @sandordargo

Thank you for your insights !

Best regards, Gapry.