News for hackers. Stuff that matters.
Re:PyTorch 1.0 is out by shaklee3 on Friday December 07, 2018 @07:54PM (#18633099)
Why do closures suck? What are they missing?
Re:PyTorch 1.0 is out by grandmczeb on Friday December 07, 2018 @10:33PM (#18633749)
I’m confused about that too - closures are one of the nicer parts of C++ imo.
Re:PyTorch 1.0 is out by usgroup on Saturday December 08, 2018 @04:16AM (#18634552)
I like to pass closures as return values or as function parameters. In my experience this is folly in c++.
Re:PyTorch 1.0 is out by grandmczeb on Saturday December 08, 2018 @11:06AM (#18635841)
Here's an example of doing both:

  $ cat test.cpp
  #include <iostream>
  #include <string>

  template <typename F>
  auto pass_func(F func) {
    return func();
  }

  auto return_func() {
    std::string test = "Hello World!";
    return [=](){ return test; };
  }

  int main() {
    auto func = return_func();
    std::cout << pass_func(func) << std::endl;
  }

  $ clang test.cpp -lstdc++ -std=c++14 -o test
  $ ./test
  "Hello World!"
What's hard about it?
Re:PyTorch 1.0 is out by black-tea on Sunday December 09, 2018 @03:47AM (#18640003)
You didn't pass a function to std::cout, you called it and passed its return value.
Re:PyTorch 1.0 is out by grandmczeb on Sunday December 09, 2018 @12:50PM (#18642161)
The way I interpret the GP, they're talking about passing closures as a function argument. In the example I pass func (a closure) to pass_func. Not sure what std::cout has to do with it?
Re:PyTorch 1.0 is out by black-tea on Sunday December 09, 2018 @03:31PM (#18643086)
Sorry, I misread the code.