Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

During return type inference, references decay to value types by default, so you have to use some awkward syntax if you want to use them to set values:

   auto item_user = [](auto&& item) -> decltype(auto) { return (item.user); };

   item_user(item) = my_user;
Even more awkward if you want some slightly better error messages with concepts:

   auto item_user = [](auto&& item) -> decltype(auto) requires requires { item.user;}  { return (item.user); };
(yes, the double requires is not a mistake).

At least is very macroable, which would also allow to wrap it in a type with more meaning than a opaque lambda (which I agree is a good thing).

edit: Full on nonsense just for laughs:

   auto user_age = [](auto&& user) noexcept (noexcept((user.age))) -> decltype(auto) requires requires { user.age;}  { return (user.age);  };


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: