3 ms·
When the definition is far from the use of auto, that's exactly the case where I think repeating the type is meaningful. Yes, it's noise to write: std::un
by vitus 5y ago
When the definition is far from the use of auto, that's exactly the case where I think repeating the type is meaningful.
Yes, it's noise to write:
std::unique_ptr<MyWidget> widget = std::make_unique<MyWidget>();
But I don't think it's so noisy in the case you've provided. If I encountered that code, I'd wonder whether that operator-> is safe, or if you're inadvertently dropping some qualifier (e.g. is it actually a raw pointer?).
And as I suggested, it's not much harder to add a using decl:
using UniqueWidget = std::unique_ptr<mynamespace::MyWidget>;
// ...
std::vector<UniqueWidget> objects;
// ...
auto it = std::find_if(objects.begin(), objects.end(), [](UniqueWidget&) { return widget->x == 1; });
(I also recognize that my opinion is very heavily flavored by the Google style guide: https://google.github.io/styleguide/cppguide.html#Type_deduction https://google.github.io/styleguide/cppguide.html#Type_deduc...)