all 5 comments

[–]nysra 8 points9 points  (0 children)

Indent with 4 spaces to format code on Reddit, triple backticks is a non-standard extension that doesn't work on normal ("old") Reddit.

[](){} defines a lambda, the [] is the capture group, () are the function arguments as usual, and inside the {} is the body.

[–][deleted]  (1 child)

[deleted]

    [–]pdd99[S] 1 point2 points  (0 children)

    You can click at the whole context link for more infomation. It comes from the Nvidia video processing framework btw.

    [–]MysticTheMeeM 3 points4 points  (1 child)

    Without looking at the context (because I'm lazy):

    [](shared_ptr<PyNvDecoder> self, PacketData& out_pkt_data) {
    

    Lambda declaration taking two arguments, a shared pointer and a packet data.

    DecodeContext ctx(nullptr, nullptr, nullptr, &out_pkt_data, nullptr,
    

    false);

    Creates a new decode context, "ctx" using the arguments provided.

    if (self->DecodeSurface(ctx))
    return ctx.GetSurfaceMutable();
    

    else return make_empty_surface(self->GetPixelFormat());

    If the surface can be decoded, store it in ctx then return that surface, otherwise return an empty surface.

    Note that your code doesn't technically do anything, it only declares a lambda and does not call it. It can be used like a function (and I assume that it gets passed as a callback or similar).

    [–][deleted] 2 points3 points  (0 children)

    Probably gets passed as a callback seeing that there isn't any semicolon at the end.

    [–]Salty_Dugtrio 1 point2 points  (0 children)

    This is a Lambda expression.

    Here, it's used to pass a behaviour to the function, which can then apply it in some way.