[webkit-dev] [webkit-reviewers] usage of auto

Xabier Rodríguez Calvar calvaris at igalia.com
Thu Jan 12 04:38:38 PST 2017


O Mér, 11-01-2017 ás 11:15 -0800, JF Bastien escribiu:
> e.g. I think this is great:
> auto ptr = std::make_unique<Foo>(bar);
> Proposed rule: if the type is obvious because it's on the line, then
> auto is good.
> Similarly:
> auto i = static_cast<int>(j);
> auto foo = make_foo();
> auto bar = something.get_bar(); // Sometimes, "bar" is obvious.
> Range-based loops are a bit tricky. IMO containers with "simple"
> types are good candidates for either:
> for (const auto& v : cont) { /* don't change v */ }
> for auto& v : cont) { /* change v */ }
> But what's "simple"? I'd say all numeric, pointer, and string types
> at least. It gets tricky for more complex types, and I'd often rather
> have the type in the loop. Here's more discussion on this, including
> a recommendation to use auto&& on range-based loops! I think this
> gets confusing, and I'm not a huge fan of r-value references
> everywhere.

I'm ok with a rule similar to this one.


Xabier Rodríguez Calvar
Software Engineer
IGALIA http://www.igalia.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 224 bytes
Desc: This is a digitally signed message part
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20170112/e3377509/attachment.sig>

More information about the webkit-dev mailing list