Filter werden benutzt, um Operationen auf einer großen Datenmenge auszuführen. In diesem Beispiel ist die Datenmenge allerdings überschaubar. Zunächst wird jedes Element modifiziert (<b>map</b>), dann ein Filter angewendet, um die Menge zu verkleinern. Abschließend folgt eine Reduzierung, bis nur noch ein Element übrig bleibt. Ein Anwendungsfall wären Streams. ``` #include <iostream> #include <vector> #include <algorithm> #include <numeric> auto map = [](int &elem) -> int {return elem-1;}; auto filter = [](int &elem) -> bool {return elem % 2 == 0 || elem <= 0;}; auto reduce = [](int &x, int &y) -> int {return x*y;}; int main(){ std::vector<int> origin{-3,-2,-1,0,1,2,3,4,5,6,7,8,9}; std::vector<int> afterMap; // map: do something with all elements in this datastructure std::transform(origin.begin(), origin.end(), std::back_inserter(afterMap), map); // filter: conditions to skip elements std::vector<int>::iterator vectorfilter = std::remove_if(afterMap.begin(), afterMap.end(), filter); for(auto it = afterMap.begin(); it != vectorfilter; it++){ std::cout << *it << '\n'; }; // reduce: to reduce elements in this container via sum, multiply or other things int result = std::accumulate(afterMap.begin(), vectorfilter, afterMap[0], reduce); std::cout << result << '\n'; } ``` 
author | ozelot47 |
---|---|
permlink | filter-in-c-mit-lambda-nutzen |
category | hive-121566 |
json_metadata | {"app":"peakd/2023.9.2","format":"markdown","tags":["stemgeeks","science","stem","deutsch","hive-engine","leofinance","archon"],"users":[],"image":["https://img.blurt.world/blurtimage/ozelot47/aae19ceb71509e85109be2dd0bcc59fc34b7f10c.png"]} |
created | 2023-09-25 10:30:03 |
last_update | 2023-09-25 10:30:03 |
depth | 0 |
children | 4 |
last_payout | 2023-10-02 10:30:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 2.590 HBD |
curator_payout_value | 2.581 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,455 |
author_reputation | 143,180,130,833,688 |
root_title | "Filter in c++ mit Lambda nutzen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,456,664 |
net_rshares | 12,340,305,341,558 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
fabio | 0 | 1,392,161,284,058 | 100% | ||
ripperone | 0 | 2,170,483,224,682 | 28% | ||
vbnm21 | 0 | 3,619,281,970 | 100% | ||
cryptoknight12 | 0 | 808,950,430 | 3.04% | ||
lifestylechill | 0 | 23,587,883,366 | 100% | ||
eturnerx | 0 | 53,757,065,354 | 2.7% | ||
pixelfan | 0 | 58,083,625,222 | 6.4% | ||
vikisecrets | 0 | 642,047,043,828 | 30% | ||
tomiscurious | 0 | 7,113,510,156 | 1.3% | ||
honolulu | 0 | 13,578,894,937 | 100% | ||
jeyf123 | 0 | 127,125,811,385 | 85% | ||
afterglow | 0 | 785,231,411 | 17% | ||
gammastern | 0 | 411,939,461,794 | 100% | ||
maxinpower | 0 | 83,476,333,953 | 50% | ||
rcshad0w | 0 | 37,093,884,278 | 62% | ||
sneakyninja | 0 | 994,927,923 | 1.52% | ||
nerdtopiade | 0 | 13,842,939,270 | 60% | ||
payger | 0 | 5,335,251,892 | 50% | ||
manncpt | 0 | 150,137,702,725 | 100% | ||
mastergerund | 0 | 975,967,018 | 3.04% | ||
condeas | 0 | 464,042,948,604 | 20% | ||
melvin7 | 0 | 60,955,114,333 | 20% | ||
indextrader24 | 0 | 263,010,659,864 | 100% | ||
dotwin1981 | 0 | 32,878,056,051 | 30% | ||
dera123 | 0 | 57,916,022,057 | 100% | ||
sd974201 | 0 | 1,410,545,446 | 3% | ||
globalschool | 0 | 8,144,918,571 | 50% | ||
sbi4 | 0 | 269,977,069,069 | 20.22% | ||
opt2o | 0 | 6,734,674,521 | 100% | ||
fw206 | 0 | 2,738,695,312,217 | 40% | ||
bitandi | 0 | 29,852,644,446 | 40% | ||
thedailysneak | 0 | 1,363,872,269 | 1.52% | ||
zuerich | 0 | 970,496,527,864 | 17% | ||
rich.art.deluxe | 0 | 2,264,333,193 | 55% | ||
ibc | 0 | 12,457,580,388 | 100% | ||
thehealthylife | 0 | 3,024,714,320 | 25% | ||
kryptodenno | 0 | 179,754,803,286 | 5% | ||
tinyhousecryptos | 0 | 484,172,024 | 5% | ||
sbi-tokens | 0 | 2,500,554,572 | 3.04% | ||
elianaicgomes | 0 | 1,715,849,213 | 5% | ||
mister.reatard | 0 | 1,663,102,864 | 10% | ||
sonnenstrom63 | 0 | 3,218,690,303 | 100% | ||
an-sich-wachsen | 0 | 3,256,461,830 | 33% | ||
chapmain | 0 | 0 | 100% | ||
danielhuhservice | 0 | 78,317,223,290 | 33% | ||
he-index | 0 | 2,957,907,621 | 10% | ||
solymi | 0 | 1,771,075,998,190 | 100% | ||
moraviareosa | 0 | 16,250,240 | 100% | ||
holovision.stem | 0 | 5,331,668,509 | 100% | ||
soturi | 0 | 1,253,839,340 | 100% | ||
furkanmamplam | 0 | 19,651,096,080 | 100% | ||
themyscira | 0 | 58,503,946,969 | 100% | ||
mario89 | 0 | 24,841,116,847 | 100% | ||
karizma | 0 | 17,806,784,750 | 50% | ||
richie8012 | 0 | 8,668,591,595 | 98.3% | ||
carina89 | 0 | 32,791,284,029 | 100% | ||
e-sport-gamer | 0 | 1,300,193,536 | 33% | ||
hobbytrader | 0 | 1,087,389,912 | 33% | ||
e-sport-girly | 0 | 1,438,570,514 | 33% | ||
it24.archive | 0 | 1,872,011,650 | 100% | ||
spaceye | 0 | 624,565,529 | 100% |
!LOL !PIZZA !BBH
author | dotwin1981 |
---|---|
permlink | re-ozelot47-s1k70h |
category | hive-121566 |
json_metadata | {"tags":["hive-121566"],"app":"peakd/2023.9.2"} |
created | 2023-09-25 20:45:54 |
last_update | 2023-09-25 20:45:54 |
depth | 1 |
children | 2 |
last_payout | 2023-10-02 20:45:54 |
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 | 16 |
author_reputation | 334,092,684,444,414 |
root_title | "Filter in c++ mit Lambda nutzen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,471,900 |
net_rshares | 0 |
<center><p>@ozelot47! <b>Your Content Is Awesome</b> so I just sent 1 <b>$BBH</b> (Bitcoin Backed Hive) to your account on behalf of @dotwin1981. <sub>(1/1)</sub></p> <p><img src="https://i.imgur.com/QwsegY0.png"></p></center>
author | bbhbot |
---|---|
permlink | re-re-ozelot47-s1k70h-20230925t204612z |
category | hive-121566 |
json_metadata | "{"app": "beem/0.24.26"}" |
created | 2023-09-25 20:46:12 |
last_update | 2023-09-25 20:46:12 |
depth | 2 |
children | 0 |
last_payout | 2023-10-02 20:46:12 |
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 | 226 |
author_reputation | 2,740,199,634,396 |
root_title | "Filter in c++ mit Lambda nutzen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,471,909 |
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>I'm glad I know sign language<br>It's pretty handy.</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>(4/10)<br>ENTER @<a href='https://peakd.com/@win.hive/posts'>WIN.HIVE'S</a> DAILY DRAW <a href='https://peakd.com/@win.hive/posts'>AND WIN HIVE!</a></center></p>
author | lolzbot |
---|---|
permlink | re-re-ozelot47-s1k70h-20230925t204641z |
category | hive-121566 |
json_metadata | "{"app": "beem/0.24.19"}" |
created | 2023-09-25 20:46:48 |
last_update | 2023-09-25 20:46:48 |
depth | 2 |
children | 0 |
last_payout | 2023-10-02 20:46:48 |
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 | 573 |
author_reputation | 196,202,562,917,811 |
root_title | "Filter in c++ mit Lambda nutzen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,471,936 |
net_rshares | 0 |
<center>PIZZA! $PIZZA slices delivered: @dotwin1981<sub>(3/10)</sub> tipped @ozelot47 </center>
author | pizzabot |
---|---|
permlink | re-filter-in-c-mit-lambda-nutzen-20230925t204631z |
category | hive-121566 |
json_metadata | "{"app": "pizzabot"}" |
created | 2023-09-25 20:46:33 |
last_update | 2023-09-25 20:46:33 |
depth | 1 |
children | 0 |
last_payout | 2023-10-02 20:46:33 |
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 | 100 |
author_reputation | 7,589,118,567,272 |
root_title | "Filter in c++ mit Lambda nutzen" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 127,471,925 |
net_rshares | 0 |