In diesem Beitrag zeige ich ein kleines Beispiel, wie man die <b>Lambda Expressions</b> in c++ nutzen kann. Lambdas werden in der funktionalen Programmierung eingesetzt, können aber auch in anderen Programmierparadigmen verwendet werden. Dadurch kann man zum Beispiel eine Funktion als Parameter an eine anderen Funktion übergeben. Man kann Lambdas auch als eine "kurzschreibweise" einer normalen Funktionsdefinition sehen. ``` #include <iostream> #include <vector> auto print = []<typename T>(T result) -> void {std::cout << result << '\n';}; auto insertNumbers = []<typename T>(std::vector<T> *list, T value) -> void {list->push_back(value);}; auto sumUp = []<typename T>(const std::vector<T> *list) -> T { T sum = 0; for(T elem : *list){ sum += elem; } return sum; }; int main(){ std::vector<int> numbers = std::vector<int>(); for(int n = 0; n < 10; n++){ insertNumbers(&numbers, n+1); } int sum = sumUp(&numbers); print(sum); } ``` https://img.blurt.world/blurtimage/ozelot47/cf187aa98ca3e8ae7f187d67d61c14ac1c778de9.png
author | ozelot47 |
---|---|
permlink | lambda-expressions-in-c-s16gqc |
category | hive-121566 |
json_metadata | {"app":"peakd/2023.9.1","format":"markdown","tags":["stemgeeks","science","stem","deutsch","hive-engine","archon","dach","lambda"],"users":[],"image":["https://img.blurt.world/blurtimage/ozelot47/cf187aa98ca3e8ae7f187d67d61c14ac1c778de9.png"]} |
created | 2023-09-18 10:49:24 |
last_update | 2023-09-18 10:49:24 |
depth | 0 |
children | 6 |
last_payout | 2023-09-25 10:49:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 1.515 HBD |
curator_payout_value | 1.509 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,081 |
author_reputation | 142,895,102,111,771 |
root_title | "Lambda Expressions in c++" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,258,219 |
net_rshares | 7,370,240,084,263 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
redes | 0 | 2,248,523,627,198 | 28% | ||
vbnm21 | 0 | 3,573,991,034 | 100% | ||
cryptoknight12 | 0 | 1,084,735,890 | 4.35% | ||
pixelfan | 0 | 60,126,728,842 | 6.4% | ||
vikisecrets | 0 | 627,025,012,116 | 30% | ||
eddwood | 0 | 57,878,598,879 | 50% | ||
jeyf123 | 0 | 120,460,436,323 | 85% | ||
gammastern | 0 | 412,884,504,488 | 100% | ||
der-prophet | 0 | 14,369,415,833 | 16.5% | ||
sneakyninja | 0 | 1,440,061,896 | 2.17% | ||
nerdtopiade | 0 | 15,771,370,781 | 60% | ||
mastergerund | 0 | 1,394,861,481 | 4.35% | ||
condeas | 0 | 440,063,552,048 | 20% | ||
dotwin1981 | 0 | 31,791,438,055 | 30% | ||
dera123 | 0 | 84,484,792,608 | 100% | ||
sd974201 | 0 | 1,410,195,017 | 3% | ||
sbi3 | 0 | 263,543,297,860 | 20.66% | ||
fw206 | 0 | 1,839,841,009,183 | 26.4% | ||
bitandi | 0 | 30,058,360,516 | 40% | ||
thedailysneak | 0 | 1,965,879,874 | 2.17% | ||
zuerich | 0 | 588,554,490,947 | 10% | ||
rich.art.deluxe | 0 | 2,108,010,274 | 55% | ||
babysavage | 0 | 674,989,706 | 4.35% | ||
ibc | 0 | 11,800,086,019 | 100% | ||
kryptodenno | 0 | 176,914,713,724 | 5% | ||
partitura.stem | 0 | 307,317,047 | 100% | ||
sbi-tokens | 0 | 3,290,487,691 | 4.35% | ||
elianaicgomes | 0 | 1,773,880,812 | 5% | ||
mister.reatard | 0 | 1,752,082,650 | 10% | ||
an-sich-wachsen | 0 | 3,127,076,578 | 33% | ||
voinvote2 | 0 | 102,093,621,990 | 50% | ||
chapmain | 0 | 0 | 100% | ||
danielhuhservice | 0 | 77,069,371,764 | 33% | ||
he-index | 0 | 2,947,568,140 | 10% | ||
moraviareosa | 0 | 73,547,114 | 100% | ||
holovision.stem | 0 | 1,227,866,077 | 100% | ||
lxsxl | 0 | 36,803,230,269 | 50% | ||
mario89 | 0 | 27,811,122,466 | 100% | ||
thedrummerboy | 0 | 439,912,868 | 100% | ||
carina89 | 0 | 34,074,966,321 | 100% | ||
cleanyourcity | 0 | 35,483,899,307 | 5% | ||
e-sport-gamer | 0 | 1,308,055,827 | 33% | ||
hobbytrader | 0 | 1,094,976,698 | 33% | ||
e-sport-girly | 0 | 1,441,163,789 | 33% | ||
goldkatze | 0 | 0 | 100% | ||
ikankaruk88 | 0 | 333,681,846 | 100% | ||
blaupunkt | 0 | 42,094,417 | 100% |
!LOL !invest_vote !BEER
author | dotwin1981 |
---|---|
permlink | re-ozelot47-s174wt |
category | hive-121566 |
json_metadata | {"tags":["hive-121566"],"app":"peakd/2023.9.1"} |
created | 2023-09-18 19:31:42 |
last_update | 2023-09-18 19:31:42 |
depth | 1 |
children | 1 |
last_payout | 2023-09-25 19:31:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 23 |
author_reputation | 333,113,166,594,230 |
root_title | "Lambda Expressions in c++" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,271,250 |
net_rshares | 0 |
<div class='pull-right'><center><img src="https://lolztoken.com/lolz.png"><br><a href="https://lolztoken.com">lolztoken.com</a></p><br><br><br><br></center></div><p><center><strong>Never scream into a colander<br>You'll strain your voice.</strong><br><sub>Credit: <a href="https://peakd.com/@reddit">reddit</a></sub><br>@ozelot47, I sent you an <a href="https://lolztoken.com">$LOLZ</a> on behalf of dotwin1981<br><br>(8/10)<br>Farm <strong><a href='https://lolztoken.com'>LOLZ tokens</a></strong> when you <strong><a href='https://peakd.com/hive-155986/@lolztoken/earn-10percent-apr-on-hive-power-delegations-to-the-lolz-project'>Delegate Hive</a> or <a href='https://peakd.com/hive-155986/@lolztoken/introducing-lolz-defi-now-you'>Hive Tokens</a>.</strong><br>Click to delegate: <a href='https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=lolzbot&vesting_shares=10%20HP'>10</a> - <a href='https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=lolzbot&vesting_shares=20%20HP'>20</a> - <a href='https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=lolzbot&vesting_shares=50%20HP'>50</a> - <a href='https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=lolzbot&vesting_shares=100%20HP'>100</a> HP</center></p>
author | lolzbot |
---|---|
permlink | re-re-ozelot47-s174wt-20230918t193208z |
category | hive-121566 |
json_metadata | "{"app": "beem/0.24.19"}" |
created | 2023-09-18 19:32:15 |
last_update | 2023-09-18 19:32:15 |
depth | 2 |
children | 0 |
last_payout | 2023-09-25 19:32:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,280 |
author_reputation | 196,320,608,704,749 |
root_title | "Lambda Expressions in c++" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,271,260 |
net_rshares | 0 |
@dotwin1981 denkt du hast ein Vote durch @investinthefutur verdient!<br>@dotwin1981 thinks you have earned a vote of @investinthefutur !<br>
author | investinthefutur |
---|---|
permlink | re-lambda-expressions-in-c-s16gqc-20230918t193200z |
category | hive-121566 |
json_metadata | "{"app": "beem/0.24.26"}" |
created | 2023-09-18 19:32:00 |
last_update | 2023-09-18 19:32:00 |
depth | 1 |
children | 0 |
last_payout | 2023-09-25 19:32:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 140 |
author_reputation | 135,729,607,290,395 |
root_title | "Lambda Expressions in c++" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,271,256 |
net_rshares | 0 |
Ich kenne Lambdas momentan auch eher als Kurzschreibweise von Funktionen in Python. Dort bin ich aktuell grad beim Regex Thema.
author | jeyf123 |
---|---|
permlink | re-ozelot47-s16jk1 |
category | hive-121566 |
json_metadata | {"tags":["hive-121566"],"app":"peakd/2023.9.1"} |
created | 2023-09-18 11:50:27 |
last_update | 2023-09-18 11:50:27 |
depth | 1 |
children | 2 |
last_payout | 2023-09-25 11:50:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 127 |
author_reputation | 85,991,437,710,893 |
root_title | "Lambda Expressions in c++" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,259,235 |
net_rshares | 42,778,995,080 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
ozelot47 | 0 | 42,778,995,080 | 100% |
Mit regulären Ausdrücken kann man schön spielen. Ist ein mächtiges Werkzeug.
author | ozelot47 |
---|---|
permlink | re-jeyf123-s16nr0 |
category | hive-121566 |
json_metadata | {"tags":["hive-121566"],"app":"peakd/2023.9.1"} |
created | 2023-09-18 13:21:00 |
last_update | 2023-09-18 13:21:00 |
depth | 2 |
children | 1 |
last_payout | 2023-09-25 13:21:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 76 |
author_reputation | 142,895,102,111,771 |
root_title | "Lambda Expressions in c++" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,261,292 |
net_rshares | 0 |
ja, da hast du recht. Derzeit muss ich mir aber erst mal die Basis aneignen. Manchmal unterscheiden sich die Angaben von der Realität.  Dann erzählt mir der Chatbot, der + Quantifier(heißt das so?) ist greedy/gierig und sucht die Buchstabenreihenfolge hintennach ("o") bis zum Ende des Strings. Interessanter Effekt, wenn man einen längeren Text einlesen lässt. (entsprechend bis zum letzten o)
author | jeyf123 |
---|---|
permlink | re-ozelot47-s16s6a |
category | hive-121566 |
json_metadata | {"tags":["hive-121566"],"app":"peakd/2023.9.1"} |
created | 2023-09-18 14:56:42 |
last_update | 2023-09-18 14:56:42 |
depth | 3 |
children | 0 |
last_payout | 2023-09-25 14:56:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 555 |
author_reputation | 85,991,437,710,893 |
root_title | "Lambda Expressions in c++" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,263,970 |
net_rshares | 0 |