View Single Post
  #7  
Old 09-05-2019, 05:50
zeffy zeffy is offline
Friend
 
Join Date: Jul 2017
Posts: 44
Rept. Given: 3
Rept. Rcvd 7 Times in 6 Posts
Thanks Given: 194
Thanks Rcvd at 163 Times in 47 Posts
zeffy Reputation: 7
Quote:
Originally Posted by chants View Post
3) as far as I know its the captures that are on the temporary object, and the actual function arguments are passed per __thiscall logic.
Oops, you're right. I knew that but mixed up the terminology (captures vs arguments), heh.

Here's an example of how MSVC seems to implement lambdas:

Code:
bool normal_function()
{
    int a, b, c;
    int d = 0;
    int e = 0;
    int f = 0;

    return [a, b, c](int, int, int) -> bool {
        return true;
    }(d, e, f);
}
Which is compiled into something resembling this:

Code:
bool normal_function()
{
    class lambda_class
    {
        int *a_;
        int *b_;
        int *c_;

    public:
        lambda_class(int *a, int *b, int *c)
            : a_(a), b_(c), c_(c)
        {
        }

        bool operator()(int d, int e, int f)
        {
            return true;
        }
    };

    int a, b, c;
    int d = 0;
    int e = 0;
    int f = 0;

    return lambda_class(&a, &b, &c)(d, e, f);
}
Reply With Quote
The Following User Says Thank You to zeffy For This Useful Post:
chants (09-05-2019)