Answers for "lambda c++"

C++
6

lambda c++

- Good website to learn lambda in c++:
https://docs.microsoft.com/en-us/cpp/cpp/lambda-expressions-in-cpp
https://en.cppreference.com/w/cpp/language/lambda
https://www.geeksforgeeks.org/lambda-expression-in-c/
https://stackoverflow.com/questions/7627098/what-is-a-lambda-expression-in-c11
https://linuxhint.com/lambda-expressions-in-c/
Posted by: Guest on May-31-2021
1

cpp lambda function

#include <iostream>
using namespace std;

bool isGreater = [](int a, int b){ return a > b; }

int main() {
	cout << isGreater(5, 2) << endl; // Output: 1
	return 0;
}
Posted by: Guest on April-03-2021
7

lambda c++

#include <iostream>
#include <string>
 
// returns a lambda
auto makeWalrus(const std::string& name)
{
  // Capture name by reference and return the lambda.
  return [&]() {
    std::cout << "I am a walrus, my name is " << name << '\n'; // Undefined behavior
  };
}
 
int main()
{
  // Create a new walrus whose name is Roofus.
  // sayName is the lambda returned by makeWalrus.
  auto sayName{ makeWalrus("Roofus") };
 
  // Call the lambda function that makeWalrus returned.
  sayName();
 
  return 0;
}
Posted by: Guest on June-26-2020
-1

cpp lambda

struct X {
    int x, y;
    int operator()(int);
    void f()
    {
        // the context of the following lambda is the member function X::f
        [=]()->int
        {
            return operator()(this->x + y); // X::operator()(this->x + (*this).y)
                                            // this has type X*
        };
    }
};
Posted by: Guest on December-18-2020
-1

lambda function in c++

//lambda function for sorting vector ascending
sort(vec.begin(),vec.end(),[](int &a, int &b){
	return a<b;
});
//lambda function for sorting vector of vector ascending based on first value
sort(vec.begin(),vec.end(),[](vector<int> &a, vector<int> &b){
	return a[0]<b[0];
});
Posted by: Guest on August-16-2021

Browse Popular Code Answers by Language