1

In clion 2017.1 when I choose live template for iterating a range (Ctrl+J iter), then I get the following code:

for (auto &&item : __) {

}

Is it really a good idea to use forwading reference as iteration object? If its used as a live template then maybe it is becoming a standard?

YSC
  • 38,212
  • 9
  • 96
  • 149
mike
  • 1,670
  • 11
  • 21
  • 1
    @nwp Pretty sure that's not an r-value reference. – Baum mit Augen Apr 03 '17 at 08:16
  • 6
    Very related: https://stackoverflow.com/questions/15927033/what-is-the-correct-way-of-using-c11s-range-based-for – Baum mit Augen Apr 03 '17 at 08:17
  • @nwp it is a forwarding reference. `auto` follows the rules of template argument deduction (plus one or two gizmos for `initializer_list`s). – Quentin Apr 03 '17 at 08:18
  • Whether or not it's always the right choice is debatable, but it's a choice that always works. So you *can* use it per default. (Reposted due to typo which changed the meaning.) – Baum mit Augen Apr 03 '17 at 08:23
  • @Baum : Considering that the [accepted answer](http://stackoverflow.com/a/15927037/15416) answers this question as well, I'd even call it a duplicate. Any objections to closing this? – MSalters Apr 03 '17 at 08:27

0 Answers0