What does this strange C++ syntax do?

113 Views Asked by At

From what I understand, 3 arguments are being passed to m.def(). I don't understand the syntax of the second argument passed, i.e. [] (Observable...){} What does this mean?

m.def(
  "DumpHistogramFile",
  [](Observable<NetBase>::Observer* ob) {
    HistogramNetObserver* hist_ob =
        dynamic_cast_if_rtti<HistogramNetObserver*>(ob);
    hist_ob->DumpHistogramFile();
  },
  pybind11::arg("ob"));

I found this syntax in the pytorch source code

1

There are 1 best solutions below

0
On

The second argument is a function that takes a pointer to an Observer and doesn't return anything. When executed, it calls DumpHistogramFile. This is called a lambda expression.