News for hackers. Stuff that matters.
Re:Lambda expression comparison between C++11, C++14 and C++17 by hendzen on Saturday May 14, 2016 @06:45PM (#11698398)
Another mildly obscure feature of lambdas is the ability to capture a variadic number of parameters.

Example (slightly contrived):

  #include <future>
  #include <iostream>

  template<typename... Args>
  void log(Args&&... args) {
      (std::cout <<  ...  << args) << std::endl;
  }

  template<typename... Args>
  std::future<void> log_async(Args&&... args) {
    return std::async(std::launch::async, [args...] { log(args...); });
  }

  int main()
  {
      auto f = log_async(1, 2, 3);
      f.wait();
  }
Re:Lambda expression comparison between C++11, C++14 and C++17 by groovy2shoes on Saturday May 14, 2016 @07:26PM (#11698521)
For those of us still stuck on C++98 at work, would you mind explaining what's going on here? In particular, I can't figure out why the ellipsis is so separated from `args` here:

        (std::cout << ... << args) << std::endl;
That looks like some black magic to me. The rest makes sense, I think.
Re:Lambda expression comparison between C++11, C++14 and C++17 by hendzen on Saturday May 14, 2016 @07:28PM (#11698529)
Re:Lambda expression comparison between C++11, C++14 and C++17 by groovy2shoes on Saturday May 14, 2016 @07:47PM (#11698589)
Neat! Thank you :)
Re:Lambda expression comparison between C++11, C++14 and C++17 by makecheck on Sunday May 15, 2016 @11:08AM (#11701178)
Heh, great. I used to put an ellipsis into a programming example to mean “fill in whatever you actually do here”, and now C++ went and made it mean something. :)
Re:Lambda expression comparison between C++11, C++14 and C++17 by moonshinefe on Sunday May 15, 2016 @05:54AM (#11700204)
Well, I feel like an old man telling kids to get off my lawn, but this syntax looks ridiculous. :/
Re:Lambda expression comparison between C++11, C++14 and C++17 by netheril96 on Saturday May 14, 2016 @06:57PM (#11698438)
Which standard version?
Re:Lambda expression comparison between C++11, C++14 and C++17 by hendzen on Saturday May 14, 2016 @06:59PM (#11698446)
That snippet depends on fold expressions, which are in c++17. AFAIK, capturing a variadic parameter pack should work in C++11.