Anonymous functions

At runtime I have some variables being passed into the alarm library to perform an action when the alarm sounds. This sounds easy using static functions, except the alarm turns on a relay. There are 4 relays. The relay number is known as a variable.

I was toying around with anonymous functions to use the relay number at runtime so that when the delegate is called, I think it's called delegate, the anonymous function would have the valve number.

I'll paste some code to illustrate. What I want to accomplish is to have the alarm have the variables so that the alarm can decide which relay to turn on. Is this even possible without some kind of big if statement?

int h = 8;
int m = 30;
int valveno = 1;

if (dayOfTheWeek=="Sunday"){
//create an alarm that sets the relay to HIGH
Alarm.alarmRepeat(dowSunday, h, m, 0, (int &valveno, bool &valvestatus){ toggleValve(a, b); });
}

void toggleValve(int valveno, bool valvestatus){
...
}

Pardon the code, but the code isn't compilable, it's shown to illustrate what I'm trying to accomplish. The anonymous function I want it to set a relay to HIGH when it is executed. There are many relays and I want them to turn ON|OFF when the alarm sounds, each being completely independent of the above runtime code, which sets the alarms according to the schedule.

For the Alarm library I'm using the code in this post: http://forum.arduino.cc/index.php?topic=37693.0

Edit: I figured how to make it work. The alarm class has a definition for the callback function, by I need to pass it parameters, so instead of making it specific to the arguments, I will define a string array property to store arguments for the callback. This keeps it generic. Then use lambda functors without and execute or caller so the alarm class can call them and pass a string array into them. It is then the responsibility of the implementer to parse parameters or arguments and do something with them.

Bingo bango

https://en.cppreference.com/w/cpp/language/lambda#Lambda_capture

Can you elaborate (i.e. provide code samples)?

No.

There are examples included and a bunch of buzzwords for further searches if something is unclear.
My teaching of the standard can not be as good as the real standard anyway.

Can someone else help? I am unfamiliar with lambda expressions and need guidance, not some reference to a library. Ita just not how I learn. I learn by example. Thanks.

I gave you a link to the relevant section of the C++ standard reference, not a library.

Whandall:
I gave you a link to the relevant section of the C++ standard reference, not a library.

Reference, sorry. I called it a library.

I need to understand how this works and applies. I am new with lambda and have not grasped the concepts. Should you provide code samples relevant to my topic/problem I might be able to understand.

Maybe that thread will shed some light:

I find this to be a little easier to follow, less pedantic than the standard: Lambda expressions in C++ | Microsoft Docs

Lambda Functions in C++11 - the Definitive Guide

Also posted at:
https://stackoverflow.com/questions/54970898
If you're going to do that then please add links to the other places you posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.